# luantruongptit/shopee_api-msa-nestjs architecture

> Architecture diagram of the GitHub repository luantruongptit/shopee_api-msa-nestjs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/luantruongptit/shopee_api-msa-nestjs
- Repository: https://github.com/luantruongptit/shopee_api-msa-nestjs

## Overview

##### Main Components

a. API Gateway Layer:
- Authentication/authorization components (JWT, Google Auth)
- Rate limiting and API key validation

b. Microservices:
- Auth Service
- User Service
- Product Service
- Logistics Service
- Seller Channel Service
- Role Service
- File Upload Service
- Brand Service
- Inventory Service

c. Message Broker:
- Kafka as the event bus between services
- Event publishing/subscription patterns

d. Databases:
- MongoDB instances for different services
- Redis for caching and session management

##### Component Relationships

a. Data Flow:
- API Gateway routing requests to appropriate services
- Event-driven communication between services via Kafka
- Database connections for each service

b. Authentication Flow:
- JWT token validation path
- Refresh token mechanism
- Google OAuth integration

##### Specific Implementation Details

a. Service Patterns:
- CQRS pattern in Product service
- Event Sourcing implementation
- Repository pattern usage

b. Cross-Cutting Concerns:
- Shared libraries usage
- Common middleware
- Error handling flow

##### Additional Components

- Nginx as the reverse proxy
- Docker containers
- Monitoring and logging components
- File storage service (AWS S3)

##### Layered Architecture

For each service, show:
- Controllers/API Layer
- Application Layer (CQRS)
- Domain Layer
- Infrastructure Layer
- Repository Layer

##### Infrastructure components

Remember to:
- Use consistent notation
- Both synchronous and asynchronous communication patterns
- Critical paths and dependencies

This system design should reflect the complex nature of the e-commerce platform while maintaining clarity in showing how different components interact and work together.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Legend"
        L1[Service]:::service
        L2[(Database)]:::database
        L3{Message Broker}:::broker
        L4([External Service]):::external
        L5[/API Layer/]:::api
    end

    subgraph "API Layer"
        API[/API Gateway/]:::api
        NGINX[Reverse Proxy]:::service
    end

    subgraph "Authentication"
        AUTH[Auth Service]:::service
        JWT[JWT Service]:::service
        GOOGLE([Google OAuth]):::external
    end

    subgraph "Core Services"
        USER[User Service]:::service
        PRODUCT[Product Service]:::service
        LOGISTICS[Logistics Service]:::service
        SELLER[Seller Channel Service]:::service
        ROLE[Role Service]:::service
        UPLOAD[File Upload Service]:::service
        BRAND[Brand Service]:::service
        INVENTORY[Inventory Service]:::service
    end

    subgraph "Message Broker"
        KAFKA{Kafka Event Bus}:::broker
    end

    subgraph "Data Layer"
        MONGODB[(MongoDB)]:::database
        REDIS[(Redis Cache)]:::database
        S3([AWS S3]):::external
    end

    subgraph "Shared Infrastructure"
        COMMON[Common Library]:::infra
        CORE[Core Library]:::infra
        INFRA[Infrastructure]:::infra
    end

    NGINX --> API
    API --> AUTH
    API --> USER
    API --> PRODUCT
    API --> LOGISTICS
    API --> SELLER
    API --> ROLE
    API --> UPLOAD
    API --> BRAND
    API --> INVENTORY

    AUTH --> JWT
    AUTH --> GOOGLE
    AUTH --> MONGODB
    AUTH --> REDIS

    USER --> MONGODB
    PRODUCT --> MONGODB
    LOGISTICS --> MONGODB
    SELLER --> MONGODB
    ROLE --> MONGODB
    BRAND --> MONGODB
    INVENTORY --> MONGODB
    UPLOAD --> S3

    USER --> KAFKA
    PRODUCT --> KAFKA
    LOGISTICS --> KAFKA
    SELLER --> KAFKA
    INVENTORY --> KAFKA

    %% Component Mappings
    click API "https://github.com/LuanTruongPTIT/Shopee_API-MSA-NestJS/tree/main/apps/api-gateway"
    click AUTH "https://github.com/LuanTruongPTIT/Shopee_API-MSA-NestJS/tree/main/apps/auth"
    click USER "https://github.com/LuanTruongPTIT/Shopee_API-MSA-NestJS/tree/main/apps/user"
    click PRODUCT "https://github.com/LuanTruongPTIT/Shopee_API-MSA-NestJS/tree/main/apps/product"
    click LOGISTICS "https://github.com/LuanTruongPTIT/Shopee_API-MSA-NestJS/tree/main/apps/logistic"
    click SELLER "https://github.com/LuanTruongPTIT/Shopee_API-MSA-NestJS/tree/main/apps/seller_channel"
    click ROLE "https://github.com/LuanTruongPTIT/Shopee_API-MSA-NestJS/tree/main/apps/role"
    click UPLOAD "https://github.com/LuanTruongPTIT/Shopee_API-MSA-NestJS/tree/main/apps/upload_file"
    click BRAND "https://github.com/LuanTruongPTIT/Shopee_API-MSA-NestJS/tree/main/apps/brand"
    click INVENTORY "https://github.com/LuanTruongPTIT/Shopee_API-MSA-NestJS/tree/main/apps/inventory"
    click COMMON "https://github.com/LuanTruongPTIT/Shopee_API-MSA-NestJS/tree/main/libs/common"
    click CORE "https://github.com/LuanTruongPTIT/Shopee_API-MSA-NestJS/tree/main/libs/core"
    click INFRA "https://github.com/LuanTruongPTIT/Shopee_API-MSA-NestJS/tree/main/libs/infra"

    classDef service fill:#3498db,stroke:#2980b9,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef broker fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef infra fill:#95a5a6,stroke:#7f8c8d,color:white
```
