# splorg/checkout-system architecture

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

- Interactive diagram: https://gitdiagram.com/splorg/checkout-system
- Repository: https://github.com/splorg/checkout-system

## Overview

##### Main Components

A. Frontend (Client Layer):
- React Application (TypeScript)
- Key modules:
- Components (UI elements)
- Stores (State management)
- Services (API integration)
- Hooks (Custom logic)

B. Backend (Server Layer):
- Node.js Application with Clean Architecture
- Layers:
- Application Layer (Use Cases, DTOs, Services)
- Domain Layer (Entities, Aggregates, Events)
- Infrastructure Layer (Controllers, Repositories, HTTP)

C. Database Layer:
- Prisma ORM
- Event Store
- Relational Database (indicated by Prisma usage)

##### Architecture Patterns to Highlight

a) Clean Architecture (Backend):
- Inner circle: Domain Layer (entities, aggregates)
- Middle circle: Application Layer (use cases)
- Outer circle: Infrastructure Layer (controllers, repositories)

b) Event Sourcing:
- Event flow with:
- Event Store
- Event Publishers
- Event Subscribers
- Command/Query separation

##### Client-Server Communication
- REST API calls between frontend services and backend controllers
- WebSocket connections (if implemented)

##### Data Flow
- Commands: Client → API → Use Cases → Domain → Event Store
- Queries: Client → API → Repositories → Database

##### Event Flow
- Domain Events
- Event Store persistence
- Event replay capability

##### Specific Implementation Details

A. Frontend Section:
- Components hierarchy
- State management stores (cart-store, event-store, etc.)
- API service layer
- Route structure

B. Backend Section:
- Controllers (Cart, Events, Order, Wallet)
- Use Cases (Checkout, Cart Management, Wallet operations)
- Domain Models (Cart, Wallet, Order, Product)
- Event Sourcing infrastructure

##### Additional Elements

- Technology stack labels
- Security boundaries
- Async operations
- Public vs. private APIs

##### Infrastructure Layer (Database + Event Store)

- The event-sourcing pattern for cart and wallet operations
- Clean architecture separation
- Frontend component organization
- API routes and controllers structure
- Database schema and event store relationship

Remember to maintain a balance between detail and clarity, focusing on the key architectural decisions while avoiding overwhelming detail at the implementation level.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#3498db,color:white
    classDef backend fill:#2ecc71,color:white
    classDef database fill:#f1c40f,color:white
    classDef event fill:#e74c3c,color:white
    classDef infra fill:#95a5a6,color:white
    classDef domain fill:#9b59b6,color:white

    %% Frontend Layer
    subgraph Client
        FC["Components"]:::frontend
        FS["Stores"]:::frontend
        FSV["Services"]:::frontend
        FH["Hooks"]:::frontend
    end

    %% Backend Layer
    subgraph Server
        %% Application Layer
        subgraph Application
            UC["Use Cases"]:::backend
            DTO["DTOs"]:::backend
            AS["Application Services"]:::backend
        end

        %% Domain Layer
        subgraph Domain
            DE["Entities"]:::domain
            DA["Aggregates"]:::domain
            DVO["Value Objects"]:::domain
            DEV["Events"]:::event
        end

        %% Infrastructure Layer
        subgraph Infrastructure
            CTRL["Controllers"]:::infra
            REPO["Repositories"]:::infra
            ROUTES["Routes"]:::infra
            ES["Event Store"]:::event
        end
    end

    %% Database Layer
    subgraph Storage
        DB[(Database)]:::database
        EDB[(Event Database)]:::database
    end

    %% Relationships
    FC --> FSV
    FSV --> ROUTES
    FS --> FSV
    FH --> FS

    ROUTES --> CTRL
    CTRL --> UC
    UC --> DTO
    UC --> AS
    AS --> DE
    AS --> DA
    DA --> DEV
    DE --> DVO

    REPO --> DB
    ES --> EDB
    UC --> REPO
    DEV --> ES

    %% Click Events
    click FC "https://github.com/splorg/checkout-system/tree/main/client/src/components/"
    click FS "https://github.com/splorg/checkout-system/tree/main/client/src/stores/"
    click FSV "https://github.com/splorg/checkout-system/tree/main/client/src/services/"
    click FH "https://github.com/splorg/checkout-system/tree/main/client/src/hooks/"
    click UC "https://github.com/splorg/checkout-system/tree/main/server/src/application/use-case/"
    click DTO "https://github.com/splorg/checkout-system/tree/main/server/src/application/dto/"
    click DE "https://github.com/splorg/checkout-system/tree/main/server/src/domain/entity/"
    click DA "https://github.com/splorg/checkout-system/tree/main/server/src/domain/aggregate/"
    click DVO "https://github.com/splorg/checkout-system/tree/main/server/src/domain/value-object/"
    click DEV "https://github.com/splorg/checkout-system/tree/main/server/src/domain/event/"
    click CTRL "https://github.com/splorg/checkout-system/tree/main/server/src/infra/http/controllers/"
    click ROUTES "https://github.com/splorg/checkout-system/tree/main/server/src/infra/http/routes/"
    click REPO "https://github.com/splorg/checkout-system/tree/main/server/src/infra/repositories/"
    click ES "https://github.com/splorg/checkout-system/tree/main/server/src/infra/event/"
    click DB "https://github.com/splorg/checkout-system/tree/main/server/prisma/"

    %% Legend
    subgraph Legend
        L1["Frontend"]:::frontend
        L2["Backend"]:::backend
        L3["Database"]:::database
        L4["Event Sourcing"]:::event
        L5["Infrastructure"]:::infra
        L6["Domain"]:::domain
    end
```
