# tranduyduong/ecommerce architecture

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

- Interactive diagram: https://gitdiagram.com/tranduyduong/ecommerce
- Repository: https://github.com/tranduyduong/ecommerce

## Overview

##### Project type and purpose
- This is a full-stack, microservice-styled e-commerce system.
- It consists of a React single-page frontend and a Django-based backend composed of multiple Django “apps” (auth_core, core, payment_gateway), with asynchronous processing via Celery and RabbitMQ, all containerized with Docker Compose.

##### Main components
a. Frontend (React)
- Node.js container or client browser—serves the SPA, static assets, and routes user interactions to the API.
b. Backend API (Django REST)
- One or more web containers running the Django project (config/urls.py, views, serializers).
- Hosts the three “microservices” as Django apps (auth_core, core, payment_gateway).
c. Message broker (RabbitMQ)
- Handles task queueing for asynchronous work (order fulfillment, emails, payments).
d. Worker (Celery)
- One or more Celery worker containers listening on RabbitMQ, executing background tasks.
e. Database (PostgreSQL)
- Primary relational datastore for all apps.
f. Media storage (Docker volume or shared storage)
- Where uploaded files (e.g. product images) are persisted.
g. External services
- Third-party payment provider (called from payment_gateway/proccess_payment.py).

##### Relationships and data flows
- Client → (HTTPS/REST) → Django API
- Django API → (SQL) → PostgreSQL
- Django API → (AMQP) → RabbitMQ
- Celery Worker → (AMQP) → RabbitMQ
- Celery Worker → (SQL) → PostgreSQL
- Celery Worker → (HTTPS/SDK) → External Payment API
- Client ← (HTTP/WebSocket optional) ← Django API responses

##### Architectural patterns and design principles
- Micro-Django apps: auth_core, core, payment_gateway are loosely coupled but share the same project settings.
- Event-driven, asynchronous processing (Celery + RabbitMQ).
- 12-factor app approach: configuration via environment variables, stateless containers, separate backing services.
- Container orchestration with Docker Compose: defines services for web, worker, broker, db, and optionally a volume for media.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        FE["React SPA (Browser)"]:::frontend
    end

    %% Backend Services under Docker Compose
    subgraph "Backend Layer (Docker Compose)"
        direction TB
        subgraph "Web Service Container"
            direction TB
            API["Django API\n(auth_core/core/payment_gateway)"]:::backend
            subgraph "Django Apps"
                direction TB
                AC["auth_core"]:::app
                CO["core"]:::app
                PG["payment_gateway"]:::app
            end
        end

        API --> AC
        API --> CO
        API --> PG
    end

    %% Asynchronous Processing
    subgraph "Asynchronous Layer"
        direction TB
        BROKER["RabbitMQ Broker"]:::broker
        WORKER["Celery Worker"]:::worker
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        DB["PostgreSQL DB"]:::db
        MEDIA["Media Storage\n(media/uploads)"]:::storage
    end

    %% External Services
    subgraph "External Services"
        direction TB
        EP["Payment Provider API"]:::external
    end

    %% Connections
    FE -->|"HTTPS/REST"| API
    API -->|"SQL read/write"| DB
    API -->|"AMQP publish"| BROKER
    WORKER -->|"AMQP consume"| BROKER
    WORKER -->|"SQL read/write"| DB
    WORKER -->|"HTTPS/SDK"| EP
    API -->|"serves files"| MEDIA

    %% Click Events - Frontend
    click FE "https://github.com/tranduyduong/ecommerce/tree/master/frontend/"
    click FE "https://github.com/tranduyduong/ecommerce/blob/master/frontend/public/index.html"
    click FE "https://github.com/tranduyduong/ecommerce/tree/master/frontend/src/"
    click FE "https://github.com/tranduyduong/ecommerce/blob/master/frontend/package.json"
    click FE "https://github.com/tranduyduong/ecommerce/blob/master/frontend/.env.example"

    %% Click Events - Backend API
    click API "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/config/settings.py"
    click API "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/config/urls.py"
    click API "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/config/wsgi.py"
    click API "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/manage.py"

    %% Click Events - auth_core app
    click AC "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/auth_core/apps.py"
    click AC "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/auth_core/models.py"
    click AC "https://github.com/tranduyduong/ecommerce/tree/master/micro-ecommerce/auth_core/migrations/"
    click AC "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/auth_core/fixtures/fake_data.json"

    %% Click Events - core app
    click CO "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/core/models.py"
    click CO "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/core/views.py"
    click CO "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/core/serializers.py"
    click CO "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/core/urls.py"
    click CO "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/core/permissions.py"
    click CO "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/core/receivers.py"
    click CO "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/core/fixtures/initial_data.json"
    click CO "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/core/tests.py"

    %% Click Events - payment_gateway app
    click PG "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/payment_gateway/proccess_payment.py"
    click PG "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/payment_gateway/models.py"
    click PG "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/payment_gateway/serializers.py"
    click PG "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/payment_gateway/middlewares.py"
    click PG "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/payment_gateway/admin.py"

    %% Click Events - Celery & Worker
    click WORKER "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/config/celery.py"
    click WORKER "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/docker/worker-entrypoint.sh"

    %% Click Events - Docker Compose & Entrypoints
    click DB "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/docker-compose.yml"
    click API "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/docker/app-entrypoint.sh"

    %% Click Events - Media & Env
    click MEDIA "https://github.com/tranduyduong/ecommerce/tree/master/micro-ecommerce/media/uploads/"
    click API "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/.env.example"
    click API "https://github.com/tranduyduong/ecommerce/blob/master/micro-ecommerce/requirements.txt"

    %% Styles
    classDef frontend fill:#F4F1BB,stroke:#000,stroke-width:1px;
    classDef backend fill:#C8D8E4,stroke:#000,stroke-width:1px;
    classDef app fill:#E8A0BF,stroke:#000,stroke-width:1px;
    classDef broker fill:#FFEBCE,stroke:#000,stroke-width:1px;
    classDef worker fill:#B5EAEA,stroke:#000,stroke-width:1px;
    classDef db fill:#D3F8E2,stroke:#000,stroke-width:1px;
    classDef storage fill:#FFCFDF,stroke:#000,stroke-width:1px;
    classDef external fill:#FFD6A5,stroke:#000,stroke-width:1px;
```
