# minhhoanq/ecommerce_web architecture

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

- Interactive diagram: https://gitdiagram.com/minhhoanq/ecommerce_web
- Repository: https://github.com/minhhoanq/ecommerce_web

## Overview

##### Project Components
- Client (Frontend):
– Located in the “client” directory.
– Built with React (JSX files, component structure, TailwindCSS).
– Contains pages for public views, member functions, and admin dashboards.

- API Gateway:
– Found in the “gateway” directory.
– Acts as the central entry point providing “unified” API endpoints for authentication, cart, category, feedback, image, order, and product services.

- AuthService Service:
– Present in the “AuthService” folder.
– Handles user authentication and related logic.

- CommentService Service:
– Present in the “CommentService” folder.
– Focused on feedback/comments handling. Note that it uses Prisma for database interactions.

- Server (Backend Core Service):
– Located in the “server” directory.
– Implements a layered architecture with clear separation into presentation, application (usecases and dtos), domain (entities, repositories, value objects), and infrastructure (dependency injection, repositories, external services like RabbitMQ, Redis, Elasticsearch, Kafka).
– This service likely handles the core business logic for product, order, cart, and category management.

- Additional Components & Integrations:
– Docker: “docker-compose.yml” and Dockerfile present in “server” indicate container-based deployment.
– Messaging / Integration Technologies: RabbitMQ (present in multiple services and in “server/src/infrastructure/rabbitmq”), Redis (for caching or session management), Kafka, and possibly Elasticsearch.
– Supporting configuration files (logstash.conf, tailwind.config.js) for logging and styling.

##### Architectural Relationships & Data Flow
- The Client interacts with the system via the API Gateway.

- The Gateway routes requests to respective microservices or backend services.
– For example, authentication requests go to AuthService, comment/feedback requests go to CommentService, and product/order related requests are forwarded to the Server.

- The Server service follows a layered (or Domain-Driven Design) architecture:

- Data Storage & External Integrations:
– Include separate components for databases (via Prisma in CommentService; possibly a relational database connected to the Server backend), message brokers (RabbitMQ/Redis/Kafka), and external services (S3 for file storage – as seen with s3.config.ts).

##### Architectural Patterns & Technologies
- Microservices Architecture: Each service (AuthService, CommentService, Server) is largely independent and communicates via an API Gateway.
- API Gateway Pattern: Centralizes front-end communication and dispatches to the appropriate backend service.
- Domain-Driven Design (especially in the “server” service): Look for aggregates in areas like product, cart, and order management.
- Use of modern frontend frameworks: The client is built with React, Tailwind CSS.
- Technology Stack Indicators: Node.js/Express (in various services), TypeScript (especially in “server”), and Prisma as an ORM.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend
    subgraph "Frontend"
        Client["Client (React & TailwindCSS)"]:::frontend
    end

    %% Backend Services
    subgraph "Backend Services"
        GW["API Gateway"]:::gateway
        Auth["AuthService (Authentication)"]:::microservice
        Comment["CommentService (Comments/Feedback via Prisma)"]:::microservice
        subgraph "Server (Core Business Logic)"
            Pres["Presentation Layer (Controllers/Routes)"]:::serverLayer
            App["Application Layer (UseCases/DTOs)"]:::serverLayer
            Dom["Domain Layer (Entities, Repositories)"]:::serverLayer
            Inf["Infrastructure Layer (DB, RabbitMQ, Redis, Kafka, etc.)"]:::serverLayer
        end
    end

    %% External Integrations
    subgraph "External Integrations"
        DB["Relational Database (Prisma/ORM)"]:::database
        RMQ["RabbitMQ (Messaging)"]:::integration
        REDIS["Redis (Cache/Session)"]:::integration
        KAFKA["Kafka (Event Streaming)"]:::integration
        S3["S3 (File Storage)"]:::integration
    end

    %% Data Flow Connections
    Client -->|"APIRequest"| GW
    GW -->|"AuthRequest"| Auth
    GW -->|"FeedbackRequest"| Comment
    GW -->|"BusinessRequest"| Pres

    %% Server Layer Flow
    Pres -->|"CallUseCases"| App
    App -->|"ProcessLogic"| Dom
    Dom -->|"DataAccess"| Inf
    Inf -->|"Persist/Retrieve"| DB
    Inf -->|"SendEvents"| RMQ
    Inf -->|"CacheOps"| REDIS
    Inf -->|"StreamEvents"| KAFKA
    Inf -->|"FileOps"| S3

    %% Asynchronous event flow from Microservices
    Auth -->|"EmitEvent"| RMQ
    Comment -->|"EmitEvent"| RMQ

    %% Click Events for Component Mapping
    click Client "https://github.com/minhhoanq/ecommerce_web/tree/main/client/"
    click GW "https://github.com/minhhoanq/ecommerce_web/tree/main/gateway/"
    click Auth "https://github.com/minhhoanq/ecommerce_web/tree/main/AuthService/"
    click Comment "https://github.com/minhhoanq/ecommerce_web/tree/main/CommentService/"
    click Pres "https://github.com/minhhoanq/ecommerce_web/tree/main/server/"
    click App "https://github.com/minhhoanq/ecommerce_web/tree/main/server/"
    click Dom "https://github.com/minhhoanq/ecommerce_web/tree/main/server/"
    click Inf "https://github.com/minhhoanq/ecommerce_web/tree/main/server/"

    %% Styles
    classDef frontend fill:#ffefba,stroke:#e8a317,stroke-width:2px;
    classDef gateway fill:#cce5ff,stroke:#337ab7,stroke-width:2px;
    classDef microservice fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef serverLayer fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef integration fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
