Skip to content

Latest commit

Β 

History

36 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

✈️ Flight Booking System

πŸš€ Production-Ready Microservices Flight Booking Platform

A modern Flight Booking System built with Node.js, Express.js, MySQL, Sequelize ORM, JWT Authentication, API Gateway, and Microservices Architecture.

Designed with production-level practices including Authentication, Role-Based Access Control (RBAC), Refresh Token Rotation (RTR), Rate Limiting, Health Monitoring, Structured Logging, Security Headers, and Centralized API Gateway.


Node.js Express MySQL Sequelize JWT API Gateway Microservices RBAC License


⭐ If you like this project, consider giving it a Star on GitHub!


πŸ“– Table of Contents


πŸ“Œ Project Overview

The Flight Booking System is a production-inspired backend microservices application that demonstrates how modern distributed systems are designed, secured, and managed.

Unlike a traditional monolithic application, this project separates responsibilities into independent services that communicate through an API Gateway, allowing better scalability, maintainability, and fault isolation.

The system includes:

  • πŸ” Secure Authentication Service
  • ✈️ Flight Management Service
  • 🎫 Booking Management Service
  • 🌐 API Gateway
  • πŸ›‘οΈ Enterprise Security Middleware
  • πŸ“Š Health Monitoring
  • πŸ“œ Centralized Request Logging
  • ⚑ Rate Limiting
  • πŸ”„ Refresh Token Rotation
  • πŸ‘₯ Role-Based Access Control

The project follows industry-standard backend engineering practices and demonstrates how multiple services collaborate while remaining independently deployable.


🌟 Why This Project?

Modern software companies rarely build everything inside one large application.

Instead, they use Microservices Architecture, where every service owns a single responsibility.

This project demonstrates many real-world backend engineering concepts, including:

  • API Gateway Pattern
  • Reverse Proxy Routing
  • JWT Authentication
  • Refresh Token Rotation (RTR)
  • Replay Attack Protection
  • Role-Based Authorization (RBAC)
  • Health Aggregation
  • Structured Request Logging
  • Request Tracing
  • Security Headers (Helmet)
  • Cross-Origin Resource Sharing (CORS)
  • IP-Based Rate Limiting
  • Failure Recovery
  • Production Health Monitoring

This repository was built as a learning project while following production engineering practices as closely as possible.


✨ Key Features

πŸ” Authentication

  • User Registration
  • User Login
  • JWT Authentication
  • Access Token Validation
  • Refresh Token Rotation (RTR)
  • Replay Attack Detection
  • Session Management
  • Secure Logout

πŸ‘₯ Authorization

  • Role-Based Access Control (RBAC)

Supported Roles:

  • ADMIN
  • AIRLINE_ADMIN
  • CUSTOMER

Write operations are protected using reusable authorization middleware.


✈️ Flight Management

  • Create Flights
  • Update Flights
  • Delete Flights
  • Search Flights
  • Airport Management
  • City Management
  • Airplane Management

🎫 Booking Management

  • Create Booking
  • Seat Reservation
  • Booking Status Management
  • Automatic Seat Release
  • Transaction Safety

🌐 API Gateway

  • Reverse Proxy
  • Centralized Routing
  • Health Aggregation
  • Request Logging
  • Request Tracing
  • Rate Limiting
  • Helmet Security
  • CORS Handling

πŸ›‘οΈ Security

  • JWT Authentication
  • RBAC
  • Replay Protection
  • Refresh Token Rotation
  • Helmet Security Headers
  • CORS Protection
  • Rate Limiting
  • Sanitized Logs

πŸ“ˆ Monitoring

  • Gateway Health Check
  • Aggregated Service Health
  • Structured Logs
  • Response Time Tracking
  • Request IDs
  • Failure Detection

πŸ—οΈ System Architecture

                           Client
                              β”‚
                              β”‚
                              β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚    API Gateway   β”‚
                    β”‚     Port 3005    β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚                     β”‚                     β”‚
       β–Ό                     β–Ό                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Auth Service β”‚      β”‚Flight Serviceβ”‚      β”‚BookingServiceβ”‚
β”‚   Port 3002  β”‚      β”‚  Port 3000   β”‚      β”‚  Port 3001   β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                     β”‚                     β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
                      β”‚                     β”‚
                      β–Ό                     β–Ό
                MySQL Database       Internal HTTP APIs

πŸ’» Technology Stack

Backend

  • Node.js
  • Express.js

Database

  • MySQL
  • Sequelize ORM

Authentication

  • JWT (JSON Web Tokens)
  • bcrypt

API Communication

  • Axios
  • HTTP Proxy Middleware

Security

  • Helmet
  • CORS
  • Express Rate Limit

Logging & Monitoring

  • Winston
  • Health Aggregation
  • Request Tracing

Development Tools

  • Nodemon
  • Dotenv
  • Git
  • GitHub

Testing

  • End-to-End Test Suites
  • Integration Testing
  • Gateway Validation
  • Authentication Validation
  • Production Readiness Testing

πŸ“ Project Structure

The project follows a Microservices Architecture, where each service owns a specific business responsibility and can be developed, deployed, and scaled independently.

Flight-Booking-System/
β”‚
β”œβ”€β”€ Gateway-Service/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ middlewares/
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── index.js
β”‚   β”‚
β”‚   β”œβ”€β”€ gateway.log
β”‚   β”œβ”€β”€ package.json
β”‚   └── .env.example
β”‚
β”œβ”€β”€ Auth-Service/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ middlewares/
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ repositories/
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── utils/
β”‚   β”‚
β”‚   β”œβ”€β”€ migrations/
β”‚   β”œβ”€β”€ seeders/
β”‚   └── package.json
β”‚
β”œβ”€β”€ Flight-Service/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ middlewares/
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ repositories/
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── utils/
β”‚   β”‚
β”‚   β”œβ”€β”€ migrations/
β”‚   β”œβ”€β”€ seeders/
β”‚   └── package.json
β”‚
β”œβ”€β”€ Booking-Service/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ middlewares/
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ repositories/
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── utils/
β”‚   β”‚
β”‚   β”œβ”€β”€ migrations/
β”‚   β”œβ”€β”€ seeders/
β”‚   └── package.json
β”‚
β”œβ”€β”€ docs/
β”‚
β”œβ”€β”€ scratch/
β”‚
└── README.md

πŸ›οΈ Microservices Overview

The system is divided into four independent services, each with a single responsibility.

Service Port Responsibility
Gateway-Service 3005 Reverse Proxy, Routing, Logging, Rate Limiting, Health Aggregation
Auth-Service 3002 Authentication, JWT, Refresh Tokens, User Sessions, RBAC
Flight-Service 3000 Flight Management, Airports, Cities, Airplanes
Booking-Service 3001 Booking Creation, Seat Reservation, Booking Lifecycle

🌐 API Gateway Responsibilities

The API Gateway is the single entry point into the system.

Every client request first reaches the Gateway.

The Gateway then:

  • Routes requests
  • Adds security headers
  • Applies rate limiting
  • Generates request IDs
  • Writes request logs
  • Aggregates health checks
  • Forwards requests to downstream services
                  Client
                     β”‚
                     β–Ό
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β”‚   API Gateway     β”‚
           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β–Ό              β–Ό               β–Ό
 Auth Service   Flight Service   Booking Service

πŸ” Authentication Flow

The authentication lifecycle follows industry-standard JWT authentication with Refresh Token Rotation (RTR).

               User Login
                    β”‚
                    β–Ό
          Auth Service validates
             username/password
                    β”‚
                    β–Ό
      Access Token + Refresh Token
                    β”‚
                    β–Ό
          Client stores tokens
                    β”‚
                    β–Ό
        Gateway receives request
                    β”‚
                    β–Ό
      JWT Authentication Middleware
                    β”‚
          Valid Access Token?
           β”‚               β”‚
          YES             NO
           β”‚               β”‚
           β–Ό               β–Ό
     Protected Route   HTTP 401

πŸ”„ Refresh Token Rotation

Unlike traditional JWT authentication, refresh tokens are rotated after every use.

Old Refresh Token
        β”‚
        β–Ό
Refresh Endpoint
        β”‚
        β–Ό
Generate

β€’ New Access Token

β€’ New Refresh Token
        β”‚
        β–Ό
Old Refresh Token Revoked
        β”‚
        β–Ό
Replay Attack?
        β”‚
      Yes
        β”‚
        β–Ό
Revoke Entire Session

Benefits

  • Prevents replay attacks
  • Prevents stolen refresh token reuse
  • Forces attackers out immediately

πŸ‘₯ Role-Based Access Control (RBAC)

Every protected route passes through reusable authorization middleware.

Incoming Request
       β”‚
       β–Ό
Authenticate JWT
       β”‚
       β–Ό
Decode User Roles
       β”‚
       β–Ό
Authorize Roles
       β”‚
 β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”
 β”‚           β”‚
 β–Ό           β–Ό
Allowed    Forbidden

Supported Roles

Role Permissions
ADMIN Full System Access
AIRLINE_ADMIN Flight Management
CUSTOMER Booking & Read Operations

🎫 Booking Lifecycle

Customer
    β”‚
    β–Ό
Create Booking
    β”‚
    β–Ό
Booking Service
    β”‚
    β–Ό
Reserve Seat
    β”‚
    β–Ό
Flight Service
    β”‚
    β–Ό
Seat Reserved
    β”‚
    β–Ό
Booking Status
    β”‚
 β”Œβ”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚                  β”‚
 β–Ό                  β–Ό
Confirmed      Expired
 β”‚                  β”‚
 β–Ό                  β–Ό
Keep Seat     Release Seat

πŸ”„ Request Flow Through Gateway

Every API request follows the same pipeline.

Client
   β”‚
   β–Ό
Request Logger
   β”‚
   β–Ό
Rate Limiter
   β”‚
   β–Ό
Helmet
   β”‚
   β–Ό
CORS
   β”‚
   β–Ό
Reverse Proxy
   β”‚
   β–Ό
Target Microservice

❀️ Health Aggregation

Instead of checking every service manually, the Gateway exposes a single endpoint.

GET /health
      β”‚
      β–Ό
Gateway
      β”‚
      β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β”‚              β”‚
      β–Ό              β–Ό
Auth          Booking
      β”‚              β”‚
      β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
             β–Ό
         Flight Service
             β”‚
             β–Ό
Aggregated JSON Response

Example:

{
  "success": true,
  "gateway": {
    "status": "UP"
  },
  "services": {
    "auth": "UP",
    "booking": "UP",
    "flight": "UP"
  }
}

πŸ—„οΈ Database Ownership

Each service owns its own data.

                MySQL

     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

     β–Ό            β–Ό            β–Ό

 Auth DB     Flight DB    Booking DB

This avoids shared database coupling, one of the key principles of microservices.


πŸ“‘ Service Communication

                 Client
                    β”‚
                    β–Ό
             API Gateway
                    β”‚
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β–Ό             β–Ό              β–Ό
 Auth Service   Flight Service   Booking Service
                                     β”‚
                                     β–Ό
                          Reserve Seat API
                                     β”‚
                                     β–Ό
                             Flight Service

🎯 Design Principles

This project follows several backend engineering principles:

  • βœ… Separation of Concerns
  • βœ… Layered Architecture
  • βœ… Single Responsibility Principle
  • βœ… Stateless Authentication
  • βœ… Secure Token Rotation
  • βœ… Least Privilege Authorization
  • βœ… Independent Service Ownership
  • βœ… Centralized Gateway
  • βœ… Production-Ready Middleware
  • βœ… Scalable Microservices Design

πŸš€ Getting Started

Follow the steps below to set up and run the Flight Booking System on your local machine.


πŸ“‹ Prerequisites

Make sure you have the following installed:

Software Version
Node.js 22.x or later
npm 10.x or later
MySQL 8.x
Git Latest
Postman (Optional) Latest

Verify your installation:

node -v
npm -v
mysql --version
git --version

πŸ“₯ Clone the Repository

git clone https://github.com/<your-username>/Flight-Booking-System.git

cd Flight-Booking-System

πŸ“¦ Install Dependencies

Install dependencies for each microservice.

Gateway Service

cd Gateway-Service
npm install

Auth Service

cd ../Auth-Service
npm install

Flight Service

cd ../Flight-Service
npm install

Booking Service

cd ../Booking-Service
npm install

βš™οΈ Environment Variables

Each microservice contains a .env.example file.

Create a .env file inside every service by copying the example.

Example:

cp .env.example .env

or manually:

.env.example
↓

.env

πŸ”‘ Environment Variables

Gateway-Service

PORT=3005

AUTH_SERVICE_URL=http://localhost:3002
FLIGHT_SERVICE_URL=http://localhost:3000
BOOKING_SERVICE_URL=http://localhost:3001

RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX_REQUESTS=100

TRUST_PROXY=false

CORS_ORIGIN=*
CORS_METHODS=GET,POST,PUT,PATCH,DELETE,OPTIONS
CORS_CREDENTIALS=false

Auth-Service

PORT=3002

DB_HOST=localhost
DB_PORT=3306
DB_NAME=<YOUR_DB_NAME>
DB_USER=<YOUR_DB_USER>
DB_PASSWORD=<YOUR_DB_PASSWORD>

JWT_SECRET=<YOUR_JWT_SECRET>
JWT_REFRESH_SECRET=<YOUR_REFRESH_SECRET>

JWT_EXPIRY=15m
JWT_REFRESH_EXPIRY=7d

Flight-Service

PORT=3000

DB_HOST=localhost
DB_PORT=3306
DB_NAME=<YOUR_DB_NAME>
DB_USER=<YOUR_DB_USER>
DB_PASSWORD=<YOUR_DB_PASSWORD>

JWT_SECRET=<SAME_JWT_SECRET_AS_AUTH>

Booking-Service

PORT=3001

DB_HOST=localhost
DB_PORT=3306
DB_NAME=<YOUR_DB_NAME>
DB_USER=<YOUR_DB_USER>
DB_PASSWORD=<YOUR_DB_PASSWORD>

JWT_SECRET=<SAME_JWT_SECRET_AS_AUTH>

FLIGHT_SERVICE_URL=http://localhost:3000

πŸ—„οΈ Database Setup

Create the required MySQL databases.

Example:

CREATE DATABASE auth_service;

CREATE DATABASE flight_service;

CREATE DATABASE booking_service;

πŸ”„ Run Database Migrations

Inside each service:

npx sequelize-cli db:migrate

🌱 Seed Initial Data

Run the seeders for services that require initial data.

npx sequelize-cli db:seed:all

This initializes:

  • Roles
  • Airports
  • Cities
  • Airplanes
  • Sample Flights (if available)

▢️ Start the Services

Open four separate terminals.


Terminal 1

Auth Service

cd Auth-Service

npm start

Runs on:

http://localhost:3002

Terminal 2

Flight Service

cd Flight-Service

npm start

Runs on:

http://localhost:3000

Terminal 3

Booking Service

cd Booking-Service

npm start

Runs on:

http://localhost:3001

Terminal 4

API Gateway

cd Gateway-Service

npm start

Runs on:

http://localhost:3005

🌐 Verify the Setup

Once all services are running, verify the Gateway:

GET http://localhost:3005/health

Expected response:

{
  "success": true,
  "gateway": {
    "status": "UP"
  },
  "services": {
    "auth": {
      "status": "UP"
    },
    "booking": {
      "status": "UP"
    },
    "flight": {
      "status": "UP"
    }
  }
}

πŸ“‘ Service Ports

Service Port
Gateway Service 3005
Flight Service 3000
Booking Service 3001
Auth Service 3002

πŸ§ͺ Running the Test Suite

Run the automated validation scripts from the project root or the scratch/ directory (depending on your project structure).

Examples:

node scratch/test-e2e-real.js
node scratch/test-gateway-proxy.js
node scratch/test-gateway-health-agg.js
node scratch/test-gateway-logging.js
node scratch/test-gateway-rate-limiting.js
node scratch/test-gateway-security.js
node scratch/test-gateway-e2e.js

βœ… Successful Setup Checklist

  • βœ… All dependencies installed
  • βœ… MySQL databases created
  • βœ… Environment variables configured
  • βœ… Database migrations completed
  • βœ… Seeders executed
  • βœ… All four services running
  • βœ… Gateway /health reports all services UP
  • βœ… End-to-end test suite passes successfully

πŸ“š API Documentation

All client requests should be sent through the API Gateway.

Gateway Base URL

http://localhost:3005

The gateway transparently routes requests to the appropriate microservice.


🌐 Gateway Route Mapping

Gateway Route Target Service Internal Route
/api/auth/* Auth Service /api/v1/auth/*
/api/flights/* Flight Service /api/v1/*
/api/bookings/* Booking Service /api/v1/bookings/*
/health Gateway Local Endpoint

πŸ” Authentication APIs

Register User

Request

POST /api/auth/register

Request Body

{
  "email": "john@example.com",
  "password": "Password123",
  "firstname": "John",
  "lastname": "Doe"
}

Success Response

{
  "success": true,
  "data": {
    "id": 1,
    "email": "john@example.com"
  }
}

Login

Request

POST /api/auth/login

Request Body

{
  "email": "john@example.com",
  "password": "Password123"
}

Success Response

{
  "success": true,
  "data": {
    "accessToken": "...",
    "refreshToken": "..."
  }
}

Refresh Token

POST /api/auth/refresh

Request

{
  "refreshToken": "<refresh_token>"
}

Returns

  • New Access Token
  • New Refresh Token

The previous Refresh Token is revoked immediately.


Logout

POST /api/auth/logout

Revokes the current session.


Current User

GET /api/auth/me

Requires:

Authorization: Bearer <access_token>

✈️ Flight APIs


Create Flight

POST /api/flights/flight

Authorization Required

Bearer Token

Allowed Roles

  • ADMIN
  • AIRLINE_ADMIN

Example Request

{
  "flightNumber": "AI202",
  "airplaneId": 1,
  "departureAirportId": 2,
  "arrivalAirportId": 5,
  "departureTime": "2026-09-20T09:00:00Z",
  "arrivalTime": "2026-09-20T11:30:00Z",
  "price": 4500
}

Search Flights

GET /api/flights/flight

Example

GET /api/flights/flight?departureAirportId=2&arrivalAirportId=5

Update Flight

PATCH /api/flights/flight/:id

Requires ADMIN privileges.


Delete Flight

DELETE /api/flights/flight/:id

Requires ADMIN privileges.


🎫 Booking APIs


Create Booking

POST /api/bookings

Authorization Required

Bearer Token

Example

{
  "flightId": 12,
  "userId": 5,
  "noOfSeats": 2
}

Booking Lifecycle

PENDING

↓

CONFIRMED

↓

COMPLETED

or

EXPIRED

❀️ Health API

Gateway exposes a centralized health endpoint.

GET /health

Example Response

{
  "success": true,
  "gateway": {
    "status": "UP"
  },
  "services": {
    "auth": {
      "status": "UP"
    },
    "booking": {
      "status": "UP"
    },
    "flight": {
      "status": "UP"
    }
  },
  "timestamp": "2026-08-07T10:00:00Z"
}

πŸ” Authorization

Protected routes require:

Authorization: Bearer <JWT_TOKEN>

Example

Authorization: Bearer eyJhbGciOi...

πŸ‘₯ Role Permissions

API CUSTOMER AIRLINE_ADMIN ADMIN
Register βœ… βœ… βœ…
Login βœ… βœ… βœ…
View Flights βœ… βœ… βœ…
Search Flights βœ… βœ… βœ…
Create Booking βœ… βœ… βœ…
Create Flight ❌ βœ… βœ…
Update Flight ❌ βœ… βœ…
Delete Flight ❌ ❌ βœ…

πŸ”„ Authentication Lifecycle

Register

↓

Login

↓

Access Token

↓

Gateway

↓

Protected API

↓

Access Token Expired

↓

Refresh Token

↓

New Access Token

↓

Continue

πŸ›‘οΈ Security Features

The project implements several production-grade security mechanisms.

Feature Status
JWT Authentication βœ…
Refresh Token Rotation βœ…
Replay Attack Protection βœ…
RBAC βœ…
Helmet Security Headers βœ…
CORS βœ…
Rate Limiting βœ…
Structured Logging βœ…
Request Tracing βœ…
Health Monitoring βœ…

πŸ“‘ HTTP Status Codes

Status Meaning
200 Success
201 Resource Created
204 No Content
400 Bad Request
401 Unauthorized
403 Forbidden
404 Resource Not Found
409 Conflict
429 Too Many Requests
500 Internal Server Error

⚠️ Error Response Format

All APIs return a consistent error structure.

{
  "success": false,
  "message": "Unauthorized",
  "error": {}
}

πŸ“Œ Production Features Summary

βœ” API Gateway

βœ” Reverse Proxy Routing

βœ” JWT Authentication

βœ” Refresh Token Rotation (RTR)

βœ” Replay Attack Detection

βœ” Role-Based Access Control

βœ” Health Aggregation

βœ” Structured Request Logging

βœ” Request ID Tracing

βœ” Rate Limiting

βœ” Helmet Security

βœ” CORS

βœ” Failure Recovery

βœ” End-to-End Production Validation


πŸ§ͺ Testing & Production Validation

The Flight Booking System has been extensively tested through unit, integration, and end-to-end (E2E) validation to ensure reliability, security, and production readiness.


βœ… Testing Strategy

The project follows a multi-layered testing approach.

                Testing Strategy

                       β”‚

      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

      β–Ό                β–Ό                 β–Ό

 Unit Tests     Integration Tests     E2E Tests

                                         β”‚

                                         β–Ό

                           Production Validation

πŸ” Test Coverage

Category Status
Authentication βœ…
Authorization (RBAC) βœ…
JWT Validation βœ…
Refresh Token Rotation βœ…
Replay Attack Protection βœ…
Flight Management βœ…
Booking Management βœ…
API Gateway βœ…
Reverse Proxy βœ…
Health Aggregation βœ…
Request Logging βœ…
Request Tracing βœ…
Rate Limiting βœ…
Helmet Security βœ…
CORS βœ…
Failure Recovery βœ…
End-to-End Validation βœ…

πŸš€ End-to-End Validation

The entire microservices ecosystem was validated using automated test suites.

Services Tested

  • Gateway Service
  • Auth Service
  • Flight Service
  • Booking Service

Authentication Flow

βœ” User Registration

βœ” Login

βœ” JWT Generation

βœ” Access Token Validation

βœ” Refresh Token Rotation

βœ” Logout

βœ” Session Revocation

βœ” Replay Attack Detection


Authorization

Verified role-based access for:

Role Read Write
CUSTOMER βœ… ❌
AIRLINE_ADMIN βœ… βœ…
ADMIN βœ… βœ…

Unauthorized write requests correctly return 403 Forbidden.


Gateway Validation

The API Gateway was validated for:

  • Reverse Proxy Routing
  • Transparent Header Forwarding
  • Query Parameter Preservation
  • Request Body Preservation
  • Request ID Propagation
  • Health Aggregation
  • Request Logging
  • Security Middleware

Rate Limiting

Verified:

  • Per-IP request limiting
  • Sliding window reset
  • OPTIONS preflight bypass
  • Health endpoint bypass
  • Standard RateLimit headers
  • Independent client isolation

Security Validation

The following security mechanisms were verified.

Security Feature Verified
JWT Authentication βœ…
Refresh Token Rotation βœ…
Replay Protection βœ…
Helmet Headers βœ…
CORS βœ…
RBAC βœ…
Structured Logging βœ…
Request Tracing βœ…

❀️ Health Monitoring

Every service exposes a health endpoint.

Service Endpoint
Gateway /health
Auth /api/v1/info
Flight /api/v1/info
Booking /api/v1/info

The Gateway aggregates all downstream health checks into a single response.


πŸ“Š Performance Observations

Measured during end-to-end validation.

Operation Average Latency
Gateway Middleware < 1 ms
Reverse Proxy ~20–30 ms
Health Aggregation ~70–80 ms
Flight Creation ~200–250 ms
Booking Creation ~150–250 ms

Actual timings may vary depending on hardware and database performance.


πŸ“œ Logging

Every incoming request passing through the Gateway generates a structured JSON log entry.

Example:

{
  "requestId": "eb722fdb-58fa-41ac-87d7-1a3f57e07462",
  "method": "POST",
  "url": "/api/bookings",
  "statusCode": 201,
  "responseTimeMs": 63.9,
  "clientIp": "::1",
  "userAgent": "node",
  "service": "Gateway"
}

Sensitive information such as:

  • Passwords
  • JWT Tokens
  • Cookies
  • Authorization Headers
  • Request Bodies

are intentionally excluded.


πŸ›‘οΈ Production Security Checklist

Feature Status
JWT Authentication βœ…
Refresh Token Rotation βœ…
Replay Attack Detection βœ…
RBAC βœ…
Helmet βœ…
CORS βœ…
Rate Limiting βœ…
Structured Logging βœ…
Request Tracing βœ…
Health Monitoring βœ…

πŸ“ˆ Production Readiness Score

Category Score
Architecture 9.0 / 10
Security 9.5 / 10
Reliability 9.0 / 10
Performance 9.0 / 10
Maintainability 9.5 / 10
Scalability 8.5 / 10

⭐ Overall Score

9.1 / 10

Status: βœ… Ready with Minor Improvements


πŸš€ Deployment Checklist

Before deploying to production:

  • JWT Authentication
  • RBAC
  • API Gateway
  • Reverse Proxy
  • Health Monitoring
  • Structured Logging
  • Request Tracing
  • Helmet Security
  • CORS
  • Rate Limiting
  • End-to-End Testing
  • Production Review

πŸ“¦ Future Improvements

The current implementation is production-ready, with the following enhancements recommended for enterprise-scale deployments:

  • Redis-backed distributed rate limiting
  • Docker & Docker Compose
  • Kubernetes deployment
  • OpenTelemetry distributed tracing
  • Circuit breakers (e.g., Opossum)
  • Service discovery (Consul/Eureka)
  • Asynchronous messaging (RabbitMQ/Kafka)
  • CI/CD pipeline (GitHub Actions)
  • Prometheus & Grafana monitoring

πŸ“Œ Key Achievements

βœ” Microservices Architecture

βœ” API Gateway

βœ” JWT Authentication

βœ” Refresh Token Rotation (RTR)

βœ” Replay Attack Protection

βœ” Role-Based Access Control (RBAC)

βœ” Health Aggregation

βœ” Structured Logging

βœ” Request Tracing

βœ” Rate Limiting

βœ” Helmet Security

βœ” CORS

βœ” Failure Recovery

βœ” End-to-End Production Validation

βœ” Production Readiness Review


πŸ“Έ Project Demo

Screenshots and GIFs will be added here.

🏠 Gateway Health Dashboard

Gateway Health


πŸ” Authentication Flow

Login


✈️ Flight Management

Flights


🎫 Booking Flow

Booking


πŸ“Š Gateway Logs

Gateway Logs


πŸŽ₯ Demo Video

A complete walkthrough of the project is available here:

πŸ“Ί YouTube Demo: (Coming Soon)

The demo covers:

  • User Registration
  • Login
  • Flight Creation
  • Flight Search
  • Booking Creation
  • Gateway Routing
  • Health Aggregation
  • Request Logging
  • Rate Limiting
  • Security Headers
  • Failure Recovery
  • End-to-End Validation

πŸ›£οΈ Project Roadmap

βœ… Completed

  • Authentication Service
  • Flight Service
  • Booking Service
  • API Gateway
  • JWT Authentication
  • Refresh Token Rotation
  • Replay Attack Protection
  • Role-Based Access Control (RBAC)
  • Reverse Proxy
  • Health Aggregation
  • Request Logging
  • Request Tracing
  • Rate Limiting
  • Helmet Security
  • CORS
  • End-to-End Validation
  • Production Readiness Review

πŸš€ Planned Enhancements

  • Docker Support
  • Docker Compose
  • Kubernetes Deployment
  • Redis Rate Limiting
  • OpenTelemetry
  • Grafana Dashboard
  • Prometheus Monitoring
  • RabbitMQ
  • Kafka Event Streaming
  • Circuit Breakers
  • Service Discovery
  • CI/CD Pipeline
  • GitHub Actions
  • Terraform Deployment
  • AWS Deployment

🀝 Contributing

Contributions are welcome!

If you would like to improve this project:

  1. Fork the repository

  2. Create a new branch

git checkout -b feature/your-feature
  1. Commit your changes
git commit -m "feat: add new feature"
  1. Push the branch
git push origin feature/your-feature
  1. Open a Pull Request

πŸ“– Learning Outcomes

This project helped me gain practical experience with:

  • Microservices Architecture
  • API Gateway Pattern
  • JWT Authentication
  • Refresh Token Rotation (RTR)
  • Replay Attack Protection
  • Role-Based Access Control (RBAC)
  • Reverse Proxy
  • REST API Design
  • Database Transactions
  • MySQL & Sequelize ORM
  • Structured Logging
  • Request Tracing
  • Health Monitoring
  • Rate Limiting
  • Helmet Security
  • CORS
  • Production Validation
  • Backend System Design

πŸ“š References

  • Node.js
  • Express.js
  • Sequelize ORM
  • MySQL
  • JWT
  • Winston
  • Helmet
  • Express Rate Limit
  • HTTP Proxy Middleware

πŸ‘¨β€πŸ’» Author

Pritam Nandi

Backend Developer | Computer Science Student

Passionate about building scalable backend systems, distributed architectures, and secure APIs.

🌐 Connect With Me


⭐ Support

If you found this project helpful:

⭐ Star this repository

🍴 Fork the repository

πŸ› οΈ Suggest improvements

πŸ“’ Share it with others


πŸ“„ License

This project is licensed under the MIT License.

See the LICENSE file for more information.


πŸ™ Acknowledgements

Special thanks to the open-source community and the maintainers of:

  • Node.js
  • Express.js
  • Sequelize
  • MySQL
  • Winston
  • Helmet
  • express-rate-limit
  • http-proxy-middleware

for providing the tools that made this project possible.


✈️ Flight Booking System

Production-Ready Microservices Backend

Built with ❀️ by Pritam Nandi

⭐ If you like this project, don't forget to give it a star! ⭐


Thank you for visiting this repository!

About

No description, website, or topics provided.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages