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.
- Project Overview
- Architecture
- Prerequisites
- Project Structure
- Cloning with Submodules
- Setup Instructions
- Running the Services
- API Documentation
- Inter-Service Communication
- Database Setup
- Environment Variables
- Testing
- Troubleshooting
- Contributing
The Flight Booking Management System is a production-ready microservices architecture consisting of:
- API Gateway - Authentication, user management, and request routing
- FLIGHTS - Flight, airplane, airport, and city data management
- Flights_bookings - Booking operations and seat management
- 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)
┌─────────────────────────────────────────────────────────┐
│ 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) │
└─────────────────────┘
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
- Docker & Docker Compose - For containerized setup
- Postman - For API testing
- VSCode - Recommended IDE
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
# 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# 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 --recursiveTo 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# 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;Each service includes migration files. Navigate to each service and run:
npx sequelize-cli db:createNavigate 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 ..
doneCreate .env file in each service directory:
# 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# 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# 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# 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.logRun 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 ..Populate sample data:
# FLIGHTS service has seeders for airplanes, airports, cities, etc.
cd FLIGHTS
npx sequelize-cli db:seed:all
cd ..Open separate terminal windows for each service:
cd "API gateway"
npm start
# Server running on http://localhost:3001cd FLIGHTS
npm start
# Server running on http://localhost:3003cd Flights_bookings
npm start
# Server running on http://localhost:3006cd noti-service
npm start
# Server running on http://localhost:3005# 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/infoIf you have Docker installed:
# Build all services
docker-compose build
# Start all services
docker-compose up
# Stop all services
docker-compose down| 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 |
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"
}'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
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
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
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}`
);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.
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
# 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;| 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 |
- 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
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- Download Postman
- Import the API collection (if available in repositories)
- Set environment variables for base URLs
- Test endpoints
- Sign up → API Gateway
- Get flights → FLIGHTS service
- Create booking → Flights_bookings service
- Verify email notification → noti-service
Solution:
# Ensure all dependencies are installed
npm install
# Clear node_modules cache
rm -rf node_modules
npm installSolution:
# Verify MySQL is running
mysql -u root -p
# Check if database exists
SHOW DATABASES;
# Verify credentials in .env fileSolution:
# Verify RabbitMQ is running
sudo systemctl status rabbitmq-server
# Start RabbitMQ if not running
sudo systemctl start rabbitmq-server
# Check RabbitMQ on default port 5672Solution:
# Find process using port (e.g., 3001)
lsof -i :3001
# Kill process
kill -9 <PID>
# Or use different port in .envSolution:
# Force update all submodules
git submodule update --remote --force
# Or re-initialize submodules
git submodule deinit -all
git submodule update --init --recursive-
Clone with submodules
git clone --recurse-submodules <repo-url>
-
Create feature branch (in each submodule)
cd <service-name> git checkout -b feature/your-feature
-
Make changes and commit
git add . git commit -m "feat: add your feature" git push origin feature/your-feature
-
Create Pull Request on GitHub
-
Update main repository after PR merge
git submodule update --remote git add . git commit -m "Update submodule version" git push
- Use descriptive commit messages
- Follow existing code style
- Add comments for complex logic
- Test before pushing
- Update README if adding new features
- Detailed System Documentation
- API Gateway README
- FLIGHTS README
- Flights_bookings README
- noti-service README
This project is licensed under the MIT License - see the LICENSE file for details.
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