The Bus Booking System is a simple backend application built using Kotlin, Spring Boot, and H2 in-memory database. It allows users to authenticate, search for buses, and book seats. The system also provides an administrative interface for managing bus details.
- User Authentication: Users can log in with a phone number and password to receive a JWT token.
- Bus Management: Administrators can add, update, and view bus details.
- Bus Search: Users can search for buses based on the source and destination.
- Bus Booking: Users can book available seats on buses.
- Kotlin: Programming language used for developing the backend.
- Spring Boot: Framework for building the RESTful API and managing business logic.
- H2 Database: In-memory database used for storing user, bus, and booking information.
- JWT (JSON Web Token): Used for securing API endpoints.
- Client (Postman/Thunder Client) interacts with the Spring Boot Application through REST APIs.
- The application consists of Controllers, Services, Repositories, and a Security Component (JWT).
- All data is stored in an H2 In-Memory Database.
-
The flow starts with the User interacting with the Auth Controller for authentication, which forwards requests to the Auth Service and then to the JWT Util for token generation.
-
The Bus Controller and Booking Controller handle bus-related and booking-related operations, respectively, communicating with their respective services and repositories.
-
Authentication Flow:
- Start: Client → AuthenticationService → JwtService → Return JWT to Client.
-
Bus Management Flow (CRUD):
- Start: Client → BusService → BusRepository → Update DB → Return Response.
-
Bus Search Flow:
- Start: Client → BusService → BusRepository → Fetch Data → Return Buses.
-
Booking Flow:
- Start: Client → BookingService → BookingRepository → Check Availability → Confirm/Reject Booking → Update DB.
Bus-Booking-System/
│
├── src/main/kotlin/com/hm/bookingsystem/
│ ├── BookingSystemApplication.kt
│ ├── GlobalExceptionHandler.kt
│ ├── ServletInitializer.kt
│ ├── controller/
│ │ ├── AuthenticationController.kt
│ │ ├── BusController.kt
│ │ └── BookingController.kt
│ ├── model/
│ │ ├── Authentication.kt
│ │ ├── Customer.kt
│ │ ├── ErrorResponse.kt
│ │ ├── Booking.kt
│ │ ├── Bus.kt
│ │ └── request/
│ │ ├── AuthRequest.kt
│ │ └── BookingRequest.kt
│ ├── repository/
│ │ ├── CustomerRepository.kt
│ │ ├── BusRepository.kt
│ │ └── BookingRepository.kt
│ ├── extensions/
│ │ └── Extensions.kt
│ ├── service/
│ │ ├── AuthenticationService.kt
│ │ ├── BusService.kt
│ │ ├── JwtService.kt
│ │ └── BookingService.kt
│ └── config/
│ ├── ApplicationConfiguration.kt
│ ├── JwtAuthenticationFilter.kt
│ ├── DemoDataRunner.kt
│ └── SecurityConfiguration.kt
├── src/main/resources/
│ ├── application.properties
└── build.gradle.kts
- POST /booking-system/authenticate
- Request Body:
{ "username": "string", "password": "string" }
- Response:
{ "token": "jwt-token", "status": "success/failure", "expiry": 3600000 }
- Request Body:
-
GET /booking-system/bus
- Retrieves all buses.
-
POST /booking-system/bus
- Adds a new bus.
- Request Body:
{ "bus_number": "string", "bus_name": "string", "travel_company": "string", "capacity": "number", "available_seats": "number", "source": "string", "destination": "string" }
-
PUT /booking-system/bus
- Updates bus details.
- Request Body: Same as POST.
- GET /booking-system/search
- Searches for buses between a source and destination.
- Query Parameters:
source
: Source location.destination
: Destination location.
- POST /booking-system/book
- Books seats on a bus.
- Request Body:
{ "bus_number": "string", "booking_date": "string", "source": "string", "destination": "string", "total_seats": "number" }
- JWT (JSON Web Token) is used to secure the API endpoints. Only authenticated users can access certain endpoints.
- The token is required for all bus search and booking operations.
The system uses an H2 in-memory database to store information about:
- Customers: User details (ID, phone number, first name, last name, password).
- Buses: Details of the buses (bus number, name, travel company, capacity, available seats, source, destination).
- Bookings: Records of all bookings made by users (booking number, bus number, booking date, source, destination, total seats, booking status).
- Java 17 installed
- IntelliJ IDEA installed
- Clone the repository:
git clone https://github.com/mghisham/bus-booking-system.git
- Navigate to the project directory:
cd bus-booking-system
- Build the project using Gradle:
./gradlew clean ./gradlew build
- Run the Spring Boot application:
./gradlew bootRun
- The application will start on http://localhost:8080.
- The application database can be viewed on http://localhost:8080/h2-console/
You can use Postman or Thunder Client to send HTTP requests to the API endpoints.