# datngth03/ecommerce-go-app architecture

> Architecture diagram of the GitHub repository datngth03/ecommerce-go-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/datngth03/ecommerce-go-app
- Repository: https://github.com/datngth03/ecommerce-go-app

## Overview

##### Project Type and Purpose
- This is a Go-based e-commerce platform built with a modern microservices architecture.
- It consists of an API Gateway plus a set of independent microservices (user, auth, product, order, cart, payment, shipping, notification, inventory, review, search, recommendation).
- Services expose gRPC interfaces (back-end) and REST/OpenAPI through the API Gateway (front-end), persisting to dedicated databases (PostgreSQL, Redis) and exchanging events (message broker).

##### File Structure
- **cmd/** holds the entrypoints for each microservice and the API Gateway.
- **internal/** groups per-service modules into the layered structure:
- domain (entities, repositories)
- application (business logic)
- infrastructure (DB clients, message publishers)
- delivery (gRPC servers under each service’s `delivery/grpc`; API-Gateway HTTP handlers)
- **api/** contains protobuf and OpenAPI specs.
- **pkg/client/** contains generated gRPC clients for inter-service communication.
- **migrations/** holds SQL schema migrations for each stateful service.
- **docker-compose.yaml** (and optional Kubernetes manifests) orchestrate containers: services, databases, message broker, cache, search engine.
- **scripts/** automates proto generation, builds, and local environment setup.

##### Key Architectural Insights from README
- Bounded contexts per service.
- Communication via gRPC (synchronous RPC) and message broker (asynchronous events).
- Central API Gateway routing REST calls to gRPC services, enforcing authentication and rate-limiting.
- Each microservice owns its own datastore (Postgres or Redis) to ensure loose coupling.
- Shared infra for logging, metrics, tracing (OpenTelemetry) likely lives under `internal/shared`.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    External["Web/Mobile Clients"]:::external

    %% API Gateway Container
    subgraph "API Gateway" 
        direction TB
        AGMain["Entrypoint\nmain.go"]:::infra
        AGMiddleware["Auth Middleware"]:::infra
        AGRouter["HTTP Router"]:::infra
        AGHandlers["HTTP Handlers"]:::infra
        AGMain --> AGMiddleware
        AGMain --> AGRouter
        AGRouter --> AGHandlers
    end

    External -->|HTTP/REST| AGRouter

    %% Microservices
    subgraph "Microservices"
        direction TB
        AuthService["Auth Service"]:::micro
        UserService["User Service"]:::micro
        ProductService["Product Service"]:::micro
        InventoryService["Inventory Service"]:::micro
        CartService["Cart Service"]:::micro
        OrderService["Order Service"]:::micro
        PaymentService["Payment Service"]:::micro
        ShippingService["Shipping Service"]:::micro
        NotificationService["Notification Service"]:::micro
        ReviewService["Review Service"]:::micro
        SearchService["Search Service"]:::micro
        RecommendationService["Recommendation Service"]:::micro
    end

    %% API Gateway to Services (gRPC)
    AGMain -->|gRPC| AuthService
    AGMain -->|gRPC| UserService
    AGMain -->|gRPC| ProductService
    AGMain -->|gRPC| InventoryService
    AGMain -->|gRPC| CartService
    AGMain -->|gRPC| OrderService
    AGMain -->|gRPC| PaymentService
    AGMain -->|gRPC| ShippingService
    AGMain -->|gRPC| NotificationService
    AGMain -->|gRPC| ReviewService
    AGMain -->|gRPC| SearchService
    AGMain -->|gRPC| RecommendationService

    %% Datastores
    subgraph "Datastores"
        direction TB
        AuthDB["Redis (Auth)"]:::datastore
        UserDB["PostgreSQL (User)"]:::datastore
        ProductDB["PostgreSQL (Product)"]:::datastore
        InventoryDB["PostgreSQL (Inventory)"]:::datastore
        CartDB["Redis (Cart)"]:::datastore
        OrderDB["PostgreSQL (Order)"]:::datastore
        PaymentDB["PostgreSQL (Payment)"]:::datastore
        ShippingDB["PostgreSQL (Shipping)"]:::datastore
        NotificationDB["PostgreSQL (Notification)"]:::datastore
        ReviewDB["PostgreSQL (Review)"]:::datastore
        ES["ElasticSearch"]:::datastore
    end

    %% Service to Datastore
    AuthService -->|Redis| AuthDB
    UserService -->|Postgres| UserDB
    ProductService -->|Postgres| ProductDB
    InventoryService -->|Postgres| InventoryDB
    CartService -->|Redis| CartDB
    OrderService -->|Postgres| OrderDB
    PaymentService -->|Postgres| PaymentDB
    ShippingService -->|Postgres| ShippingDB
    NotificationService -->|Postgres| NotificationDB
    ReviewService -->|Postgres| ReviewDB
    SearchService -->|Elasticsearch| ES

    %% Message Broker
    Broker["Message Broker\n(Kafka/RabbitMQ)"]:::infra
    subgraph "Event Flow"
        direction TB
        AuthService -->|events| Broker
        UserService -->|events| Broker
        ProductService -->|events| Broker
        InventoryService -->|events| Broker
        CartService -->|events| Broker
        OrderService -->|events| Broker
        PaymentService -->|events| Broker
        ShippingService -->|events| Broker
        NotificationService -->|events| Broker
        ReviewService -->|events| Broker
        RecommendationService -->|events| Broker
        SearchService -->|consume| Broker
        NotificationService -->|consume| Broker
    end

    %% External Integrations
    PaymentGateway["Payment Gateway"]:::external
    EmailSMS["Email/SMS Provider"]:::external

    PaymentService -->|API| PaymentGateway
    NotificationService -->|SMTP/REST| EmailSMS

    %% Click Events for API Gateway
    click AGMain "https://github.com/datngth03/ecommerce-go-app/blob/main/cmd/api-gateway/main.go"
    click AGRouter "https://github.com/datngth03/ecommerce-go-app/blob/main/internal/api_gateway/delivery/http/router.go"
    click AGHandlers "https://github.com/datngth03/ecommerce-go-app/blob/main/internal/api_gateway/delivery/http/handlers.go"
    click AGMiddleware "https://github.com/datngth03/ecommerce-go-app/blob/main/internal/api_gateway/middleware/auth_middleware.go"

    %% Click Events for Services Entrypoints
    click AuthService "https://github.com/datngth03/ecommerce-go-app/blob/main/cmd/auth-service/main.go"
    click UserService "https://github.com/datngth03/ecommerce-go-app/blob/main/cmd/user-service/main.go"
    click ProductService "https://github.com/datngth03/ecommerce-go-app/blob/main/cmd/product-service/main.go"
    click InventoryService "https://github.com/datngth03/ecommerce-go-app/blob/main/cmd/inventory-service/main.go"
    click CartService "https://github.com/datngth03/ecommerce-go-app/blob/main/cmd/cart-service/main.go"
    click OrderService "https://github.com/datngth03/ecommerce-go-app/blob/main/cmd/order-service/main.go"
    click PaymentService "https://github.com/datngth03/ecommerce-go-app/blob/main/cmd/payment-service/main.go"
    click ShippingService "https://github.com/datngth03/ecommerce-go-app/blob/main/cmd/shipping-service/main.go"
    click NotificationService "https://github.com/datngth03/ecommerce-go-app/blob/main/cmd/notification-service/main.go"
    click ReviewService "https://github.com/datngth03/ecommerce-go-app/blob/main/cmd/review-service/main.go"

    %% Styles
    classDef micro fill:#B3D4FC,stroke:#0366D6,color:#000
    classDef datastore fill:#FFD8A8,stroke:#C2410C,color:#000
    classDef infra fill:#D1F2A5,stroke:#237804,color:#000
    classDef external fill:#E5E5E5,stroke:#666,color:#000
```
