# luongquockhang/bookingsystem architecture

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

- Interactive diagram: https://gitdiagram.com/luongquockhang/bookingsystem
- Repository: https://github.com/luongquockhang/bookingsystem

## Overview

##### Project type and purpose
- It’s a full-stack, microservices-based booking system.
- Components include:
– React single-page app (“webapp”)
– API Gateway (Ocelot)
– Identity Server for authentication/authorization
– Microservices: Stay, Promotion (API + gRPC), Cars, Flight, Booking, Experiences, Payment (API + background processor), Trips
– Databases (SQL Server, PostgreSQL, EF Core contexts, Redis TODO)
– Cross-cutting infra: centralized logging (ELK), health checks, resilience (Polly), Docker Compose

##### Main components
A. User-facing clients
– React Webapp
B. Edge services
– API Gateway (Ocelot)
– Identity Server (Duende IdentityServer + ASP.NET Core)
C. Microservices (each shown as its own container)
– Stay Management (REST + gRPC)
– Promotion Management (REST + gRPC)
– Cars Management (REST + GraphQL)
– Flight Management
– Booking Management
– Experiences Management
– Payment Management + Payment Processor (background worker)
– Trips Management
D. Data stores
– SQL Server (Identity, Booking, Stay, Trips, etc.)
– PostgreSQL (Promotion)
– Redis cache (future)
E. Cross-cutting/DevOps
– ELK stack
– HealthCheck/Watchdog monitoring
– Docker Compose

##### Relationships & data flows
- Browser → React Webapp
- Webapp → API Gateway (HTTPS REST calls)
- API Gateway → Identity Server (JWT validation)
- API Gateway → REST endpoints of each microservice
- Services may call one another via:
– HTTP (Booking → Stay gRPC via a gRPC‐to‐HTTP bridge)
– gRPC (Promotion and Stay expose gRPC endpoints)
- Microservices → their own database contexts (direct EF Core access)
- Payment Processor worker consumes events or scheduled tasks and writes to Payment DB
- All services push logs to ELK via Serilog sink
- HealthCheck endpoints polled by Watchdog service

##### Architectural patterns & principles
- Microservices—each service owns its data/schema
- API Gateway pattern for request routing & security
- CQRS/MediatR within services (separate Application, Domain, Infrastructure layers)
- gRPC for high-performance internal calls (Stay & Promotion)
- Resilience patterns: Retry, Circuit Breaker via IHttpClientFactory + Polly
- Centralized logging & monitoring

##### Final checklist
– All components are labeled
– Important technology stacks noted (React, .NET Core, EF Core, gRPC, PostgreSQL, Ocelot)
– Architectural patterns highlighted (API Gateway, microservices, CQRS, resilience, centralized logging)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Webapp["React Webapp"]:::client
    end

    %% Gateway & Identity Layer
    subgraph "Edge Services" 
        direction TB
        Gateway["API Gateway (Ocelot)"]:::gateway
        Identity["Identity Server"]:::identity
    end

    %% Microservices Cluster
    subgraph "Docker Compose Cluster\nMicroservices" 
        direction TB

        subgraph "Stay Service" 
            direction TB
            StayApi["Stay Management API"]:::service
            StayGrpc["Stay gRPC Service"]:::grpc
            StayApi -->|gRPC: 8011| StayGrpc
            StayApi -->|"EF Core"| StayDB["Stay SQL DB"]:::db
        end

        subgraph "Promotion Service"
            direction TB
            PromoApi["Promotion Management API"]:::service
            PromoGrpc["Promotion gRPC Service"]:::grpc
            PromoApi -->|gRPC: 8021| PromoGrpc
            PromoApi -->|"EF Core"| PromoDB["Promotion PostgreSQL"]:::db
        end

        subgraph "Cars Service"
            direction TB
            CarsApi["Cars Management API"]:::service
            CarsApi -->|"EF Core"| CarsDB["Cars SQL DB"]:::db
        end

        subgraph "Flight Service"
            direction TB
            FlightApi["Flight Management API"]:::service
            FlightApi -->|"EF Core"| FlightDB["Flight SQL DB"]:::db
        end

        subgraph "Booking Service"
            direction TB
            BookingApi["Booking Management API"]:::service
            BookingProc["Booking Processor"]:::worker
            BookingApi -->|"EF Core"| BookingDB["Booking SQL DB"]:::db
            BookingProc -->|"Scheduled Tasks"| BookingDB
        end

        subgraph "Experiences Service"
            direction TB
            ExpApi["Experiences Management API"]:::service
            ExpApi -->|"EF Core"| ExpDB["Experiences SQL DB"]:::db
        end

        subgraph "Payment Service"
            direction TB
            PaymentApi["Payment Management API"]:::service
            PaymentProc["Payment Processor"]:::worker
            PaymentApi -->|"EF Core"| PaymentDB["Payment SQL DB"]:::db
            PaymentProc -->|"Event Consumer"| PaymentDB
        end

        subgraph "Trips Service"
            direction TB
            TripsApi["Trips Management API"]:::service
            TripsApi -->|"EF Core"| TripsDB["Trips SQL DB"]:::db
        end
    end

    %% Infra Layer
    subgraph "Infrastructure & Monitoring"
        direction TB
        ELK["ELK Stack"]:::infra
        Watchdog["Watchdog HealthMonitor"]:::infra
    end

    %% Relationships
    Webapp -->|"HTTPS (Bearer JWT)"| Gateway
    Gateway -->|"JWT validation / OAuth2"| Identity

    Gateway -->|"REST"| StayApi
    Gateway -->|"REST"| PromoApi
    Gateway -->|"REST"| CarsApi
    Gateway -->|"REST"| FlightApi
    Gateway -->|"REST"| BookingApi
    Gateway -->|"REST"| ExpApi
    Gateway -->|"REST"| PaymentApi
    Gateway -->|"REST"| TripsApi

    StayGrpc -.gRPC.-> PromoGrpc

    %% Logging & HealthCheck
    StayApi -->|Logs| ELK
    PromoApi -->|Logs| ELK
    CarsApi -->|Logs| ELK
    FlightApi -->|Logs| ELK
    BookingApi -->|Logs| ELK
    ExpApi -->|Logs| ELK
    PaymentApi -->|Logs| ELK
    TripsApi -->|Logs| ELK

    Watchdog -->|HealthCheck Poll| StayApi
    Watchdog -->|HealthCheck Poll| PromoApi
    Watchdog -->|HealthCheck Poll| CarsApi
    Watchdog -->|HealthCheck Poll| FlightApi
    Watchdog -->|HealthCheck Poll| BookingApi
    Watchdog -->|HealthCheck Poll| ExpApi
    Watchdog -->|HealthCheck Poll| PaymentApi
    Watchdog -->|HealthCheck Poll| TripsApi

    %% Click Events
    click Webapp "https://github.com/luongquockhang/bookingsystem/tree/master/src/webapp"
    click Gateway "https://github.com/luongquockhang/bookingsystem/blob/master/src/ApiGateways/BookingSystem.ApiGateways"
    click Identity "https://github.com/luongquockhang/bookingsystem/blob/master/src/Identity/BookingSystem.Identity.Api"

    click StayApi "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Stay/BookingSystem.Stay.Api"
    click StayGrpc "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Stay/BookingSystem.Stay.gRPC"
    click StayDB "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Stay/BookingSystem.Stay.Infrastructure/Persistance/StayContext.cs"
    click PromoApi "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Promotion/BookingSystem.Promotion.Api"
    click PromoGrpc "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Promotion/BookingSystem.Promotion.gRPC"
    click PromoDB "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Promotion/BookingSystem.Promotion.Infrastructure/Persistance/PromotionContext.cs"
    click CarsApi "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Cars/BookingSystem.Cars.Api"
    click FlightApi "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Flight/BookingSystem.Flight.Api"
    click BookingApi "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Booking/BookingSystem.Booking.Api"
    click BookingProc "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Booking/BookingSystem.Booking.Processor"
    click ExpApi "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Experiences/BookingSystem.Experiences.Api"
    click PaymentApi "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Payment/BookingSystem.Payment.Api"
    click PaymentProc "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Payment/BookingSystem.Payment.Processor"
    click TripsApi "https://github.com/luongquockhang/bookingsystem/blob/master/src/services/Trips/BookingSystem.Trips.Api"

    %% Styles
    classDef client fill:#E3F2FD,stroke:#2196F3,color:#0D47A1;
    classDef gateway fill:#E8F5E9,stroke:#4CAF50,color:#1B5E20;
    classDef identity fill:#E8F5E9,stroke:#4CAF50,color:#1B5E20;
    classDef service fill:#FFF3E0,stroke:#FB8C00,color:#E65100;
    classDef grpc fill:#FFE0B2,stroke:#FB8C00,color:#E65100,stroke-dasharray: 5 5;
    classDef db fill:#ECEFF1,stroke:#90A4AE,color:#263238,stroke-dasharray: 2 2;
    classDef worker fill:#F3E5F5,stroke:#9C27B0,color:#4A148C,stroke-dasharray: 2 2;
    classDef infra fill:#F3E5F5,stroke:#9C27B0,color:#4A148C;
```
