Skip to content

Repository files navigation

Flight Booking Management System

A comprehensive microservices-based Flight Booking System built with Node.js and Express.js. This system manages flight data, user bookings, and sends automated email notifications across four independent but interconnected services.

GitHub Node.js License


Table of Contents


Project Overview

The Flight Booking Management System is a production-ready microservices architecture consisting of:

  1. API Gateway - Authentication, user management, and request routing
  2. FLIGHTS - Flight, airplane, airport, and city data management
  3. Flights_bookings - Booking operations and seat management
  4. noti-service - Email notifications and ticket management

Tech Stack:

  • Runtime: Node.js
  • Framework: Express.js
  • ORM: Sequelize
  • Database: MySQL
  • Message Queue: RabbitMQ
  • Email Service: Nodemailer
  • Logging: Winston
  • Auth: JWT (JSON Web Tokens)

Architecture

┌─────────────────────────────────────────────────────────┐
│                    Client Layer                         │
│              (REST API Consumers)                       │
└────────────────────┬────────────────────────────────────┘
                     │
        ┌────────────▼─────────────┐
        │   API Gateway (3001)     │
        │  - Authentication        │
        │  - User Management       │
        │  - Request Routing       │
        └──────┬────────┬──────────┘
               │        │
        ┌──────▼──┐  ┌──▼──────────────────┐
        │ FLIGHTS │  │ Flights_bookings    │
        │ (3003)  │  │ (3006)              │
        │         │  │ - Booking Mgmt      │
        │ - Cities│  │ - Seat Allocation   │
        │ - Planes│  │ - Payment Processing│
        │ - Routes│  └──┬─────────────────┘
        │         │     │
        └────┬─────┘     │
             │           │
             │      ┌────▼──────────────┐
             │      │  noti-service     │
             │      │  (3005)           │
             │      │ - Email Tickets   │
             │      │ - Notifications   │
             │      └────┬──────────────┘
             │           │
        ┌────▼───────────▼────┐
        │   Message Queue     │
        │   (RabbitMQ: 5672)  │
        └─────────────────────┘
             │
        ┌────▼────────────────┐
        │   MySQL Database    │
        │   (Port: 3306)      │
        └─────────────────────┘

Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v14 or higher) - Download
  • npm (v6 or higher) - Comes with Node.js
  • Git (v2.x or higher) - Download
  • MySQL (v5.7 or higher) - Download
  • RabbitMQ - Download

Optional but Recommended

  • Docker & Docker Compose - For containerized setup
  • Postman - For API testing
  • VSCode - Recommended IDE

Project Structure

Flight-Booking-Management-System/
├── README.md                                    # This file
├── Flight_Booking_System_Documentation.md       # Detailed system documentation
├── .gitmodules                                  # Git submodule configuration
│
├── API\ gateway/                                # API Gateway Service (Submodule)
│   ├── src/
│   │   ├── config/                             # Configuration files
│   │   ├── controllers/                        # Request handlers
│   │   ├── middlewares/                        # Auth & validation middlewares
│   │   ├── models/                             # Database models
│   │   ├── repositories/                       # Data access layer
│   │   ├── routes/                             # Route definitions
│   │   ├── services/                           # Business logic
│   │   └── index.js                            # Server entry point
│   ├── package.json
│   └── README.md
│
├── FLIGHTS/                                     # FLIGHTS Service (Submodule)
│   ├── src/
│   │   ├── config/                             # Configuration files
│   │   ├── controllers/                        # Controllers for each resource
│   │   ├── middlewares/                        # Request validation
│   │   ├── models/                             # Sequelize models
│   │   ├── repositories/                       # Data access patterns
│   │   ├── routes/                             # API routes
│   │   ├── services/                           # Core business logic
│   │   └── index.js                            # Server entry point
│   ├── migrations/                             # Database migrations
│   ├── seeders/                                # Database seeders
│   ├── package.json
│   └── README.md
│
├── Flights_bookings/                           # Bookings Service (Submodule)
│   ├── src/
│   │   ├── config/
│   │   ├── controllers/
│   │   ├── middlewares/
│   │   ├── models/
│   │   ├── repositories/
│   │   ├── routes/
│   │   ├── services/
│   │   └── index.js
│   ├── migrations/
│   ├── package.json
│   └── README.md
│
└── noti-service/                               # Notification Service (Submodule)
    ├── src/
    │   ├── config/
    │   ├── controllers/
    │   ├── middlewares/
    │   ├── models/
    │   ├── repositories/
    │   ├── routes/
    │   ├── services/
    │   └── index.js
    ├── migrations/
    ├── package.json
    └── README.md

Cloning with Submodules

Method 1: Clone with All Submodules (Recommended)

# Clone the repository with all submodules
git clone --recurse-submodules https://github.com/AsyncNigam/Flight-Booking-Management-System.git

# Navigate to project directory
cd Flight-Booking-Management-System

# Verify all submodules are present
git submodule status

Method 2: Clone and Initialize Submodules Separately

# Clone the main repository
git clone https://github.com/AsyncNigam/Flight-Booking-Management-System.git

# Navigate to project directory
cd Flight-Booking-Management-System

# Initialize and update submodules
git submodule update --init --recursive

Updating Submodules

To pull the latest changes from all submodules:

# Update all submodules to latest master branch
git submodule update --remote

# Or batch update all submodules
git submodule foreach git pull origin master

Setup Instructions

1. Database Setup

Create MySQL Databases

# Open MySQL CLI
mysql -u root -p

# Create databases for each service
CREATE DATABASE api_gateway;
CREATE DATABASE flights_db;
CREATE DATABASE bookings_db;
CREATE DATABASE notifications_db;

# Verify creation
SHOW DATABASES;

# Exit MySQL
EXIT;

Alternative: Use Sequelize Migrations

Each service includes migration files. Navigate to each service and run:

npx sequelize-cli db:create

2. Install Dependencies

Navigate to each service and install dependencies:

# API Gateway
cd "API gateway"
npm install
cd ..

# FLIGHTS
cd FLIGHTS
npm install
cd ..

# Flights_bookings
cd Flights_bookings
npm install
cd ..

# noti-service
cd noti-service
npm install
cd ..

Or use this batch command:

for dir in "API gateway" FLIGHTS Flights_bookings noti-service; do
  cd "$dir"
  npm install
  cd ..
done

3. Environment Configuration

Create .env file in each service directory:

API Gateway - .env

# Server Configuration
PORT=3001
NODE_ENV=development

# Database Configuration
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=api_gateway
DB_DIALECT=mysql

# JWT Configuration
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRY=7d

# Logger Configuration
LOG_LEVEL=debug
LOG_FILE=logs/api-gateway.log

FLIGHTS - .env

# Server Configuration
PORT=3003
NODE_ENV=development

# Database Configuration
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=flights_db
DB_DIALECT=mysql

# Logger Configuration
LOG_LEVEL=debug
LOG_FILE=logs/flights.log

Flights_bookings - .env

# Server Configuration
PORT=3006
NODE_ENV=development

# Database Configuration
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=bookings_db
DB_DIALECT=mysql

# Service URLs
FLIGHTS_SERVICE_URL=http://localhost:3003
PAYMENT_GATEWAY_URL=your_payment_gateway_url

# RabbitMQ Configuration
RABBITMQ_URL=amqp://guest:guest@localhost:5672

# Logger Configuration
LOG_LEVEL=debug
LOG_FILE=logs/bookings.log

noti-service - .env

# Server Configuration
PORT=3005
NODE_ENV=development

# Database Configuration
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=notifications_db
DB_DIALECT=mysql

# RabbitMQ Configuration
RABBITMQ_URL=amqp://guest:guest@localhost:5672
RABBITMQ_QUEUE=noti-queue

# Email Configuration
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your_email@gmail.com
SMTP_PASS=your_app_password
SENDER_EMAIL=noreply@flightbooking.com

# Logger Configuration
LOG_LEVEL=debug
LOG_FILE=logs/noti-service.log

4. Database Migrations

Run migrations for each service:

# API Gateway
cd "API gateway"
npx sequelize-cli db:migrate
cd ..

# FLIGHTS
cd FLIGHTS
npx sequelize-cli db:migrate
cd ..

# Flights_bookings
cd Flights_bookings
npx sequelize-cli db:migrate
cd ..

# noti-service
cd noti-service
npx sequelize-cli db:migrate
cd ..

5. Database Seeders (Optional)

Populate sample data:

# FLIGHTS service has seeders for airplanes, airports, cities, etc.
cd FLIGHTS
npx sequelize-cli db:seed:all
cd ..

Running the Services

Start All Services Individually

Open separate terminal windows for each service:

Terminal 1: API Gateway

cd "API gateway"
npm start
# Server running on http://localhost:3001

Terminal 2: FLIGHTS

cd FLIGHTS
npm start
# Server running on http://localhost:3003

Terminal 3: Flights_bookings

cd Flights_bookings
npm start
# Server running on http://localhost:3006

Terminal 4: noti-service

cd noti-service
npm start
# Server running on http://localhost:3005

Verify All Services Are Running

# Check if all ports are listening
netstat -ano | grep -E "3001|3003|3005|3006"

# Or use curl to test endpoints
curl http://localhost:3001/api/v1/info
curl http://localhost:3003/api/v1/info
curl http://localhost:3005/api/v1/info
curl http://localhost:3006/api/v1/info

Using Docker (Alternative)

If you have Docker installed:

# Build all services
docker-compose build

# Start all services
docker-compose up

# Stop all services
docker-compose down

API Documentation

Base URLs

Service URL Port
API Gateway http://localhost:3001 3001
FLIGHTS http://localhost:3003 3003
Flights_bookings http://localhost:3006 3006
noti-service http://localhost:3005 3005

API Gateway Endpoints

POST   /api/v1/signup        - Register new user
POST   /api/v1/signin        - Login user
GET    /api/v1/info          - Get server info

Example: User Signup

curl -X POST http://localhost:3001/api/v1/signup \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "securepassword"
  }'

FLIGHTS Service Endpoints

GET    /api/v1/flights              - List all flights
GET    /api/v1/flights/:id          - Get flight details
GET    /api/v1/airports             - List airports
GET    /api/v1/cities               - List cities
GET    /api/v1/airplanes            - List airplanes

Flights_bookings Service Endpoints

POST   /api/v1/bookings             - Create a new booking
GET    /api/v1/bookings             - Get user bookings
GET    /api/v1/bookings/:id         - Get booking details
PUT    /api/v1/bookings/:id/cancel  - Cancel booking

noti-service Endpoints

GET    /api/v1/tickets              - Get all tickets
GET    /api/v1/tickets/:id          - Get ticket details

For detailed API documentation, see Flight_Booking_System_Documentation.md


Inter-Service Communication

HTTP Communication (Synchronous)

Flights_bookings → FLIGHTS

When creating a booking, the service queries FLIGHTS to validate flight and seat availability:

// Example from Flights_bookings service
const response = await axios.get(
  `http://localhost:3003/api/v1/flights/${flightId}`
);

Message Queue Communication (Asynchronous)

Flights_bookings → noti-service (via RabbitMQ)

After successful booking, a message is published to the queue:

// Publishing message
await channel.assertQueue('noti-queue');
channel.sendToQueue('noti-queue', Buffer.from(JSON.stringify({
  bookingId: booking.id,
  userEmail: user.email,
  flightDetails: booking.flight
})));

noti-service subscribes to the queue and processes messages asynchronously.


Database Setup

MySQL Database Schema

Each service manages its own database:

  • api_gateway: User authentication and profile data
  • flights_db: Flight, airplane, airport, and city information
  • bookings_db: Booking records and seat allocations
  • notifications_db: Email tickets and notification history

Viewing Database Structure

# Connect to MySQL
mysql -u root -p

# Show all databases
SHOW DATABASES;

# Use a specific database
USE flights_db;

# Show all tables
SHOW TABLES;

# Describe a table
DESCRIBE flights;

Environment Variables

Common Variables Across Services

Variable Purpose Example
PORT Service port 3001, 3003, 3005, 3006
NODE_ENV Environment mode development, production
DB_HOST MySQL host localhost
DB_USER MySQL username root
DB_PASSWORD MySQL password securepass
DB_NAME Database name api_gateway
LOG_LEVEL Logging level debug, info, warn, error

Service-Specific Variables

  • API Gateway: JWT_SECRET, JWT_EXPIRY
  • Flights_bookings: FLIGHTS_SERVICE_URL, RABBITMQ_URL, PAYMENT_GATEWAY_URL
  • noti-service: RABBITMQ_URL, SMTP_HOST, SMTP_USER, SMTP_PASS

Testing

Health Check

Test if all services are running:

# API Gateway Health
curl http://localhost:3001/api/v1/info

# FLIGHTS Health  
curl http://localhost:3003/api/v1/info

# Flights_bookings Health
curl http://localhost:3006/api/v1/info

# noti-service Health
curl http://localhost:3005/api/v1/info

Using Postman

  1. Download Postman
  2. Import the API collection (if available in repositories)
  3. Set environment variables for base URLs
  4. Test endpoints

End-to-End Test Flow

  1. Sign up → API Gateway
  2. Get flights → FLIGHTS service
  3. Create booking → Flights_bookings service
  4. Verify email notification → noti-service

Troubleshooting

Issue: "Cannot find module" Error

Solution:

# Ensure all dependencies are installed
npm install

# Clear node_modules cache
rm -rf node_modules
npm install

Issue: Database Connection Error

Solution:

# Verify MySQL is running
mysql -u root -p

# Check if database exists
SHOW DATABASES;

# Verify credentials in .env file

Issue: RabbitMQ Connection Error

Solution:

# Verify RabbitMQ is running
sudo systemctl status rabbitmq-server

# Start RabbitMQ if not running
sudo systemctl start rabbitmq-server

# Check RabbitMQ on default port 5672

Issue: Port Already in Use

Solution:

# Find process using port (e.g., 3001)
lsof -i :3001

# Kill process
kill -9 <PID>

# Or use different port in .env

Issue: Submodule Not Updating

Solution:

# Force update all submodules
git submodule update --remote --force

# Or re-initialize submodules
git submodule deinit -all
git submodule update --init --recursive

Contributing

Git Workflow

  1. Clone with submodules

    git clone --recurse-submodules <repo-url>
  2. Create feature branch (in each submodule)

    cd <service-name>
    git checkout -b feature/your-feature
  3. Make changes and commit

    git add .
    git commit -m "feat: add your feature"
    git push origin feature/your-feature
  4. Create Pull Request on GitHub

  5. Update main repository after PR merge

    git submodule update --remote
    git add .
    git commit -m "Update submodule version"
    git push

Code Standards

  • Use descriptive commit messages
  • Follow existing code style
  • Add comments for complex logic
  • Test before pushing
  • Update README if adding new features

Additional Resources


License

This project is licensed under the MIT License - see the LICENSE file for details.


Support

For issues or questions:

  • Create an issue on GitHub
  • Check existing documentation
  • Review individual service READMEs
  • Contact the development team

Last Updated: April 2026
Version: 1.0.0
Repository: https://github.com/AsyncNigam/Flight-Booking-Management-System

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors