A secure, role-based backend service built using Spring Boot and Gradle with MySQL to manage hotel listings and room bookings for a hotel management aggregator platform. The application exposes RESTful APIs secured with JWT-based authentication and enforces strict role-based authorization and business rules to prevent overbooking and ensure data integrity.
This project follows a clean layered architecture and incorporates production-ready practices such as validation, centralized error handling, logging, and unit testing.
The goal of this project is to design and implement a backend service for a simplified hotel room booking system that:
The system assumes:
| Technology | Purpose |
|---|---|
| Java 17 | Backend programming language |
| Spring Boot (3.3.3) | Framework for building RESTful APIs |
| Spring Security | Authentication & authorization |
| JWT (io.jsonwebtoken:0.11.5) | Stateless authentication |
| MySQL | Relational database for persistent storage |
| Spring Data JPA | ORM and database abstraction |
| BCrypt | Secure password hashing |
| Gradle | Build and dependency management |
| JUnit 5 & Mockito | Unit and integration testing |
| SLF4J / Logback | Logging |
Why Gradle? Gradle provides efficient build automation, dependency management, and incremental compilation for faster builds, especially in Spring Boot projects.
Why MySQL? MySQL provides strong transactional guarantees and relational integrity, making it suitable for booking systems where consistency and accuracy are critical.
Client (Postman / Frontend)
โ
Controller Layer
โ
Service Layer
โ
Repository Layer
โ
MySQL Database
Controller Layer Handles HTTP requests, request validation, and response mapping
Service Layer Contains core business logic such as booking rules, room availability checks, and date validation
Repository Layer Manages database operations using Spring Data JPA
Security Layer Implements JWT authentication and role-based access control
| Role | Description |
|---|---|
| USER | Can browse hotels and create bookings |
| HOTEL_MANAGER | Can update hotel details and cancel bookings |
| ADMIN | Can create and delete hotels |
| Action | USER | HOTEL_MANAGER | ADMIN |
|---|---|---|---|
| Register / Login | โ | โ | โ |
| Browse Hotels | โ | โ | โ |
| Create Hotel | โ | โ | โ |
| Update Hotel | โ | โ | โ |
| Delete Hotel | โ | โ | โ |
| Create Booking | โ | โ | โ |
| Cancel Booking | โ | โ | โ |
USERDate validation:
YYYY-MM-DDhttp://localhost:8081
| Method | Endpoint |
|---|---|
| POST | /api/users/register |
| POST | /api/users/login |
| Method | Endpoint | Access |
|---|---|---|
| GET | /api/hotels | Public |
| POST | /api/hotels | ADMIN |
| PUT | /api/hotels/{hotelId} | HOTEL_MANAGER |
| DELETE | /api/hotels/{hotelId} | ADMIN |
| Method | Endpoint | Access |
|---|---|---|
| POST | /api/bookings/{hotelId} | USER |
| GET | /api/bookings/{bookingId} | Authenticated |
| DELETE | /api/bookings/{bookingId} | HOTEL_MANAGER |
# Clone the repository
git clone <your-github-repo-url>
cd hotel-booking-aggregator
# Configure database
# Update application.properties or application.yml with MySQL credentials
# Build the project
./gradlew clean build
# Run the application
./gradlew bootRun
http://localhost:8081
Contributions, issues, and feature requests are welcome. Feel free to open an issue or submit a pull request.
Maintained by: Shushant Rishav