# devmentors/group-flights-ddd architecture

> Architecture diagram of the GitHub repository devmentors/group-flights-ddd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/devmentors/group-flights-ddd
- Repository: https://github.com/devmentors/group-flights-ddd

## Overview

##### Project type and purpose
- This is a .NET-based **modular monolith** implementing a group flight booking system (“GroupFlights”) using **Domain-Driven Design**.
- It consists of multiple **bounded contexts** (Inquiries, Sales, Backoffice, Finance, Postsale, TimeManagement, WorkloadManagement, Communication) plus a central API gateway and shared libraries.
- Purpose: handle the end-to-end process of group flight inquiries, offer creation, reservation, contract generation, payment, post-sale changes and associated deadlines/workload management.

##### File structure
- **src/Api/GroupFlights.Api**: the HTTP gateway, routes requests to modules.
- **src/[Module]/** (e.g. Inquiries, Sales, Finance, etc.): each contains
- Api project: exposes REST endpoints
- Core project: domain model, services, repositories, DTOs
- Shared project: integration contracts (ModuleApi, Shared DTOs, IntegrationEvents)
- Infrastructure (for some): EF Core configurations, DB contexts, migrations
- **src/Shared/GroupFlights.Shared.Plumbing**: in-memory command/event/query dispatcher, user-context.
- **src/Shared/GroupFlights.Shared.ModuleDefinition**: endpoint registration, shared contracts.
- **src/_ExternalSystems**: FakePaymentGateway emulating an external payment service.
- **docker-compose.yml** and SQL scripts configure a **Postgres** database with separate schemas per module.
- No external message broker: modules integrate via **in-memory event dispatcher**.

##### Key architectural insights from README
- Modular monolith with **separate schemas** for each module in a single Postgres instance.
- Integration patterns: synchronous REST (shared contracts) and asynchronous in-memory events with deliberate delivery delays.
- Each module may implement one of three persistence styles: JSON-serialized aggregates, CRUD, or rich domain model with EF.
- Commands/Queries separation, Clean Architecture in non-trivial modules.

##### Main components
A. **API Gateway** (GroupFlights.Api)
B. **Bounded Context Modules** (each deployed within the same process):
1. Inquiries
2. Sales
3. Backoffice
4. Finance
5. Postsale
6. TimeManagement
7. WorkloadManagement
8. Communication
C. **Shared Libraries** (Plumbing, ModuleDefinition, Types)
D. **Database** (Postgres with multiple schemas)
E. **External Payment Gateway** (FakePaymentGateway)
F. **Clients**: Web/Console users issuing HTTP calls (via .http scenario files)

##### Relationships and interactions
- **Clients → API Gateway**: HTTP/JSON requests with header-based naive auth (`X-UserId`, `X-CashierId`).
- **Gateway → Module APIs**: routes to the correct module based on URL path.
- **Module APIs → Core**: each module’s API calls its Core services/repositories.
- **Core → Database**: using EF Core (per-module DbContext) or JSON storage.
- **Core → Shared Plumbing**: dispatch commands/queries/events in-memory.
- **Event Flow**: e.g., Sales emits `ContractGenerationRequested` → Backoffice handles it → Backoffice emits `ContractSignedIntegrationEvent` → Sales/Postsale react → TimeManagement schedules deadlines → modules react to `DeadlineOverdueIntegrationEvent`, etc.
- **External Calls**: Finance calls FakePaymentGateway REST; FakePaymentGateway pushes back a payment-completed webhook.
- **WorkloadManagement**: tracks and validates cashier workload assignments.
- **Communication**: publishes messages (console email simulation).

##### Architectural patterns and principles
- **Modular Monolith**: modules are independent at the code and DB schema level but run in one process.
- **Bounded Contexts** with Clear APIs and Integration Events.
- **Clean Architecture** in complex modules: separation between Api, Application (commands/queries), Domain (entities, value objects), Infrastructure.
- **CQRS-style** separation between command handlers and query handlers.
- **In-Memory Event Bus**: for eventual consistency and async flows without external broker.
- **Schema-per-Module**: isolation of data stores.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    Browser["Web / HTTP Client"]:::external
    Scenarios["Scenario Files"]:::external

    %% API Gateway
    APIGateway["GroupFlights.Api"]:::gateway

    Browser -->|HTTP/JSON| APIGateway
    Scenarios -->|HTTP/JSON| APIGateway

    %% Monolith Process
    subgraph "Monolith Process"
        direction TB

        %% Shared Libraries
        subgraph "Shared Libraries"
            direction TB
            Plumbing["Shared.Plumbing\n(In-Memory Event Bus)"]:::shared
            ModuleDef["Shared.ModuleDefinition"]:::shared
            Types["Shared.Types"]:::shared
        end

        %% Inquiries Module
        subgraph "Inquiries" 
            direction TB
            InqApi["Inquiries.Api"]:::inquiries
            InqCore["Inquiries.Core"]:::inquiries
        end

        %% Sales Module
        subgraph "Sales"
            direction TB
            SalesApi["Sales.Api"]:::sales
            SalesApp["Sales.Application"]:::sales
            SalesDom["Sales.Domain"]:::sales
            SalesInfra["Sales.Infrastructure"]:::sales
            SalesShared["Sales.Shared"]:::sales
        end

        %% Backoffice Module
        subgraph "Backoffice"
            direction TB
            BOApi["Backoffice.Api"]:::backoffice
            BOCore["Backoffice.Core"]:::backoffice
            BOShared["Backoffice.Shared"]:::backoffice
        end

        %% Finance Module
        subgraph "Finance"
            direction TB
            FinApi["Finance.Api"]:::finance
            FinCore["Finance.Core"]:::finance
            FinShared["Finance.Shared"]:::finance
        end

        %% Postsale Module
        subgraph "Postsale"
            direction TB
            PSApi["Postsale.Api"]:::postsale
            PSApp["Postsale.Application"]:::postsale
            PSDom["Postsale.Domain"]:::postsale
            PSInfra["Postsale.Infrastructure"]:::postsale
            PSShared["Postsale.Shared"]:::postsale
        end

        %% TimeManagement Module
        subgraph "TimeManagement"
            direction TB
            TMApi["TimeManagement.Api"]:::time
            TMCore["TimeManagement.Core"]:::time
            TMShared["TimeManagement.Shared"]:::time
        end

        %% WorkloadManagement Module
        subgraph "WorkloadManagement"
            direction TB
            WMApi["WorkloadManagement.Api"]:::workload
            WMCore["WorkloadManagement.Core"]:::workload
            WMShared["WorkloadManagement.Shared"]:::workload
        end

        %% Communication Module
        subgraph "Communication"
            direction TB
            ComApi["Communication.Api"]:::communication
            ComCore["Communication.Core"]:::communication
            ComShared["Communication.Shared"]:::communication
        end
    end

    %% External Systems and DB
    subgraph "External Systems"
        FakePay["FakePaymentGateway"]:::external
    end

    DB["Postgres\n(Multi-Schema)"]:::db

    %% Gateway to Modules
    APIGateway -->|Routes to| InqApi
    APIGateway -->|Routes to| SalesApi
    APIGateway -->|Routes to| BOApi
    APIGateway -->|Routes to| FinApi
    APIGateway -->|Routes to| PSApi
    APIGateway -->|Routes to| TMApi
    APIGateway -->|Routes to| WMApi
    APIGateway -->|Routes to| ComApi

    %% API to Core
    InqApi -->|Calls| InqCore
    SalesApi -->|Calls| SalesApp
    SalesApp -->|Domain| SalesDom
    SalesDom -->|Infra Persistence| SalesInfra
    BOApi -->|Calls| BOCore
    FinApi -->|Calls| FinCore
    PSApi -->|Calls| PSApp
    PSApp -->|Domain| PSDom
    PSDom -->|Infra Persistence| PSInfra
    TMApi -->|Calls| TMCore
    WMApi -->|Calls| WMCore
    ComApi -->|Calls| ComCore

    %% Core to Shared & DB
    InqCore -->|Dispatch| Plumbing
    SalesApp -->|Dispatch| Plumbing
    BOCore -->|Dispatch| Plumbing
    FinCore -->|Dispatch| Plumbing
    PSApp -->|Dispatch| Plumbing
    TMCore -->|Dispatch| Plumbing
    WMCore -->|Dispatch| Plumbing
    ComCore -->|Dispatch| Plumbing

    InqCore -->|Reads/Writes| DB
    SalesInfra -->|Reads/Writes| DB
    BOCore -->|Reads/Writes| DB
    FinCore -->|Reads/Writes| DB
    PSInfra -->|Reads/Writes| DB
    TMCore -->|Reads/Writes| DB
    WMCore -->|Reads/Writes| DB
    ComCore -->|Reads/Writes| DB

    %% Finance external payment
    FinCore -->|REST Call| FakePay
    FakePay -->|Webhook| FinCore

    %% Click Events
    click APIGateway "https://github.com/devmentors/group-flights-ddd/blob/master/src/Api/GroupFlights.Api"
    click InqApi "https://github.com/devmentors/group-flights-ddd/blob/master/src/Inquiries/GroupFlights.Inquiries.Api"
    click InqCore "https://github.com/devmentors/group-flights-ddd/blob/master/src/Inquiries/GroupFlights.Inquiries.Core"
    click SalesApi "https://github.com/devmentors/group-flights-ddd/blob/master/src/Sales/GroupFlights.Sales.Api"
    click SalesApp "https://github.com/devmentors/group-flights-ddd/blob/master/src/Sales/GroupFlights.Sales.Application"
    click SalesDom "https://github.com/devmentors/group-flights-ddd/blob/master/src/Sales/GroupFlights.Sales.Domain"
    click SalesInfra "https://github.com/devmentors/group-flights-ddd/blob/master/src/Sales/GroupFlights.Sales.Infrastructure"
    click SalesShared "https://github.com/devmentors/group-flights-ddd/blob/master/src/Sales/GroupFlights.Sales.Shared"
    click BOApi "https://github.com/devmentors/group-flights-ddd/blob/master/src/Backoffice/GroupFlights.Backoffice.Api"
    click BOCore "https://github.com/devmentors/group-flights-ddd/blob/master/src/Backoffice/GroupFlights.Backoffice.Core"
    click BOShared "https://github.com/devmentors/group-flights-ddd/blob/master/src/Backoffice/GroupFlights.Backoffice.Shared"
    click FinApi "https://github.com/devmentors/group-flights-ddd/blob/master/src/Finance/GroupFlights.Finance.Api"
    click FinCore "https://github.com/devmentors/group-flights-ddd/blob/master/src/Finance/GroupFlights.Finance.Core"
    click FinShared "https://github.com/devmentors/group-flights-ddd/blob/master/src/Finance/GroupFlights.Finance.Shared"
    click PSApi "https://github.com/devmentors/group-flights-ddd/blob/master/src/Postsale/GroupFlights.Postsale.Api"
    click PSApp "https://github.com/devmentors/group-flights-ddd/blob/master/src/Postsale/GroupFlights.Postsale.Application"
    click PSDom "https://github.com/devmentors/group-flights-ddd/blob/master/src/Postsale/GroupFlights.Postsale.Domain"
    click PSInfra "https://github.com/devmentors/group-flights-ddd/blob/master/src/Postsale/GroupFlights.Postsale.Infrastructure"
    click PSShared "https://github.com/devmentors/group-flights-ddd/blob/master/src/Postsale/GroupFlights.Postsale.Shared"
    click TMApi "https://github.com/devmentors/group-flights-ddd/blob/master/src/TimeManagement/GroupFlights.TimeManagement.Api"
    click TMCore "https://github.com/devmentors/group-flights-ddd/blob/master/src/TimeManagement/GroupFlights.TimeManagement.Core"
    click TMShared "https://github.com/devmentors/group-flights-ddd/blob/master/src/TimeManagement/GroupFlights.TimeManagement.Shared"
    click WMApi "https://github.com/devmentors/group-flights-ddd/blob/master/src/WorkloadManagement/GroupFlights.WorkloadManagement.Api"
    click WMCore "https://github.com/devmentors/group-flights-ddd/blob/master/src/WorkloadManagement/GroupFlights.WorkloadManagement.Core"
    click WMShared "https://github.com/devmentors/group-flights-ddd/blob/master/src/WorkloadManagement/GroupFlights.WorkloadManagement.Shared"
    click ComApi "https://github.com/devmentors/group-flights-ddd/blob/master/src/Communication/GroupFlights.Communication.Api"
    click ComCore "https://github.com/devmentors/group-flights-ddd/blob/master/src/Communication/GroupFlights.Communication.Core"
    click ComShared "https://github.com/devmentors/group-flights-ddd/blob/master/src/Communication/GroupFlights.Communication.Shared"
    click Plumbing "https://github.com/devmentors/group-flights-ddd/blob/master/src/Shared/GroupFlights.Shared.Plumbing"
    click ModuleDef "https://github.com/devmentors/group-flights-ddd/blob/master/src/Shared/GroupFlights.Shared.ModuleDefinition"
    click Types "https://github.com/devmentors/group-flights-ddd/blob/master/src/Shared/GroupFlights.Shared.Types"
    click FakePay "https://github.com/devmentors/group-flights-ddd/tree/master/src/_ExternalSystems/FakePaymentGateway"
    click Scenarios "https://github.com/devmentors/group-flights-ddd/tree/master/src/_Scenarios"

    %% Styles
    classDef gateway fill:#ffcc00,stroke:#333,stroke-width:1px
    classDef inquiries fill:#f9f,stroke:#333
    classDef sales fill:#ff9,stroke:#333
    classDef backoffice fill:#9f9,stroke:#333
    classDef finance fill:#9ff,stroke:#333
    classDef postsale fill:#fcf,stroke:#333
    classDef time fill:#cff,stroke:#333
    classDef workload fill:#fcf,stroke:#333
    classDef communication fill:#cfc,stroke:#333
    classDef shared fill:#eee,stroke:#333
    classDef external fill:#ddd,stroke:#333
    classDef db fill:#bbb,stroke:#333,stroke-dasharray: 5 5
```
