# deroldan26/orangeteam-deliverybackend architecture

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

- Interactive diagram: https://gitdiagram.com/deroldan26/orangeteam-deliverybackend
- Repository: https://github.com/deroldan26/orangeteam-deliverybackend

## Overview

This project is a backend service for the GoDely delivery application built using NestJS. The README and file tree clearly indicate that the project is designed following the principles of Hexagonal Architecture (Ports and Adapters), Domain-Driven Design (DDD), and Aspect-Oriented Programming (AOP). The repository is structured into multiple bounded contexts or modules (such as audit, auth, category, combo, cupon, discount, order, product, and user) that encapsulate their own domain logic and infrastructure concerns.

##### Main Components to Highlight
a. Domain Core:
b. Application Layer:
- Surrounding the core, the application services and use-case logic such as command handlers, queries, and DTOs, which orchestrate and mediate interactions between the domain and the external layers. They are organized under src/*/application.
c. Infrastructure Layer:
- This layer contains the adapters that interact with external systems (e.g., repositories with Postgres entities, controllers for HTTP endpoints, authentication with JWT, event messaging via RabbitMQ, cloud storage via Cloudinary, email services, etc.). They are under directories like src/*/infrastructure.
d. Cross-Cutting Concerns:
- AOP elements such as decorators for logging, auditing, exception handling, and performance measurement are located in src/core/application/aspects.
e. External Services:
- External integrations such as:
- Database providers (e.g., PostgreSQL and MongoDB as seen in src/core/infrastructure/database).
- Messaging Services (RabbitMQ components).
- Cloud services (Cloudinary for image handling) and Email Sender.
- Authentication (using JWT and related guard modules).

##### Relationships and Interactions
- How the application layer interacts with the domain layer by invoking domain logic and emitting domain events.
- Adapters connecting the domain and application layers to infrastructure components (e.g., repositories that persist entities, mappers translating between domain objects and persistence models, DTO transformations, etc.).
- Cross-cutting concerns where decorators wrap service calls or controller methods.

##### Architectural Patterns and Design Principles
- Hexagonal Architecture by showing the domain core at the center with “ports” (interfaces in the domain) that are implemented by “adapters” (infrastructure repositories, controllers, etc.).
- Demonstrate the DDD approach by grouping modules (product, order, etc.) into their own bounded contexts.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Domain Core
    subgraph "Domain Core"
        PD["Product Domain\n(Entities, Aggregates)"]
        click PD "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/product/domain"
        OD["Order Domain\n(Entities, Aggregates)"]
        click OD "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/order/domain"
        CD["Category Domain"]
        click CD "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/category/domain"
        CBD["Combo Domain"]
        click CBD "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/combo/domain"
        CuD["Cupon Domain"]
        click CuD "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/cupon/domain"
        DD["Discount Domain"]
        click DD "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/discount/domain"
        UD["User Domain"]
        click UD "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/user/domain"
        AD["Audit Domain"]
        click AD "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/audit/domain"
    end

    %% Application Layer
    subgraph "Application Layer"
        PA["Product Application Service"]
        click PA "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/product/application"
        OA["Order Application Service"]
        click OA "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/order/application"
        CA["Category Application Service"]
        click CA "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/category/application"
        CBA["Combo Application Service"]
        click CBA "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/combo/application"
        CuA["Cupon Application Service"]
        click CuA "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/cupon/application"
        DA["Discount Application Service"]
        click DA "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/discount/application"
        UA["User Application Service"]
        click UA "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/user/application"
        AA["Auth Application Service"]
        click AA "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/auth/application"
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        %% Controllers/Adapters
        subgraph "Controllers & Adapters"
            AC["Auth Controller\n(HTTP, JWT)"]
            CAda["Category Adapter"]
            PAda["Product Adapter"]
            OAda["Order Adapter"]
            CBAda["Combo Adapter"]
            CuAda["Cupon Adapter"]
            DAda["Discount Adapter"]
            UAda["User Adapter"]
            AAda["Audit Adapter"]
        end

        %% Repositories & Persistence
        subgraph "Repositories & Persistence"
            PRepo["Product Repository"]
            click PRepo "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/product/infrastructure"
            ORepo["Order Repository"]
            click ORepo "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/order/infrastructure"
            CRepo["Category Repository"]
            click CRepo "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/category/infraestructure"
            CBRepo["Combo Repository"]
            click CBRepo "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/combo/infraestructure"
            CuRepo["Cupon Repository"]
            click CuRepo "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/cupon/infraestructure"
            DRepo["Discount Repository"]
            click DRepo "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/discount/infraestructure"
            URepo["User Repository"]
            click URepo "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/user/infrastructure"
            ARepo["Audit Repository"]
            click ARepo "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/audit/infrastructure"
        end

        %% External Integrations
        subgraph "External Integrations"
            PG["Postgres DB"]
            click PG "https://github.com/deroldan26/orangeteam-deliverybackend/blob/main/src/core/infrastructure/database/postgresSQL/postgresProvider.ts"
            MG["MongoDB"]
            click MG "https://github.com/deroldan26/orangeteam-deliverybackend/blob/main/src/core/infrastructure/database/mongodb/mongoProvider.ts"
            RMQ["RabbitMQ Messaging"]
            click RMQ "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/core/infrastructure/events/rabbitmq"
            CLD["Cloudinary (Media)"]
            click CLD "https://github.com/deroldan26/orangeteam-deliverybackend/blob/main/src/core/infrastructure/cloudinary/cloudinary.ts"
            ES["Email Sender"]
            click ES "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/core/infrastructure/emailsender"
            JWT["JWT Service"]
            click JWT "https://github.com/deroldan26/orangeteam-deliverybackend/blob/main/src/auth/infraestructure/jwt/jwt.service.ts"
            AG["Auth Guard"]
            click AG "https://github.com/deroldan26/orangeteam-deliverybackend/blob/main/src/auth/infraestructure/guard/guard.service.ts"
            IDG["ID Generator Service"]
            click IDG "https://github.com/deroldan26/orangeteam-deliverybackend/blob/main/src/core/infrastructure/id.generator.ts"
        end
    end

    %% Cross-Cutting Concerns
    subgraph "Cross-Cutting Concerns"
        AOP["Application Aspects\n(Logging, Auditing, Exception Handling)"]
        click AOP "https://github.com/deroldan26/orangeteam-deliverybackend/tree/main/src/core/application/aspects"
    end

    %% Interactions and Data Flow

    %% HTTP Requests flow from Controllers to Application Layer
    AC -->|"handles"| AA
    CAda -->|"calls"| CA
    PAda -->|"calls"| PA
    OAda -->|"calls"| OA
    CBAda -->|"calls"| CBA
    CuAda -->|"calls"| CuA
    DAda -->|"calls"| DA
    UAda -->|"calls"| UA
    AAda -->|"triggers"| AD

    %% Application Layer invoking Domain Logic
    PA -->|"invokes"| PD
    OA -->|"invokes"| OD
    CA -->|"invokes"| CD
    CBA -->|"invokes"| CBD
    CuA -->|"invokes"| CuD
    DA -->|"invokes"| DD
    UA -->|"invokes"| UD
    AA -->|"authenticates"| PD

    %% Application Layer persisting data via Repositories
    PA -->|"persists"| PRepo
    OA -->|"persists"| ORepo
    CA -->|"persists"| CRepo
    CBA -->|"persists"| CBRepo
    CuA -->|"persists"| CuRepo
    DA -->|"persists"| DRepo
    UA -->|"persists"| URepo

    %% Repositories interfacing with Databases
    PRepo -->|"queries"| PG
    ORepo -->|"queries"| PG
    ORepo -->|"or"| MG
    CRepo -->|"queries"| PG
    CBRepo -->|"queries"| PG
    CuRepo -->|"queries"| PG
    DRepo -->|"queries"| PG
    URepo -->|"queries"| PG
    ARepo -->|"logs to"| PG

    %% Domain emitting events to Messaging
    PD -->|"emits events"| RMQ
    OD -->|"emits events"| RMQ
    CD -->|"emits events"| RMQ

    %% Authentication and ID generation interactions
    AA -->|"generatesToken"| JWT
    AA -->|"checksToken"| AG
    PA -->|"generatesID"| IDG

    %% Cross-Cutting Aspects wrapping Application logic
    AOP -->|"wraps"| PA
    AOP -->|"wraps"| OA
    AOP -->|"wraps"| CA
    AOP -->|"wraps"| CBA
    AOP -->|"wraps"| CuA
    AOP -->|"wraps"| DA
    AOP -->|"wraps"| UA
    AOP -->|"wraps"| AA

    %% External Integrations with Controllers/Adapters
    CLD -->|"handlesMedia"| PAda
    ES -->|"sendsEmails"| UAda
    AC -->|"intercepts"| AOP

    %% Styling Definitions
    class PD,OD,CD,CBD,CuD,DD,UD,AD domainCore;
    class PA,OA,CA,CBA,CuA,DA,UA,AA appLayer;
    class AC,CAda,PAda,OAda,CBAda,CuAda,DAda,UAda,AAda repoAdapter;
    class PRepo,ORepo,CRepo,CBRepo,CuRepo,DRepo,URepo,ARepo persistence;
    class PG,MG,RMQ,CLD,ES,JWT,AG,IDG extServices;
    class AOP aop;

    classDef domainCore fill:#FFE0B2,stroke:#F57C00,stroke-width:2px;
    classDef appLayer fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef repoAdapter fill:#BBDEFB,stroke:#1976D2,stroke-width:2px;
    classDef persistence fill:#D1C4E9,stroke:#7B1FA2,stroke-width:2px;
    classDef extServices fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef aop fill:#D7CCC8,stroke:#5D4037,stroke-width:2px;
```
