项目 / rasadov/EcommerceAPI

rasadov/EcommerceAPI

行业推荐
语言 Go标签 backenddockerdocker-composeecommerceelasticsearchevent-drivengingogqlgengraphqlgrpckafkamicroservicespostgresqlprotobufpythonrecommendation-systemrecommender-system数据更新 2026-11-13 19:42:00 · 仓库 2026-11-10

一段话介绍

这是一套示例电商后端,用来演示微服务架构:多个 Go 服务分别负责账户、商品、订单和支付,再配一个 Python 推荐服务。服务之间用 gRPC 通信,订单与商品事件会进入 Kafka;商品检索接入 Elasticsearch,客户端则通过统一的 GraphQL 网关访问。整个环境用 Docker Compose 编排,数据层包括 PostgreSQL、Elasticsearch 和 Kafka。按文档构建并启动后,可在本机打开 GraphQL 接口与 Playground。说明见[仓库 README](https://github.com/rasadov/EcommerceAPI)。

本站整理,非 GitHub 官方 description。

官方 description(GitHub API 原样)
Modular e-commerce backend with a GraphQL gateway and gRPC microservices for accounts, products, orders, payments, and recommendations.
698累计星
107Fork
—峰值日增
0上榜次数
总榜
暂未入榜
日榜
暂未入榜
周榜
暂未入榜
月榜
暂未入榜

官方快照(gh_history.db,2026-11-25):总榜 未进 Top50 · 日榜 未进 Top50 · 周榜未满 7 天基线(官方不生成) · 月榜暂无官方口径;下方四卡为站内趋势聚合(周卡按上榜次数,非官方 7 日增量窗)。

行业与场景

按行业选型 →

电商交易与订单履约

适配系统:交易中台、订单履约系统 · 得分 1.4

内置商品、购物车、订单与支付对象模型,可作为电商交易中台直接改造复用。

搜索引擎与语义检索

适配系统:搜索引擎、向量检索服务 · 得分 1.2

提供索引构建与相似度检索能力,可作为站内搜索、语义匹配与以图搜图底座。

更多信息

以下三段按该项目自己的 GitHub README 章节摘录(可合理截断并标明);README 没有对应章节的留空,不编造。

我的用法
可运行 docker compose up -d --build。
特点或设计要点
该电商项目由 Go 微服务(账户、商品、订单、支付、GraphQL 网关)与 Python 推荐服务组成,用 Docker Compose 容器化,数据层用 PostgreSQL、Elasticsearch 和 Kafka。
局限和适用边界
运行该项目前需要预先安装 Docker、Docker Compose 和 Git,即项目依赖这些工具环境。
星标走势还差一天的数据,明天就能看到曲线
每天 10:30 记一次星标,连续两天后自动生成曲线
首次发现 — · 最近在榜 2026-11-18 · 语言 Go · 贡献者 —
go

GitHub 项目主页介绍

来自 GitHub 仓库 README / 主页介绍正文,原样摘录,共 5,791 字节。

# ECOMMERCE MICROSERVICES

This repository hosts a sample **e-commerce platform** demonstrating a **microservices architecture** using multiple **Go services** alongside a **Python-based Recommender service**. The project showcases:

- gRPC communication between services
- Kafka-based event streaming pipeline
- A unified GraphQL API gateway for clients
- Elasticsearch integration for product search

---

## 📚 Table of Contents

- [Overview](#-overview)
- [Architecture Diagram](#-architecture-diagram)
- [Services](#-services)
- [Getting Started](#-getting-started)
- [Usage](#-usage-graphql)
- [Contributing](#-contributing)
- [Author](#-author)
- [License](#-license)

---

## 🧭 Overview

The system comprises several microservices:

- **Account** (Go): Manages user accounts, authentication, and authorization.
- **Product** (Go): CRUD for products; indexes product data in **Elasticsearch**.
- **Order** (Go): Handles order creation and persistence; publishes events to Kafka.
- **Payment** (Go): Handles payment operations and sends updates to order microservice
- **Recommender** (Python): Consumes Kafka events and builds product recommendations.
- **API Gateway** (Go): A GraphQL service exposing a unified API for front-end clients.

The entire ecosystem is containerized using **Docker Compose**. Datastores include **PostgreSQL**, **Elasticsearch**, and **Kafka**.

---

## 🏗 Architecture Diagram

Below is a high-level overview of the system architecture:

![API Design](./design.png)

### Communication Overview

- `API Gateway (GraphQL)` talks to:
    - `Account client` → `Account server` → `Postgres`
    - `Product client` → `Product server` → `ElasticSearch` + Kafka
    - `Order client` → `Order server` → `Postgres` + Kafka
      (also communicates with Product service via gRPC)
    - `Payment client` → `Payment service` → `payment provider` + `Postgres` + Kafka
    - `Recommender client` → `Recommender server` (Python) → `Postgres (Replica)` + Kafka

- **Event Flow**:
    - `Order` and `Product` services act as **Kafka producers**.
    - `Payment` service is a **Kafka consumer**, ingesting product events and saving them in payment provider (DodoPayments).
    - `Recommender` service is also a **Kafka consumer**, ingesting order/product events and updating internal state for recommendations.

---

## ⚙ Services

### 🧑‍💼 Account Service (Go)
- Responsibilities: Register, login, fetch account data, generate JWT tokens.
- Database: PostgreSQL

### 📦 Product Service (Go)
- Responsibilities: Product CRUD operations, indexing to Elasticsearch, event publishing to Kafka.
- Database: Elasticsearch

### 🛒 Order Service (Go)
- Responsibilities: Order creation, price calculation, data persistence, Kafka event publishing.
- Dependencies: Calls product service to retrieve product info.

### 🧠 Recommender Service (Python)
- Responsibilities: Kafka consumer that builds recommendations based on product/order events.
- Tech Stack: Python + gRPC + PostgreSQL (replica of product DB)

### 🚪 API Gateway (Go)
- Responsibilities: Unified GraphQL endpoint at `/graphql`.
- Implementation: Uses gRPC clients for all microservices and schema stitching.

---
## 🚀 Getting Started

### ✅ Prerequisites

Before running the project, ensure you have the following installed:

- [Docker](https://www.docker.com/get-started) & [Docker Compose](https://docs.docker.com/compose/)
- [Git](https://git-scm.com/)

---

### 📥 Clone the Repository

```bash
  git clone https://github.com/rasadov/EcommerceAPI.git
  cd ecommercemicroservices
```

---

### 🐳 Run the Stack

To build and start all services using Docker Compose, run:

```bash
# Step 1: Build the base image
docker compose build base

# Step 2: Build and start all services
docker compose up -d --build```
```

This will start:

- Go microservices (`account`, `order`, `product`, `payment`, `graphql`)
- Python-based `recommender` service
- Databases: PostgreSQL, Elasticsearch
- Kafka + Zookeeper
- GraphQL gateway

---

### 🌐 Access the API

Once everything is running, open your browser to:

- **GraphQL API endpoint**:  
  [http://localhost:8080/graphql](http://localhost:8080/graphql)

- **GraphQL Playground (interactive testing)**:  
  [http://localhost:8080/playground](http://localhost:8080/playground)

---

## 📬 Usage (GraphQL)

Below are example GraphQL queries and mutations you can test in the [GraphQL Playground](http://localhost:8080/playground).

---

### 📝 Register a New Account

```graphql
mutation {
  register(account: {
    name: "Alice"
    email: "alice@example.com"
    password: "secret123"
  }) {
    token
  }
}
```

---

### 🔐 Login

```graphql
mutation {
  login(account: {
    email: "alice@example.com"
    password: "secret123"
  }) {
    token
  }
}
```

---

### ➕ Create a Product

```graphql
mutation {
  createProduct(product: {
    name: "Camera"
    description: "A digital camera"
    price: 99.99
  }) {
    id
    name
  }
}
```

---

### 🔍 Query Products

```graphql
query {
  product(pagination: { skip: 0, take: 10 }) {
    id
    name
    price
  }
}
```

---

### 🛒 Create an Order

```graphql
mutation {
  createOrder(order: {
    products: [
      { id: "PRODUCT_ID", quantity: 2 }
    ]
  }) {
    id
    totalPrice
    products {
      name
      quantity
    }
  }
}
```

## 🤝 Contributing
We welcome contributions! To contribute:

Fork the repository

Create a new branch

Commit and push your changes

Open a Pull Request

## 👤 Author

**Rauf Asadov**  
GitHub: [@rasadov](https://github.com/rasadov)  
LinkedIn: [Rauf Asadov](https://www.linkedin.com/in/rauf-asadov/)  
Email: raufasadov23@gmail.com

## 🪪 License
This project is licensed under the Apache License 2.0.
↑