电商系统 活跃维护

EcommerceAPI

rasadov/EcommerceAPI

模块化电商后端,带有 GraphQL 网关和用于账户、产品、订单、支付和推荐的 gRPC 微服务。

696
Stars 标星
106
Forks 分支
6
Watchers 关注
3
Open Issues
Go
主要语言
Apache-2.0
开源协议
852 KB
仓库大小
2 个月前
最后推送
一键安装扩展 / 插件指令
dsh plugin --profile web add github:rasadov/EcommerceAPI
git clone https://github.com/rasadov/EcommerceAPI.git
git clone git@github.com:rasadov/EcommerceAPI.git
README.md master

英文原文正文为项目原始 README(英文),本站后续会翻译为中文,当前仅剔除图片与无关章节并统一排版。

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

🧭 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:

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:


📥 Clone the Repository

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

🐳 Run the Stack

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

# 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:


📬 Usage (GraphQL)

Below are example GraphQL queries and mutations you can test in the GraphQL Playground.


📝 Register a New Account

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

🔐 Login

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

➕ Create a Product

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

🔍 Query Products

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

🛒 Create an Order

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 LinkedIn: Rauf Asadov Email: raufasadov23@gmail.com

🪪 License

This project is licensed under the Apache License 2.0.

本站来源与版权声明
  • 本文标题:EcommerceAPI - 模块化电商后端
  • 本文链接:https://cn121.com/shop/rasadov-ecommerceapi.html
  • 原项目:rasadov/EcommerceAPI 版权归原作者 rasadov 及贡献者所有
  • 收录信息:本站于 2026-10-08 收录本项目,本页所列协议与仓库指标均为收录当时的状态;该日期之后原项目的版本更新与协议变更,本页不作同步。
  • 开源协议:收录时本项目采用 Apache-2.0(查看 LICENSE 原文),本站转载其原始文档(未改动文字,仅剔除图片与无关章节);使用、修改、分发请以该仓库 LICENSE 原文为准。本站对原文仅作排版与图片地址适配, 并保留原项目的 NOTICE 与署名要求。
  • 站点出处:本文首发于 OneTwoOne,收录自 GitHub 开源项目 rasadov/EcommerceAPI。
  • 内容说明:本页正文为原项目 README 原文(英文),本站后续会翻译为中文(当前尚未译出),仅剔除了图片与赞助等无关章节、并把相对链接改为绝对地址;页首简介为机器翻译自仓库描述。
  • 引用声明:商业转载、第三方聚合或 AI 检索训练引用时,请务必保留以上来源出处、本文永久链接,以及原项目的版权声明与许可信息。
  • 下架通道:若原项目此后变更或收紧了许可协议、或作者/权利人认为本站的收录方式(译文、排版适配、简介翻译等)超出其授权范围,请通过 xyd3302001@163.com 发送下架通知,并附上项目地址与本页链接。本站核实后将第一时间删除本页内容,或改为不复制原文的目录性收录;署名更正等其他要求可一并提出。