# harshshah8/flight-booking-system architecture

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

- Interactive diagram: https://gitdiagram.com/harshshah8/flight-booking-system
- Repository: https://github.com/harshshah8/flight-booking-system

## Overview

##### Project Type and Purpose
- This is a microservice-based backend system for managing flight searches, inventory, bookings and payments. There is no user-facing frontend here—clients (e.g., web or mobile apps) consume REST APIs exposed by four Spring Boot services. Each service is packaged in Docker, orchestrated via Docker Compose, and backed by PostgreSQL and Redis.

##### File Structure
- Top-level modules:
- search-service (port 8081)
- inventory-service (port 8082)
- booking-service (port 8083)
- payment-service (port 8084)
- fbs-commons (shared library)
- infra (docker-compose.yml, init-db.sql)
- scripts (Python data-seeding)
- Each service follows a layered structure:
– config (Spring configs, Redis setup)
– controller (REST endpoints, health checks)
– service (business logic)
– repository/accessor (JPA or HTTP clients to other services)
– dto/entity/model/exception
- infra/docker-compose.yml defines container relationships, network and volume mounts.

##### README for Additional Insights
- Tech stack: Java 21, Spring Boot, REST, Docker, Redis, PostgreSQL, Python for seeding
- Service ports, startup order: first databases (Postgres, Redis), then seed data, then all Java services
- Clients interact directly with each service via its port
- Booking depends on Inventory and Payment; Inventory publishes seat-reservation events; Search listens to inventory events for cache updates.

##### Main Components & Their Interactions
a. API Consumer (Client)
– Initiates HTTP calls to Search, Inventory, Booking or Payment endpoints.
b. Search Service
– Receives /v1/search, queries Redis-cached graph or falls back to Inventory via REST.
– Subscribes to inventory change events (Redis Pub/Sub) to update in-memory graph cache.
c. Inventory Service
– Manages flights in PostgreSQL (flight_inventory_db).
– Exposes REST endpoints for flight data, seat reserve/release, admin operations.
– Publishes events (e.g., “seats reserved”) over Redis.
d. Booking Service
– Persists bookings in PostgreSQL (flight_booking_db).
– Calls InventoryServiceAccessor (REST) to reserve seats.
– Calls PaymentServiceAccessor (REST) to trigger payment.
e. Payment Service
– Processes /v1/payments/process, performs business rules, returns confirmation.
f. Shared Components
– PostgreSQL (single instance hosting two DBs: inventory + booking)
– Redis (cache + Pub/Sub)
– fbs-commons (shared exception types, utilities)
– data-seeding script (Python)

##### Key Architectural Patterns & Design Principles
- Microservices: each bounded context in its own deployable unit
- Layered/Spring-Boot conventions (Controller → Service → Repository)
- Event-driven cache synchronization (Inventory → Redis Pub/Sub → Search)
- Shared library for cross-cutting concerns (fbs-commons)
- Containerized deployment with Docker Compose

1. Sketch a top-level view: place Client at top.
3. Postgres and Redis beneath, connecting to services.
6. Service ports and database names.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["API Consumer (Client)"]:::external

    %% Docker Network Subgraph
    subgraph "Docker Network"
        direction TB
        SearchSvc["Search Service\n(port:8081)"]:::service
        InventorySvc["Inventory Service\n(port:8082)"]:::service
        BookingSvc["Booking Service\n(port:8083)"]:::service
        PaymentSvc["Payment Service\n(port:8084)"]:::service
        Commons["fbs-commons\n(shared library)"]:::service
    end

    %% Datastores
    subgraph "Data Stores"
        direction TB
        Postgres["PostgreSQL\n(flight_inventory_db, flight_booking_db)"]:::db
        RedisCache["Redis Cache"]:::cache
        RedisPubSub["Redis Pub/Sub"]:::cache
    end

    %% Scripts
    Seeder["Data Seeding Script\n(Python)"]:::script

    %% Relationships
    Client -->|"HTTP/REST\n/v1/search"| SearchSvc
    Client -->|"HTTP/REST\n/v1/inventory"| InventorySvc
    Client -->|"HTTP/REST\n/v1/bookings"| BookingSvc
    Client -->|"HTTP/REST\n/v1/payments"| PaymentSvc

    SearchSvc -->|"Reads cache"| RedisCache
    SearchSvc -->|"Falls back via REST"| InventorySvc
    InventorySvc -->|"CRUD via JPA"| Postgres
    InventorySvc -->|"Publishes events"| RedisPubSub
    RedisPubSub -->|"Subscribes"| SearchSvc

    BookingSvc -->|"Reserve seats\nHTTP/REST"| InventorySvc
    BookingSvc -->|"Trigger payment\nHTTP/REST"| PaymentSvc
    BookingSvc -->|"Persists bookings"| Postgres

    PaymentSvc -->|"Processes payment\nbusiness rules"| Postgres

    Seeder -->|"Initial data load"| Postgres

    %% Click Events
    click SearchSvc "https://github.com/harshshah8/flight-booking-system/tree/main/search-service/"
    click InventorySvc "https://github.com/harshshah8/flight-booking-system/tree/main/inventory-service/"
    click BookingSvc "https://github.com/harshshah8/flight-booking-system/tree/main/booking-service/"
    click PaymentSvc "https://github.com/harshshah8/flight-booking-system/tree/main/payment-service/"
    click Commons "https://github.com/harshshah8/flight-booking-system/tree/main/fbs-commons/"
    click Infra "https://github.com/harshshah8/flight-booking-system/tree/main/infra/"
    click Seeder "https://github.com/harshshah8/flight-booking-system/tree/main/scripts/"

    %% Styles
    classDef service fill:#bbdefb,stroke:#1e88e5,stroke-width:1px
    classDef db fill:#c8e6c9,stroke:#388e3c,stroke-width:1px
    classDef cache fill:#ffe0b2,stroke:#f57c00,stroke-width:1px
    classDef script fill:#e0e0e0,stroke:#616161,stroke-width:1px
    classDef external fill:#f0f4c3,stroke:#827717,stroke-width:1px

    %% Legend
    subgraph Legend
        direction TB
        L1["Service"]:::service
        L2["Database"]:::db
        L3["Cache/Event Bus"]:::cache
        L4["Script"]:::script
        L5["External"]:::external
    end
```
