A comprehensive microservices-based bus reservation system built with Spring Boot, providing user authentication, bus management, route planning, scheduling, and booking capabilities.
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
- 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
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
git clone <repository-url>
cd BusPortCreate three MySQL databases for each microservice:
CREATE DATABASE user_service_db;
CREATE DATABASE bus_service_db;
CREATE DATABASE booking_service_db;Update the application.properties or application.yml files in each service with your MySQL configuration:
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=86400000spring.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.MySQL8Dialectspring.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.MySQL8DialectNavigate to each service directory and run the following commands:
cd UserService
mvn clean install
mvn spring-boot:runcd BusService
mvn clean install
mvn spring-boot:runcd BookingService
mvn clean install
mvn spring-boot:runPOST /api/auth/register- Register a new userPOST /api/auth/login- Authenticate user and get JWT token
GET /api/user/profile- Get user profile (Authenticated)PUT /api/user/profile- Update user profile (Authenticated)
POST /api/bus- Create a new busPUT /api/bus/{id}- Update bus informationDELETE /api/bus/{id}- Delete a busGET /api/bus/{id}- Get bus by IDGET /api/bus- Get all buses
POST /api/route- Create a new routePUT /api/route/{id}- Update route informationDELETE /api/route/{id}- Delete a routeGET /api/route/{id}- Get route by IDGET /api/route/all- Get all routes
POST /api/schedules- Create a new schedulePUT /api/schedules/{id}- Update scheduleDELETE /api/schedules/{id}- Delete schedulePUT /api/schedules/{id}/seats- Update available seatsGET /api/schedules/{id}- Get schedule by IDGET /api/schedules- Get all schedules
GET /api/search?source={source}&destination={destination}&date={date}- Search buses
POST /api/bookings- Create a new bookingPUT /api/bookings/{bookingId}/cancel- Cancel a bookingGET /api/bookings/user- Get user's bookingsGET /api/bookings/user/upcoming- Get upcoming journeysGET /api/bookings/admin/all- Get all bookings (Admin)GET /api/bookings/check-schedule/{scheduleId}- Check active bookings for scheduleGET /api/bookings/schedule/{scheduleId}/passengers- Get passengers by schedule
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.
POST /api/auth/register
{
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"password": "password123",
"phoneNumber": "+1234567890"
}POST /api/auth/login
{
"email": "[email protected]",
"password": "password123"
}POST /api/bookings
Headers: X-User-Id: 1
{
"scheduleId": 1,
"passengers": [
{
"name": "John Doe",
"age": 30,
"gender": "MALE",
"seatNumber": "A1"
}
],
"totalAmount": 500.00
}GET /api/search?source=mumbai&destination=pune&date=2024-12-25
- Start MySQL server
- Create the required databases
- Update configuration files with your database credentials
- Run each service in separate terminal windows
- Services will be available at:
- User Service: http://localhost:8081
- Bus Service: http://localhost:8082
- Booking Service: http://localhost:8083
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