# wernerreyes/c24_5_2024-1_g8b_vamosexpeditions-backend architecture

> Architecture diagram of the GitHub repository wernerreyes/c24_5_2024-1_g8b_vamosexpeditions-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wernerreyes/c24_5_2024-1_g8b_vamosexpeditions-backend
- Repository: https://github.com/wernerreyes/c24_5_2024-1_g8b_vamosexpeditions-backend

## Overview

##### Main System Components

a) Presentation Layer (API Layer)
- Controllers, Routes, and Services for:
- Authentication
- Clients
- Hotels
- Reservations
- Quotations
- Version Quotations
- Countries

b) Domain Layer
- Entities
- DTOs (Data Transfer Objects)
- Error Handling

c) Core Layer
- Adapters (BCrypt, JWT, Cache)
- Constants
- Utils

d) Data Layer
- PostgreSQL Database
- Prisma ORM

e) External Services
- Email Service (Nodemailer)
- PDF Generation (PDFMake)

##### Component Relationships

a) Client Request Flow:
**Client Request → Routes → Controllers → Services → Domain Layer ↔ Data Layer**

b) Authentication Flow:
**Auth Request → Auth Controller → JWT Adapter → User Entity ↔ Database**

c) External Services Integration:
**Services → Email Service**
**Services → PDF Service**

##### Specific Design Elements

Use the following visual elements:

- Hexagons: Core business entities
- Blue: Presentation Layer
- Green: Domain Layer
- Yellow: Core Layer
- Red: Data Layer
- Purple: External Services

##### Key Architectural Patterns to Highlight

a) Clean Architecture:
- Clear separation between layers
- Demonstrate dependency flow from outer to inner layers
- Domain-driven design approach

b) Repository Pattern:
- Data access abstraction through Prisma
- Separation between business logic and data access

c) Adapter Pattern:
- External service integrations
- How core functionality is adapted to external services

##### Important Details

a) Authentication & Authorization:
- JWT flow
- Middleware placement
- Role-based access control

b) Data Flow:
- DTO transformations
- Entity relationships
- Validation points

c) External Integrations:
- Email service connection
- PDF generation flow
- External API connections (if any)

##### Technical Stack Indicators

- Node.js + Express
- TypeScript
- Prisma ORM
- PostgreSQL
- JWT
- BCrypt
- Nodemailer
- PDFMake

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CL[Client Request]
    end

    subgraph "Presentation Layer"
        RT["Routes"]
        AC["Authentication"]:::controller
        CC["Clients"]:::controller
        HC["Hotels"]:::controller
        RC["Reservations"]:::controller
        QC["Quotations"]:::controller
        VQC["Version Quotations"]:::controller
        COC["Countries"]:::controller
        SV["Server"]:::server
    end

    subgraph "Domain Layer"
        EN["Entities"]:::domain
        DTO["DTOs"]:::domain
        ERR["Error Handling"]:::domain
    end

    subgraph "Core Layer"
        BC["BCrypt Adapter"]:::core
        JW["JWT Adapter"]:::core
        CA["Cache Adapter"]:::core
        CN["Constants"]:::core
        UT["Utils"]:::core
    end

    subgraph "Data Layer"
        DB[(PostgreSQL)]:::database
        PR["Prisma ORM"]:::orm
    end

    subgraph "External Services"
        EM["Email Service"]:::external
        PDF["PDF Generation"]:::external
    end

    %% Connections
    CL --> RT
    RT --> AC & CC & HC & RC & QC & VQC & COC
    AC & CC & HC & RC & QC & VQC & COC --> EN
    AC & CC & HC & RC & QC & VQC & COC --> DTO
    EN & DTO --> PR
    PR --> DB
    AC --> JW
    AC --> BC
    RC & QC --> EM
    QC --> PDF
    AC & CC & HC & RC & QC & VQC & COC --> ERR
    AC & CC & HC & RC & QC & VQC & COC --> CA

    %% Click Events
    click AC "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/tree/main/src/presentation/auth/"
    click CC "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/tree/main/src/presentation/client/"
    click HC "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/tree/main/src/presentation/hotel/"
    click RC "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/tree/main/src/presentation/reservation/"
    click QC "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/tree/main/src/presentation/quotation/"
    click VQC "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/tree/main/src/presentation/versionQuotation/"
    click COC "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/tree/main/src/presentation/country/"
    click EN "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/tree/main/src/domain/entities/"
    click DTO "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/tree/main/src/domain/dtos/"
    click ERR "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/tree/main/src/domain/error/"
    click BC "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/blob/main/src/core/adapters/bcrypt.adapter.ts"
    click JW "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/blob/main/src/core/adapters/jwt.adapter.ts"
    click CA "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/blob/main/src/core/adapters/cache.adapter.ts"
    click CN "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/tree/main/src/core/constants/"
    click UT "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/tree/main/src/core/utils/"
    click PR "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/blob/main/prisma/schema.prisma"
    click DB "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/tree/main/src/data/postgres/"
    click EM "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/blob/main/src/lib/nodemailer/email.service.ts"
    click PDF "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/blob/main/src/lib/pdfmake/pdf.service.ts"
    click SV "https://github.com/WernerReyes/C24_5_2024-1_G8B_VamosExpeditions-Backend/blob/main/src/presentation/server.ts"

    %% Styles
    classDef controller fill:#2196F3,stroke:#1565C0,color:white
    classDef domain fill:#4CAF50,stroke:#2E7D32,color:white
    classDef core fill:#FFC107,stroke:#FFA000,color:black
    classDef database fill:#F44336,stroke:#C62828,color:white
    classDef orm fill:#E91E63,stroke:#C2185B,color:white
    classDef external fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef server fill:#607D8B,stroke:#455A64,color:white

    %% Legend
    subgraph Legend
        L1["Controller"]:::controller
        L2["Domain"]:::domain
        L3["Core"]:::core
        L4["Database"]:::database
        L5["ORM"]:::orm
        L6["External Service"]:::external
    end
```
