Skip to content

I-am-Rishabh/BusPort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Bus Reservation System

Java Spring Boot Maven MySQL JWT Microservices

A comprehensive microservices-based bus reservation system built with Spring Boot, providing user authentication, bus management, route planning, scheduling, and booking capabilities.

πŸ—οΈ Architecture Overview

The system consists of three main microservices:

  • User Service - Handles user authentication, registration, and profile management
  • Bus Service - Manages buses, routes, schedules, and search functionality
  • Booking Service - Handles ticket bookings, cancellations, and passenger management

πŸ› οΈ Technology Stack

  • Backend Framework: Spring Boot 3.x
  • Build Tool: Maven
  • Database: MySQL
  • Authentication: JWT-based authentication
  • Validation: Jakarta Validation (Bean Validation)
  • Documentation: Lombok for boilerplate reduction

πŸ“‹ Prerequisites

Before running the application, ensure you have the following installed:

  • Java 17 or later
  • Maven 3.6 or later
  • MySQL 8.0 or later
  • Git

πŸš€ Getting Started

1. Clone the Repository

git clone <repository-url>
cd BusPort

2. Database Setup

Create three MySQL databases for each microservice:

CREATE DATABASE user_service_db;
CREATE DATABASE bus_service_db;
CREATE DATABASE booking_service_db;

3. Configure Application Properties

Update the application.properties or application.yml files in each service with your MySQL configuration:

User Service (UserService/src/main/resources/application.properties)

spring.application.name=user-service
server.port=8081

# Database Configuration
spring.datasource.url=jdbc:mysql://localhost:3306/user_service_db
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# JPA Configuration
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

# JWT Configuration
jwt.secret=your_jwt_secret_key
jwt.expiration=86400000

Bus Service (BusService/src/main/resources/application.properties)

spring.application.name=bus-service
server.port=8082

# Database Configuration
spring.datasource.url=jdbc:mysql://localhost:3306/bus_service_db
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# JPA Configuration
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

Booking Service (BookingService/src/main/resources/application.properties)

spring.application.name=booking-service
server.port=8083

# Database Configuration
spring.datasource.url=jdbc:mysql://localhost:3306/booking_service_db
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# JPA Configuration
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

4. Build and Run Services

Navigate to each service directory and run the following commands:

User Service

cd UserService
mvn clean install
mvn spring-boot:run

Bus Service

cd BusService
mvn clean install
mvn spring-boot:run

Booking Service

cd BookingService
mvn clean install
mvn spring-boot:run

πŸ“‘ API Endpoints

User Service (Port: 8081)

Authentication

  • POST /api/auth/register - Register a new user
  • POST /api/auth/login - Authenticate user and get JWT token

User Profile

  • GET /api/user/profile - Get user profile (Authenticated)
  • PUT /api/user/profile - Update user profile (Authenticated)

Bus Service (Port: 8082)

Bus Management

  • POST /api/bus - Create a new bus
  • PUT /api/bus/{id} - Update bus information
  • DELETE /api/bus/{id} - Delete a bus
  • GET /api/bus/{id} - Get bus by ID
  • GET /api/bus - Get all buses

Route Management

  • POST /api/route - Create a new route
  • PUT /api/route/{id} - Update route information
  • DELETE /api/route/{id} - Delete a route
  • GET /api/route/{id} - Get route by ID
  • GET /api/route/all - Get all routes

Schedule Management

  • POST /api/schedules - Create a new schedule
  • PUT /api/schedules/{id} - Update schedule
  • DELETE /api/schedules/{id} - Delete schedule
  • PUT /api/schedules/{id}/seats - Update available seats
  • GET /api/schedules/{id} - Get schedule by ID
  • GET /api/schedules - Get all schedules

Search

  • GET /api/search?source={source}&destination={destination}&date={date} - Search buses

Booking Service (Port: 8083)

Booking Management

  • POST /api/bookings - Create a new booking
  • PUT /api/bookings/{bookingId}/cancel - Cancel a booking
  • GET /api/bookings/user - Get user's bookings
  • GET /api/bookings/user/upcoming - Get upcoming journeys
  • GET /api/bookings/admin/all - Get all bookings (Admin)
  • GET /api/bookings/check-schedule/{scheduleId} - Check active bookings for schedule
  • GET /api/bookings/schedule/{scheduleId}/passengers - Get passengers by schedule

πŸ” Authentication

The system uses JWT-based authentication. Include the JWT token in the Authorization header for protected endpoints:

Authorization: Bearer <your_jwt_token>

Some booking endpoints require the user ID to be passed in the X-User-Id header.

πŸ“ Request/Response Examples

User Registration

POST /api/auth/register
{
    "firstName": "John",
    "lastName": "Doe",
    "email": "[email protected]",
    "password": "password123",
    "phoneNumber": "+1234567890"
}

User Login

POST /api/auth/login
{
    "email": "[email protected]",
    "password": "password123"
}

Create Booking

POST /api/bookings
Headers: X-User-Id: 1
{
    "scheduleId": 1,
    "passengers": [
        {
            "name": "John Doe",
            "age": 30,
            "gender": "MALE",
            "seatNumber": "A1"
        }
    ],
    "totalAmount": 500.00
}

Search Buses

GET /api/search?source=mumbai&destination=pune&date=2024-12-25

πŸƒβ€β™‚οΈ Running in Development

  1. Start MySQL server
  2. Create the required databases
  3. Update configuration files with your database credentials
  4. Run each service in separate terminal windows
  5. Services will be available at:

πŸ”§ Project Structure

BusPort/
β”œβ”€β”€ UserService/
β”‚   β”œβ”€β”€ src/main/java/com/reservation/UserService/
β”‚   β”‚   β”œβ”€β”€ controller/
β”‚   β”‚   β”œβ”€β”€ service/
β”‚   β”‚   β”œβ”€β”€ dto/
β”‚   β”‚   └── ...
β”‚   └── pom.xml
β”œβ”€β”€ BusService/
β”‚   β”œβ”€β”€ src/main/java/com/reservation/BusService/
β”‚   β”‚   β”œβ”€β”€ Controller/
β”‚   β”‚   β”œβ”€β”€ Model/
β”‚   β”‚   └── ...
β”‚   └── pom.xml
β”œβ”€β”€ BookingService/
β”‚   β”œβ”€β”€ src/main/java/com/reservation/BookingService/
β”‚   β”‚   β”œβ”€β”€ Controller/
β”‚   β”‚   β”œβ”€β”€ Model/
β”‚   β”‚   └── ...
β”‚   └── pom.xml
└── README.md

About

Bus Ticket Reservation System

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages