# daniyalahmed21/flight-booking-system architecture

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

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

## Overview

##### Project type and purpose
- This is a microservices-based flight booking system structured as a monorepo.
- Its purpose is to provide a full end-to-end booking workflow: clients call the API gateway, which routes to the flight catalog, booking orchestration, and notification services.

##### File–structure analysis
- Top-level folders:
- api-gateway – single HTTP entrypoint, authentication, routing.
- flight-service – manages flights, airports, cities, seats (MySQL via Sequelize).
- booking-service – booking creation/cancellation, seat allocation, payment orchestration, uses a message queue for inter-service events.
- notification-service – delivers booking events via email/SMS.
- Each service follows a layered structure: config, controllers, middlewares, models/migrations, repositories, services, routes, utils.
- docker-compose.yml ties the services together for local/dev orchestration.

##### Key insights from README
- Architecture is client → api-gateway → individual services.
- Each service owns its own data store (MySQL for flight, optionally MongoDB for booking, another for notifications).
- Uses Node.js + Express for all services, Sequelize ORM, Winston for logging, dotenv for config, Docker for containers.

a. Main components
- Clients (web/mobile)
- API Gateway (Express, authentication, routing)
- Flight Service (Express + Sequelize + MySQL)
- Booking Service (Express + queue integration + database)
- Notification Service (Express + email/SMS delivery + database)
- Message broker/Queue (e.g., RabbitMQ or built-in queue)
- Databases (MySQL instances, MongoDB if used)
- External services (SMTP server, SMS gateway, payment provider)

b. Relationships and interactions
- Clients send requests to API Gateway.
- Gateway routes “flight search” requests to Flight Service.
- Booking requests go to Booking Service via the gateway.
- Booking Service allocates seats by calling Flight Service APIs or directly via shared queue.
- Booking Service publishes “booking created/cancelled” events to the message broker.
- Notification Service subscribes to booking events, then sends emails/SMS.
- All services read their own environment variables, log to Winston, and persist domain data to their own DBs.
- Docker Compose links all containers and the broker/network.

c. Architectural patterns and principles
- Microservices with bounded contexts (flight, booking, notification).
- API Gateway pattern for cross-cutting concerns (auth, rate limiting).
- Layered architecture within each service (controllers → services → repositories → models).
- Event-driven integration via message broker for loose coupling.
- Independent persistence per service (database per microservice).
- Containerized deployment (Docker + Compose).

d. Technologies and frameworks
- Node.js + Express
- Sequelize ORM (Flight Service, potentially Notification)
- MongoDB driver or ORM for Booking Service (if used)
- RabbitMQ or similar queue (config/queueConfig.js in booking-service)
- Winston for logging
- dotenv for configuration
- Docker & Docker Compose

## Diagram (Mermaid)

```mermaid
graph TD
  Clients["Web/Mobile Clients"]:::external
  APIGw["API Gateway"]:::api
  Clients -->|HTTP Requests| APIGw

  APIGw -->|GET /flights| FlightService
  APIGw -->|POST /bookings| BookingService

  FlightService["Flight Service"]:::service
  FlightService --> FlightDB["Flight MySQL DB"]:::db

  BookingService["Booking Service"]:::service
  BookingService --> BookingDB["Booking DB"]:::db
  BookingService -->|publish BookingCreated/Cancelled| Broker["Message Broker"]:::broker

  Broker -->|consume events| NotificationService

  NotificationService["Notification Service"]:::service
  NotificationService --> NotificationDB["Notification DB"]:::db

  Compose["Docker Compose"]:::external
  Compose -.-> APIGw
  Compose -.-> FlightService
  Compose -.-> BookingService
  Compose -.-> NotificationService
  Compose -.-> Broker

  classDef external fill:#cccccc,stroke:#333,stroke-width:1px;
  classDef api fill:#a2d2ff,stroke:#333,stroke-width:1px;
  classDef service fill:#b7e4c7,stroke:#333,stroke-width:1px;
  classDef db fill:#ffcb77,stroke:#333,stroke-width:1px;
  classDef broker fill:#cdb4db,stroke:#333,stroke-width:1px;

  click APIGw "https://github.com/daniyalahmed21/flight-booking-system/blob/master/api-gateway/src/index.js"
  click FlightService "https://github.com/daniyalahmed21/flight-booking-system/blob/master/flight-service/src/index.js"
  click BookingService "https://github.com/daniyalahmed21/flight-booking-system/blob/master/booking-service/src/index.js"
  click NotificationService "https://github.com/daniyalahmed21/flight-booking-system/blob/master/notification-service/src/index.js"
  click Broker "https://github.com/daniyalahmed21/flight-booking-system/blob/master/booking-service/src/config/queueConfig.js"
  click Compose "https://github.com/daniyalahmed21/flight-booking-system/blob/master/docker-compose.yml"
```
