# matheusfcorocher/shopping-cart architecture

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

- Interactive diagram: https://gitdiagram.com/matheusfcorocher/shopping-cart
- Repository: https://github.com/matheusfcorocher/shopping-cart

## Overview

##### Main Architectural Layers (Use vertical layers from top to bottom)

a. Interface Layer (Top)
- HTTP Controllers & Routes
- Serializers
- Swagger Documentation

b. Application Layer
- Use Cases (Cart, Product, Voucher operations)

c. Domain Layer
- Entities (Cart, Product, Buyer, Order, Voucher)
- Value Objects (Money, AppliedVoucher)
- Domain Services (CheckoutDomainService)
- Repository Interfaces

d. Infrastructure Layer (Bottom)
- Database (PostgreSQL)
- ORM (Objection.js)
- Repository Implementations

##### Component Relationships

- HTTP Routes → Controllers → Use Cases
- Use Cases → Domain Services/Entities
- Domain Layer → Repository Interfaces
- Repository Implementations → Database

##### Key Components

a. External Interface:
- Fastify Server
- Swagger UI
- API Endpoints (/cart, /product, /voucher)

b. Core Business Components:
- Cart Management
- Product Catalog
- Voucher System
- Checkout Process

c. Data Storage:
- PostgreSQL Database
- Knex Migrations
- Objection.js Models

##### Technical Details

- Technologies: TypeScript, Fastify, PostgreSQL, Objection.js
- Testing Framework: Jest
- Money Pattern Implementation
- Dependency Injection Container

##### Component Interactions

Specific flows for key operations:
- Product Listing
- Cart Management
- Voucher Application
- Checkout Process

##### External API endpoints

- Rectangles: Modules/Components
- Hexagons: Domain Entities
- Rounded Rectangles: Services
- Diamonds: Decision Points

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Interface
        HTTP[HTTP Controllers]
        SER[Serializers]
        SWAG[Swagger Documentation]
        ROUTES[Routes]
    end

    subgraph Application
        CART_UC[Cart Use Cases]
        PROD_UC[Product Use Cases]
        VOUCH_UC[Voucher Use Cases]
    end

    subgraph Domain
        direction TB
        subgraph Entities
            CART_E[Cart Entity]
            PROD_E[Product Entity]
            VOUCH_E[Voucher Entity]
            ORDER_E[Order Entity]
        end
        
        subgraph ValueObjects
            MONEY[Money VO]
            APP_VOUCH[AppliedVoucher VO]
        end
        
        DOM_SERV[Checkout Domain Service]
        REPO_INT[Repository Interfaces]
        DOM_FAC[Domain Factories]
    end

    subgraph Infrastructure
        DB_CONFIG[Database Config]
        ORM[ORM Models]
        REPO_IMPL[Repository Implementations]
        DB[(PostgreSQL)]
    end

    %% Relationships
    ROUTES --> HTTP
    HTTP --> SER
    HTTP --> CART_UC
    HTTP --> PROD_UC
    HTTP --> VOUCH_UC
    
    CART_UC --> DOM_SERV
    PROD_UC --> DOM_SERV
    VOUCH_UC --> DOM_SERV
    
    DOM_SERV --> CART_E
    DOM_SERV --> PROD_E
    DOM_SERV --> VOUCH_E
    DOM_SERV --> ORDER_E
    
    CART_E --> MONEY
    CART_E --> APP_VOUCH
    
    Domain --> REPO_INT
    REPO_IMPL --> DB
    REPO_INT --> REPO_IMPL
    
    %% Styling
    classDef interface fill:#e1f5fe,stroke:#01579b
    classDef application fill:#e8f5e9,stroke:#1b5e20
    classDef domain fill:#fff3e0,stroke:#e65100
    classDef infrastructure fill:#fff3e0,stroke:#bf360c
    
    class HTTP,SER,SWAG,ROUTES interface
    class CART_UC,PROD_UC,VOUCH_UC application
    class CART_E,PROD_E,VOUCH_E,ORDER_E,MONEY,APP_VOUCH,DOM_SERV,REPO_INT,DOM_FAC domain
    class DB_CONFIG,ORM,REPO_IMPL,DB infrastructure

    %% Click Events
    click HTTP "https://github.com/matheusfcorocher/shopping-cart/tree/main/src/interfaces/http/controllers/handlers/"
    click SER "https://github.com/matheusfcorocher/shopping-cart/tree/main/src/interfaces/http/controllers/serializers/"
    click SWAG "https://github.com/matheusfcorocher/shopping-cart/blob/main/src/config/swagger.ts"
    click ROUTES "https://github.com/matheusfcorocher/shopping-cart/tree/main/src/interfaces/http/routes/"
    click CART_UC "https://github.com/matheusfcorocher/shopping-cart/tree/main/src/application/Cart/"
    click PROD_UC "https://github.com/matheusfcorocher/shopping-cart/tree/main/src/application/Product/"
    click VOUCH_UC "https://github.com/matheusfcorocher/shopping-cart/tree/main/src/application/Voucher/"
    click CART_E "https://github.com/matheusfcorocher/shopping-cart/blob/main/src/domain/entities/Cart.ts"
    click PROD_E "https://github.com/matheusfcorocher/shopping-cart/blob/main/src/domain/entities/Product.ts"
    click VOUCH_E "https://github.com/matheusfcorocher/shopping-cart/blob/main/src/domain/entities/Voucher.ts"
    click DOM_SERV "https://github.com/matheusfcorocher/shopping-cart/blob/main/src/domain/services/CheckoutDomainService.ts"
    click REPO_INT "https://github.com/matheusfcorocher/shopping-cart/tree/main/src/domain/repositories/"
    click DOM_FAC "https://github.com/matheusfcorocher/shopping-cart/tree/main/src/domain/factories/"
    click DB_CONFIG "https://github.com/matheusfcorocher/shopping-cart/tree/main/src/infra/database/"
    click ORM "https://github.com/matheusfcorocher/shopping-cart/tree/main/src/infra/database/knex/models/"
    click REPO_IMPL "https://github.com/matheusfcorocher/shopping-cart/tree/main/src/infra/repositories/"
```
