# felipecal/ride-hailing architecture

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

- Interactive diagram: https://gitdiagram.com/felipecal/ride-hailing
- Repository: https://github.com/felipecal/ride-hailing

## Overview

##### Project Overview
- The project is a modular ride-hailing application built following Clean Architecture principles. It is divided into three main modules:
- Account: Manages user accounts and authentication.
- Payment: Handles transactions and payment processing.
- Ride: Manages ride requests, ride statuses, and integration with other modules.
- External dependencies include a PostgreSQL database and RabbitMQ for messaging, as indicated in the README.

##### Main Components and Layers
a. Domain Layer – Entities, Value Objects, domain logic, and events (for example, Account, Transaction, Ride, RideCompleted event, etc.).
b. Application Layer – Use cases (e.g., Signup, GetAccount, ProcessPayment, RequestRide, AcceptRide etc.) that orchestrate business logic.
c. Infrastructure Layer – Adapters for database connections, HTTP controllers, gateways (MailerGateway, PaymentGateways, AccountGateway), repository implementations, ORM, and queues.

##### Relationships and Interactions
- That the Ride module communicates with the Account and Payment modules through adapter/gateway implementations (e.g., AccountGatewayHttp and PaymentGatewayHttp) to perform validations, payments, and share status updates.
- How repository components interact with the external PostgreSQL database.
- Message Queue (RabbitMQ) flows for event-driven actions, such as queuing ride events or payment notifications.
- Integration points with external dependencies (PostgreSQL, RabbitMQ).

##### Architectural Patterns and Technologies
- Use of Clean Architecture with a clear separation between layers.
- Use of specific technologies:
- Node.js/TypeScript for the modules (inferred from file extensions and configuration files such as tsconfig.json and package.json).
- PostgreSQL for persistent storage (indicated by create.sql and docker command).
- RabbitMQ for asynchronous processing and event handling.
- Testing frameworks (jest) as seen in the test folders.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Account Module
    subgraph "Account Module"
        subgraph "Domain"
            A1["Account Entity"]:::domain
            A2["Account VOs"]:::domain
        end
        subgraph "Application"
            A3["GetAccount UseCase"]:::application
            A4["Signup UseCase"]:::application
        end
        subgraph "Infrastructure"
            A5["AccountController"]:::infrastructure
            A6["AccountRepository"]:::infrastructure
            A7["DatabaseConnection"]:::infrastructure
            A8["MailerGateway"]:::infrastructure
            A9["HttpServer"]:::infrastructure
        end
    end

    %% Payment Module
    subgraph "Payment Module"
        subgraph "Domain"
            P1["Transaction Entity"]:::domain
        end
        subgraph "Application"
            P2["GetTransaction UseCase"]:::application
            P3["ProcessPayment UseCase"]:::application
            P4["PaymentGateway Abstraction"]:::application
        end
        subgraph "Infrastructure"
            P5["DatabaseConnection"]:::infrastructure
            P6["CieloGateway"]:::infrastructure
            P7["PJBankGateway"]:::infrastructure
            P8["PaymentController"]:::infrastructure
            P9["ORM/TransactionModel"]:::infrastructure
            P10["Queue"]:::infrastructure
            P11["QueueController"]:::infrastructure
            P12["TransactionRepositoryDatabase"]:::infrastructure
            P13["TransactionRepositoryORM"]:::infrastructure
        end
    end

    %% Ride Module
    subgraph "Ride Module"
        subgraph "Domain"
            R1["Ride Entity"]:::domain
            R2["Position Entity"]:::domain
            R3["CalculateFare (DS)"]:::domain
            R4["DistanceCalculator (DS)"]:::domain
            R5["RideCompleted Event"]:::domain
        end
        subgraph "Application"
            R6["RequestRide UseCase"]:::application
            R7["StartRide UseCase"]:::application
            R8["AcceptRide UseCase"]:::application
            R9["FinishRide UseCase"]:::application
            R10["ProcessPayment UseCase"]:::application
            R11["UpdatePosition UseCase"]:::application
            R12["GetRide UseCase"]:::application
        end
        subgraph "Infrastructure"
            R13["DatabaseConnection"]:::infrastructure
            R14["DI Registry"]:::infrastructure
            R15["AccountGatewayHttp"]:::infrastructure
            R16["PaymentGatewayHttp"]:::infrastructure
            R17["HttpClient"]:::infrastructure
            R18["HttpServer"]:::infrastructure
            R19["Mediator"]:::infrastructure
            R20["Observable"]:::infrastructure
            R21["Queue"]:::infrastructure
            R22["queue_consumer"]:::infrastructure
            R23["queue_producer"]:::infrastructure
            R24["PositionRepository"]:::infrastructure
            R25["RideRepository"]:::infrastructure
        end
    end

    %% External Systems
    subgraph "External Systems"
        E1["PostgreSQL Database"]:::external
        E2["RabbitMQ Message Queue"]:::external
    end

    %% Account Module Connections
    A9 -->|"routes"| A5
    A5 -->|"calls"| A3
    A5 -->|"calls"| A4
    A3 -->|"executes"| A1
    A4 -->|"executes"| A1
    A6 -->|"uses"| A7
    A7 -->|"connects"| E1
    A4 -->|"notifies"| A8

    %% Payment Module Connections
    P8 -->|"routes"| P2
    P8 -->|"routes"| P3
    P2 -->|"executes"| P1
    P3 -->|"executes"| P1
    P4 -->|"abstracts"| P1
    P6 -->|"feeds"| P4
    P7 -->|"feeds"| P4
    P12 -->|"implements"| P5
    P13 -->|"implements"| P5
    P5 -->|"connects"| E1
    P11 -->|"manages"| P10
    P10 -->|"queues"| E2

    %% Ride Module Connections
    R18 -->|"routes"| R6
    R6 -->|"initiates"| R1
    R7 -->|"initiates"| R1
    R8 -->|"initiates"| R1
    R9 -->|"finishes"| R1
    R10 -->|"integrates"| R1
    R11 -->|"updates"| R2
    R12 -->|"fetches"| R1
    R15 -->|"communicates"| A9
    R16 -->|"communicates"| P8
    R24 -->|"accesses"| R13
    R25 -->|"accesses"| R13
    R13 -->|"connects"| E1
    R22 -->|"consumes"| R21
    R23 -->|"produces"| R21
    R21 -->|"queues"| E2

    %% Styles
    classDef domain fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef application fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px;

    %% Click Events for Account Module
    click A1 "https://github.com/felipecal/ride-hailing/blob/main/account/src/domain/entity/Account.ts"
    click A2 "https://github.com/felipecal/ride-hailing/tree/main/account/src/domain/vo"
    click A3 "https://github.com/felipecal/ride-hailing/blob/main/account/src/application/usecase/GetAccount.ts"
    click A4 "https://github.com/felipecal/ride-hailing/blob/main/account/src/application/usecase/Signup.ts"
    click A5 "https://github.com/felipecal/ride-hailing/blob/main/account/src/infra/http/AccountController.ts"
    click A6 "https://github.com/felipecal/ride-hailing/blob/main/account/src/infra/repository/AccountRepository.ts"
    click A7 "https://github.com/felipecal/ride-hailing/blob/main/account/src/infra/database/DatabaseConnection.ts"
    click A8 "https://github.com/felipecal/ride-hailing/blob/main/account/src/infra/gateway/MailerGateway.ts"
    click A9 "https://github.com/felipecal/ride-hailing/blob/main/account/src/infra/http/HttpServer.ts"

    %% Click Events for Payment Module
    click P1 "https://github.com/felipecal/ride-hailing/blob/main/payment/src/domain/Transaction.ts"
    click P2 "https://github.com/felipecal/ride-hailing/blob/main/payment/src/application/usecase/GetTransaction.ts"
    click P3 "https://github.com/felipecal/ride-hailing/blob/main/payment/src/application/usecase/ProcessPayment.ts"
    click P4 "https://github.com/felipecal/ride-hailing/blob/main/payment/src/application/gateway/PaymentGateway.ts"
    click P5 "https://github.com/felipecal/ride-hailing/blob/main/payment/src/infra/database/DatabaseConnection.ts"
    click P6 "https://github.com/felipecal/ride-hailing/blob/main/payment/src/infra/gateway/CieloGateway.ts"
    click P7 "https://github.com/felipecal/ride-hailing/blob/main/payment/src/infra/gateway/PJBankGateway.ts"
    click P8 "https://github.com/felipecal/ride-hailing/blob/main/payment/src/infra/http/PaymentController.ts"
    click P9 "https://github.com/felipecal/ride-hailing/blob/main/payment/src/infra/orm/TransactionModel.ts"
    click P10 "https://github.com/felipecal/ride-hailing/blob/main/payment/src/infra/queue/Queue.ts"
    click P11 "https://github.com/felipecal/ride-hailing/blob/main/payment/src/infra/queue/QueueController.ts"
    click P12 "https://github.com/felipecal/ride-hailing/blob/main/payment/src/infra/repository/TransactionRepositoryDatabase.ts"
    click P13 "https://github.com/felipecal/ride-hailing/blob/main/payment/src/infra/repository/TransactionRepositoryORM.ts"

    %% Click Events for Ride Module
    click R1 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/domain/entity/Ride.ts"
    click R2 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/domain/entity/Position.ts"
    click R3 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/domain/ds/CalculateFare.ts"
    click R4 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/domain/ds/DistanceCalculator.ts"
    click R5 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/domain/event/RideCompleted.ts"
    click R6 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/application/usecase/RequestRide.ts"
    click R7 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/application/usecase/StartRide.ts"
    click R8 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/application/usecase/AcceptRide.ts"
    click R9 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/application/usecase/FinishRide.ts"
    click R10 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/application/usecase/ProcessPayment.ts"
    click R11 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/application/usecase/UpdatePosition.ts"
    click R12 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/application/usecase/GetRide.ts"
    click R13 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/infra/database/DatabaseConnection.ts"
    click R14 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/infra/di/Registry.ts"
    click R15 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/infra/gateway/AccountGatewayHttp.ts"
    click R16 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/infra/gateway/PaymentGatewayHttp.ts"
    click R17 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/infra/http/HttpClient.ts"
    click R18 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/infra/http/HttpServer.ts"
    click R19 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/infra/mediator/Mediator.ts"
    click R20 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/infra/mediator/Observable.ts"
    click R21 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/infra/queue/Queue.ts"
    click R22 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/infra/queue/queue_consumer.ts"
    click R23 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/infra/queue/queue_producer.ts"
    click R24 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/infra/repository/PositionRepository.ts"
    click R25 "https://github.com/felipecal/ride-hailing/blob/main/ride/src/infra/repository/RideRepository.ts"
```
