# pcdaco/pcdaco-be architecture

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

- Interactive diagram: https://gitdiagram.com/pcdaco/pcdaco-be
- Repository: https://github.com/pcdaco/pcdaco-be

## Overview

##### Project Type & Purpose
- This is a backend API project for a full-stack application that connects car owners and drivers.
- It implements Clean Architecture with separate layers for Presentation (API), Application (UseCases/Business Logic), Domain, Infrastructure (services like email, payment, and encryption), and Persistence.
- That the overall flow supports features such as user management, car listings, booking transactions, contract management, and integrated third-party services.

##### Main Components
- Client: Mobile/Web clients (act as external systems).
- Presentation/API Layer: Contains the API endpoints (controllers) and middleware (e.g., authentication, exception handling).
- Application (UseCases) Layer: Encompasses business logic, including command/queries and background jobs for asynchronous processing.
- Domain Layer: The core of the system with domain entities (users, cars, bookings, etc.) and business rules.
- Infrastructure Layer: Implements services such as email, PayOS, encryption, and media handling.
- Persistence Layer: The database layer (using EF Core) and migrations for data storage.
- External Services: Integration points for Payment Gateways, SMS/Email providers, GPS tracking, and Cloud Media services.

##### Relationships & Interactions
- API Endpoints interact with multiple middleware components that manage request preprocessing and error handling.
- The Application layer consumes the business logic (commands and queries) and otherwise interacts with both the domain and infrastructure.
- The Infrastructure layer connects outward to external services such as the Payment Gateway and Cloud Media, and inward to the Domain and Application layers.
- Finally, the Persistence layer sits at the bottom, serving as the data-access implementation for saving domain entities.

##### Incorporate Architectural Patterns & Technologies
- Mention important technologies and frameworks (ASP.NET Core Web API, Entity Framework Core, .NET SDK, SQL Server/PostgreSQL).
- For background jobs, indicate microservices or scheduled job handling (booking expiration, reminders, etc.) located within the Application layer.
- Out the integration points with external services such as payment gateways and GPS tracking.

## Diagram (Mermaid)

```mermaid
graph TD
    Client["Client (Mobile/Web)"]:::external

    subgraph "Presentation/API Layer"
        APIEndpoints["API Endpoints"]:::api
        Middlewares["Middlewares"]:::api
    end

    subgraph "Application (UseCases) Layer"
        BusinessLogic["Business Logic (Commands/Queries)"]:::app
        BackgroundJobs["Background Jobs"]:::app
    end

    subgraph "Domain Layer"
        DomainEntities["Domain Entities & Business Rules"]:::domain
    end

    subgraph "Infrastructure Layer"
        EmailService["Email Service"]:::infra
        PayOSService["PayOS Service"]:::infra
        EncryptionService["Encryption Service"]:::infra
        MediasService["Medias Service"]:::infra
    end

    subgraph "Persistence Layer"
        Database["Database (EF Core)"]:::persistence
    end

    PaymentGateway["External Payment Gateway"]:::external
    SMSProvider["SMS/Email Provider"]:::external
    GPSTracking["GPS Tracking Service"]:::external
    CloudMedia["Cloud Media Service"]:::external

    %% Connections between layers
    Client -->|"calls"| APIEndpoints
    APIEndpoints -->|"preprocesses"| Middlewares
    APIEndpoints -->|"routes to"| BusinessLogic
    Middlewares -->|"handles errors for"| BusinessLogic
    BusinessLogic -->|"executes"| BackgroundJobs
    BusinessLogic -->|"invokes"| DomainEntities
    BackgroundJobs -->|"triggers"| DomainEntities

    %% Domain interaction with Infrastructure using dotted style to indicate dependency inversion
    DomainEntities -.->|"requires services from"| EmailService
    DomainEntities -.->|"requires services from"| PayOSService
    DomainEntities -.->|"requires services from"| EncryptionService
    DomainEntities -.->|"requires services from"| MediasService

    %% Infrastructure connections
    EmailService -->|"sends notifications via"| SMSProvider
    PayOSService -->|"integrates with"| PaymentGateway
    MediasService -->|"utilizes"| CloudMedia
    EncryptionService -->|"secures data in"| Database
    EmailService -->|"logs to"| Database
    PayOSService -->|"records transactions in"| Database
    MediasService -->|"stores metadata in"| Database

    %% External service for GPS Tracking
    DomainEntities -.->|"fetches location from"| GPSTracking

    %% Click events for component mapping
    click APIEndpoints "https://github.com/pcdaco/pcdaco-be/tree/main/src/API/Endpoints"
    click Middlewares "https://github.com/pcdaco/pcdaco-be/tree/main/src/API/Middlewares"
    click BusinessLogic "https://github.com/pcdaco/pcdaco-be/tree/main/src/UseCases"
    click BackgroundJobs "https://github.com/pcdaco/pcdaco-be/tree/main/src/UseCases/BackgroundServices"
    click DomainEntities "https://github.com/pcdaco/pcdaco-be/tree/main/src/Domain"
    click EmailService "https://github.com/pcdaco/pcdaco-be/tree/main/src/Infrastructure/EmailService"
    click PayOSService "https://github.com/pcdaco/pcdaco-be/tree/main/src/Infrastructure/PayOSService"
    click EncryptionService "https://github.com/pcdaco/pcdaco-be/tree/main/src/Infrastructure/Encryption"
    click MediasService "https://github.com/pcdaco/pcdaco-be/tree/main/src/Infrastructure/Medias"
    click Database "https://github.com/pcdaco/pcdaco-be/tree/main/src/Persistance"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:2px
    classDef api fill:#bbf,stroke:#333,stroke-width:2px
    classDef app fill:#fdb,stroke:#333,stroke-width:2px
    classDef domain fill:#dfd,stroke:#333,stroke-width:2px
    classDef infra fill:#ffd,stroke:#333,stroke-width:2px
    classDef persistence fill:#cfc,stroke:#333,stroke-width:2px
```
