# anniemon/e-commerce architecture

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

- Interactive diagram: https://gitdiagram.com/anniemon/e-commerce
- Repository: https://github.com/anniemon/e-commerce

## Overview

##### Main Components

a. Client Layer:
- External clients (Web/Mobile applications)
- REST API endpoints interaction

b. Application Layer (Controllers & DTOs):
- OrderController
- PointController
- ProductController
- Validation and request/response transformation

c. Domain Layer:
- Core business logic
- Services (OrderService, PointService, ProductService)
- Entities (Order, Point, Product, Stock)
- Facades (OrderFacade, ProductFacade)

d. Infrastructure Layer:
- TypeORM implementation
- Database connections
- Repositories
- Cache implementation (Redis)

e. External Systems:
- MySQL Database
- Redis Cache

**[Clients] → [Controllers] → [Facades/Services] → [Repositories] → [Database/Cache]**

##### Specific Implementation Details

a. Data Flow Patterns:
- Point transaction flow
- Order processing sequence
- Demonstrate product inventory management
- Cart operations

b. Key Technical Elements:
- TypeORM entities and their relationships
- Repository pattern implementation
- Service layer business logic
- Cache integration points

##### Architectural Patterns to Highlight

- Clean Architecture implementation
- Repository Pattern
- Facade Pattern (for Order and Product)
- CQRS-like separation in services

**┌─ API Layer ─────────────────┐**
- Controllers                 │
- DTOs                       │
- Exception Filters          │
- ┬─────────────┘
- ↓
**┌─ Domain Layer ─────────────┐**
- Services                   │
- Facades                    │
- Entities                   │
- Business Logic            │
- ┬─────────────┘
- ↓
**┌─ Infrastructure Layer ─────┐**
- TypeORM Repositories      │
- Database Connections      │
- Cache Implementation      │
- ┬─────────────┘
- ↓
**┌─ External Systems ─────────┐**
- MySQL                     │
- Redis                     │
- ┘

##### Important Details

- Transaction boundaries for critical operations
- Cache invalidation points
- Error handling flows
- Database relationship mappings

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef client fill:#2196F3,stroke:#1565C0,color:white
    classDef controller fill:#4CAF50,stroke:#388E3C,color:white
    classDef service fill:#FFC107,stroke:#FFA000,color:black
    classDef entity fill:#FF9800,stroke:#F57C00,color:white
    classDef infra fill:#FF5722,stroke:#E64A19,color:white
    classDef external fill:#9E9E9E,stroke:#616161,color:white
    classDef facade fill:#9C27B0,stroke:#7B1FA2,color:white

    %% Client Layer
    Client["External Clients\n(Web/Mobile)"]:::client

    %% Application Layer
    subgraph ApplicationLayer["Application Layer"]
        Controllers["Controllers Layer"]
        OrderC["Order Controller"]
        PointC["Point Controller"]
        ProductC["Product Controller"]
        DTOs["Data Transfer Objects"]
        ExceptionFilter["Global Exception Filter"]
    end

    %% Domain Layer
    subgraph DomainLayer["Domain Layer"]
        Facades["Facades"]
        OrderF["Order Facade"]
        ProductF["Product Facade"]
        
        Services["Services"]
        OrderS["Order Service"]
        PointS["Point Service"]
        ProductS["Product Service"]
        
        Entities["Domain Entities"]
        OrderE["Order Entity"]
        PointE["Point Entity"]
        ProductE["Product Entity"]
        StockE["Stock Entity"]
    end

    %% Infrastructure Layer
    subgraph InfrastructureLayer["Infrastructure Layer"]
        Repositories["TypeORM Repositories"]
        OrderR["Order Repository"]
        PointR["Point Repository"]
        ProductR["Product Repository"]
        StockR["Stock Repository"]
        
        DBConn["Database Connection"]
        CacheImpl["Cache Implementation"]
    end

    %% External Systems
    MySQL[(MySQL Database)]:::external
    Redis[(Redis Cache)]:::external

    %% Relationships
    Client --> Controllers
    Controllers --> |REST| OrderC & PointC & ProductC
    OrderC & PointC & ProductC --> DTOs
    OrderC --> OrderF
    PointC --> PointS
    ProductC --> ProductF
    
    OrderF --> OrderS
    ProductF --> ProductS
    
    OrderS & PointS & ProductS --> Repositories
    Repositories --> DBConn
    DBConn --> MySQL
    CacheImpl --> Redis

    %% Click Events
    click OrderC "https://github.com/anniemon/e-commerce/blob/main/src/application/controllers/order.controller.ts"
    click PointC "https://github.com/anniemon/e-commerce/blob/main/src/application/controllers/point.controller.ts"
    click ProductC "https://github.com/anniemon/e-commerce/blob/main/src/application/controllers/product.controller.ts"
    click DTOs "https://github.com/anniemon/e-commerce/tree/main/src/application/dtos"
    click ExceptionFilter "https://github.com/anniemon/e-commerce/blob/main/src/application/filters/global-exception.filter.ts"
    click OrderF "https://github.com/anniemon/e-commerce/blob/main/src/domain/usecase/order.facade.ts"
    click ProductF "https://github.com/anniemon/e-commerce/blob/main/src/domain/usecase/product.facade.ts"
    click OrderS "https://github.com/anniemon/e-commerce/blob/main/src/domain/services/order.service.ts"
    click PointS "https://github.com/anniemon/e-commerce/blob/main/src/domain/services/point.service.ts"
    click ProductS "https://github.com/anniemon/e-commerce/blob/main/src/domain/services/product.service.ts"
    click OrderE "https://github.com/anniemon/e-commerce/blob/main/src/domain/entities/order.entity.ts"
    click PointE "https://github.com/anniemon/e-commerce/blob/main/src/domain/entities/point.entity.ts"
    click ProductE "https://github.com/anniemon/e-commerce/blob/main/src/domain/entities/product.entity.ts"
    click StockE "https://github.com/anniemon/e-commerce/blob/main/src/domain/entities/stock.entity.ts"
    click Repositories "https://github.com/anniemon/e-commerce/tree/main/src/infrastructure/typeorm/repositories"
    click DBConn "https://github.com/anniemon/e-commerce/tree/main/src/infrastructure/typeorm/data-source"

    %% Legend
    subgraph Legend
        Client_L[Client]:::client
        Controller_L[Controller]:::controller
        Service_L[Service]:::service
        Entity_L[Entity]:::entity
        Infra_L[Infrastructure]:::infra
        External_L[External System]:::external
        Facade_L[Facade]:::facade
    end
```
