Skip to content

adityainhub/flight-booking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flight Booking Microservices System

Project Overview

This project implements a modern, scalable flight booking system using microservices architecture. The system consists of multiple services that handle different aspects of flight booking, from searching flights to managing bookings and sending notifications.

System Architecture

Microservices Components

  1. Booking Service (Port: 8081)

    • Handles flight searches and booking management
    • Integrates with AviationStack API for real-time flight data
    • Manages booking creation and retrieval
    • Communicates with Notification Service via RabbitMQ
  2. Notification Service (Port: 8082)

    • Handles email notifications for booking confirmations
    • Processes booking events from RabbitMQ
    • Sends confirmation emails to customers
  3. Frontend Service (Port: 3000)

    • React-based user interface
    • Provides intuitive booking experience
    • Real-time flight search and booking management

Infrastructure Components

  1. PostgreSQL Database

    • Stores booking and user data
    • Runs on port 5432
    • Database name: flightbooking
    • Default credentials:
      • Username: postgres
      • Password: password
  2. RabbitMQ

    • Message broker for inter-service communication
    • Runs on port 5672
    • Management interface on port 15672
    • Default credentials:
      • Username: admin
      • Password: admin

Technical Stack

Backend Technologies

  • Java 17
  • Spring Boot 3.x
  • Spring Data JPA
  • Spring WebFlux
  • PostgreSQL
  • RabbitMQ
  • Maven

Frontend Technologies

  • React
  • TypeScript
  • Material-UI
  • Axios

DevOps & Infrastructure

  • Docker
  • Docker Compose
  • Git

API Documentation

Booking Service Endpoints

All endpoints are prefixed with /api

  1. Search Flights

    POST /flights/search
    Content-Type: application/json
    
    Request:
    {
      "fromCity": "new york",
      "toCity": "london"
    }
    
    Response:
    {
      "flights": [
        {
          "flightNumber": "AA123",
          "airline": "American Airlines",
          "departureCity": "New York",
          "arrivalCity": "London",
          "departureTime": "2024-03-20T10:00:00",
          "arrivalTime": "2024-03-20T22:00:00",
          "price": 499.99
        }
      ]
    }
    
  2. Create Booking

    POST /bookings
    Content-Type: application/json
    
    Request:
    {
      "flightNumber": "AA123",
      "passengerName": "John Doe",
      "passengerEmail": "john@example.com",
      "departureDate": "2024-03-20"
    }
    
    Response:
    {
      "id": 1,
      "flightNumber": "AA123",
      "passengerName": "John Doe",
      "passengerEmail": "john@example.com",
      "departureDate": "2024-03-20",
      "bookingDate": "2024-03-15T14:30:00",
      "status": "CONFIRMED"
    }
    
  3. Get All Bookings

    GET /bookings
    
    Response:
    [
      {
        "id": 1,
        "flightNumber": "AA123",
        "passengerName": "John Doe",
        "passengerEmail": "john@example.com",
        "departureDate": "2024-03-20",
        "bookingDate": "2024-03-15T14:30:00",
        "status": "CONFIRMED"
      }
    ]
    
  4. Get Booking by ID

    GET /bookings/{id}
    
    Response:
    {
      "id": 1,
      "flightNumber": "AA123",
      "passengerName": "John Doe",
      "passengerEmail": "john@example.com",
      "departureDate": "2024-03-20",
      "bookingDate": "2024-03-15T14:30:00",
      "status": "CONFIRMED"
    }
    
  5. Get Bookings by Email

    GET /bookings/email/{email}
    
    Response:
    [
      {
        "id": 1,
        "flightNumber": "AA123",
        "passengerName": "John Doe",
        "passengerEmail": "john@example.com",
        "departureDate": "2024-03-20",
        "bookingDate": "2024-03-15T14:30:00",
        "status": "CONFIRMED"
      }
    ]
    
  6. Get Supported Cities

    GET /cities
    
    Response:
    {
      "cities": [
        "New York",
        "London",
        "Paris",
        "Tokyo",
        "Sydney"
      ]
    }
    

Notification Service Endpoints

  1. Send Email Notification

    POST /api/notifications/email
    Content-Type: application/json
    
    Request:
    {
      "to": "john@example.com",
      "subject": "Flight Booking Confirmation",
      "body": "Your flight booking has been confirmed..."
    }
    
    Response:
    {
      "status": "SENT",
      "message": "Email notification sent successfully"
    }
    
  2. Get Notification Status

    GET /api/notifications/{id}
    
    Response:
    {
      "id": 1,
      "status": "SENT",
      "sentAt": "2024-03-15T14:30:00",
      "recipient": "john@example.com"
    }
    

Error Responses

All endpoints may return the following error responses:

  1. 400 Bad Request

    {
      "error": "Bad Request",
      "message": "Invalid input parameters",
      "timestamp": "2024-03-15T14:30:00"
    }
  2. 404 Not Found

    {
      "error": "Not Found",
      "message": "Resource not found",
      "timestamp": "2024-03-15T14:30:00"
    }
  3. 500 Internal Server Error

    {
      "error": "Internal Server Error",
      "message": "An unexpected error occurred",
      "timestamp": "2024-03-15T14:30:00"
    }

Database Schema

Booking Table

CREATE TABLE bookings (
    id BIGSERIAL PRIMARY KEY,
    flight_number VARCHAR(10) NOT NULL,
    passenger_name VARCHAR(100) NOT NULL,
    passenger_email VARCHAR(100) NOT NULL,
    departure_date DATE NOT NULL,
    booking_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    status VARCHAR(20) DEFAULT 'CONFIRMED'
);

Setup and Installation

Prerequisites

  • Docker and Docker Compose
  • Java 17
  • Maven
  • Node.js and npm (for frontend)

Environment Variables

Create a .env file in the project root:

AVIATIONSTACK_API_KEY=your_api_key
EMAIL_USERNAME=your_email
EMAIL_PASSWORD=your_email_password

Running the Application

  1. Start all services:

    docker-compose up --build
  2. Access the services:

Development Workflow

Local Development

  1. Clone the repository
  2. Set up environment variables
  3. Run services individually for development:
    # Booking Service
    cd booking-service
    mvn spring-boot:run
    
    # Notification Service
    cd notification-service
    mvn spring-boot:run
    
    # Frontend
    cd frontend
    npm install
    npm start

Database Management

  1. Connect to PostgreSQL:

    docker exec -it flightservice-postgres-1 psql -U postgres -d flightbooking
  2. View tables:

    \dt
  3. View table structure:

    \d table_name

Testing

API Testing

Use the provided Postman collection or test endpoints using curl:

# Search flights
curl -X POST http://localhost:8081/api/flights/search \
  -H "Content-Type: application/json" \
  -d '{"fromCity":"new york","toCity":"london"}'

# Create booking
curl -X POST http://localhost:8081/api/bookings \
  -H "Content-Type: application/json" \
  -d '{"flightNumber":"AA123","passengerName":"John Doe","passengerEmail":"john@example.com","departureDate":"2024-03-20"}'

Security Considerations

  1. API Security

    • Environment variables for sensitive data
    • Input validation
    • Error handling
  2. Database Security

    • Secure password storage
    • Connection encryption
    • Access control
  3. Communication Security

    • HTTPS for API endpoints
    • Secure email configuration
    • Message encryption

Monitoring and Logging

  1. Application Logs

    • Spring Boot logging
    • Docker container logs
    • Error tracking
  2. Performance Monitoring

    • Service health checks
    • Response time monitoring
    • Resource utilization

Future Enhancements

  1. Planned Features

    • User authentication and authorization
    • Payment integration
    • Flight schedule management
    • Admin dashboard
  2. Technical Improvements

    • Service discovery
    • API gateway
    • Circuit breakers
    • Caching layer

Troubleshooting

Common Issues

  1. Database Connection

    • Check PostgreSQL container status
    • Verify credentials
    • Check port availability
  2. RabbitMQ Issues

    • Verify service connectivity
    • Check queue status
    • Monitor message flow
  3. API Integration

    • Validate API keys
    • Check service health
    • Verify request/response format

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit changes
  4. Push to the branch
  5. Create a Pull Request

License

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

Contact

For support or queries, please contact the development team.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages