A lightweight Spring Boot 4 backend application for managing hotels, rooms, and bookings using a clean layered architecture.
- Overview
- Core Features
- Architecture
- Getting Started
- API Endpoints
- Documentation
- Technology Stack
- Project Structure
- Installation
- Configuration
- Running the Application
- Testing
- Contributing
- License
This project provides a Spring Boot 4 REST API for handling hotel booking operations. It showcases essential backend development concepts, including:
- Layered Architecture for better code organization
- RESTful APIs with CRUD functionality
- Spring Data JPA for database interaction
- Centralized Exception Handling
- OpenAPI (Swagger) integration for API documentation
- Request Validation to ensure reliable input
- Add new hotels
- Retrieve hotel information
- Maintain hotel and room relationships
- Create and manage rooms
- Store room pricing details
- Associate rooms with hotels and bookings
- Register new bookings
- View booking records
- Store guest and reservation details
- Request validation
- Custom exception classes
- Global exception handling mechanism
- Interactive Swagger UI
- API request and response reference
βββββββββββββββββββββββββββββββββββββββ
β Controller Layer β
β (REST API Endpoints) β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββ
β Service Layer β
β (Business Logic & Validation) β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββ
β Repository Layer β
β (Database Access Operations) β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββ
β Entity Layer β
β (Domain Models) β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββ
β MySQL Database β
β (Persistent Storage) β
βββββββββββββββββββββββββββββββββββββββ
Ensure the following tools are installed:
# Verify Java installation (21 or above)
java -version
# Verify Maven installation (3.6 or above)
mvn -version
# Confirm MySQL is running
mysql -u root -pCREATE DATABASE hotel_booking_db
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;Update the database credentials inside:
src/main/resources/application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/hotel_booking_db
spring.datasource.username=root
spring.datasource.password=your_password# Build the application
mvn clean install
# Start using Maven
mvn spring-boot:run
# Or execute the packaged JAR
java -jar target/ai-spring-boot-hotel-booking-0.0.1-SNAPSHOT.jarSwagger UI : http://localhost:8080/swagger-ui.html
OpenAPI Docs: http://localhost:8080/api-docs
Base URL : http://localhost:8080/api/v1
The application exposes RESTful endpoints for managing hotels, rooms, and bookings.
POST /api/v1/hotels Create a new hotel
GET /api/v1/hotels Retrieve all hotels
GET /api/v1/hotels/{id} Retrieve hotel details by IDPOST /api/v1/rooms?hotelId={hotelId} Add a room to a hotel
GET /api/v1/rooms Retrieve all roomsPOST /api/v1/bookings Create a new booking
GET /api/v1/bookings Retrieve all bookingsAvailable Endpoints: 7
The repository contains dedicated documentation to help you understand the project and its implementation.
| Document | Description |
|---|---|
| ARCHITECTURE.md | Explains the overall project architecture and design. |
| API_DOCUMENTATION.md | Complete REST API reference with endpoint details. |
| GETTING_STARTED.md | Step-by-step setup and installation guide. |
| QUICK_REFERENCE.md | Handy reference for frequently used commands and APIs. |
| IMPLEMENTATION_SUMMARY.md | Overview of the implementation and project decisions. |
The project is built using the following technologies:
| Technology | Version | Purpose |
|---|---|---|
| Java | 21 | Core programming language |
| Spring Boot | 4.0.3 | Backend application framework |
| Spring Data JPA | Latest | Data persistence layer |
| Hibernate | Latest | JPA implementation |
| MySQL | 8.0+ | Relational database |
| Jakarta EE | Latest | Enterprise Java specifications |
| Lombok | Latest | Reduces boilerplate code |
| SpringDoc OpenAPI | 3.0.2 | Swagger/OpenAPI integration |
| Maven | 3.6+ | Dependency management and build tool |
The project follows a clean layered architecture to improve readability and maintainability.
ai-spring-boot-hotel-booking/
βββ src/main/java/com/dipdeveloper/ai_spring_boot_hotel_booking/
β βββ controller/ # REST Controllers
β βββ service/ # Business Logic
β βββ repository/ # Data Access Layer
β βββ entity/ # JPA Entities
β βββ dto/ # Request & Response DTOs
β βββ exception/ # Custom Exceptions & Global Handler
β βββ config/ # Configuration Classes
β βββ AiSpringBootHotelBookingApplication.java
βββ src/main/resources/
β βββ application.properties
βββ pom.xml
βββ ARCHITECTURE.md
βββ API_DOCUMENTATION.md
βββ GETTING_STARTED.md
βββ QUICK_REFERENCE.md
βββ IMPLEMENTATION_SUMMARY.md
βββ README.md
The application consists of three primary database tables.
| Column | Type | Constraint |
|---|---|---|
| id | BIGINT | Primary Key, Auto Increment |
| name | VARCHAR(255) | Not Null |
| location | VARCHAR(255) | Not Null |
| Column | Type | Constraint |
|---|---|---|
| id | BIGINT | Primary Key, Auto Increment |
| room_number | VARCHAR(255) | Not Null |
| price | DOUBLE | Not Null |
| hotel_id | BIGINT | Foreign Key β hotels.id |
| Column | Type | Constraint |
|---|---|---|
| id | BIGINT | Primary Key, Auto Increment |
| guest_name | VARCHAR(255) | Not Null |
| check_in_date | DATE | Not Null |
| check_out_date | DATE | Not Null |
| room_id | BIGINT | Foreign Key β rooms.id |
The application validates incoming requests before processing them.
- Name is mandatory (2β100 characters)
- Location is mandatory
- Room Number is required
- Price must be greater than zero
- Hotel ID is required
- Guest Name is required
- Check-in Date is required
- Check-out Date is required
- Room ID is required
- Start the application using:
mvn spring-boot:run
- Visit http://localhost:8080/swagger-ui.html
- Expand any endpoint.
- Click Try it out.
- Provide the required values and execute the request.
Retrieve all hotels:
curl http://localhost:8080/api/v1/hotelsCreate a hotel:
curl -X POST http://localhost:8080/api/v1/hotels \
-H "Content-Type: application/json" \
-d '{
"name":"Test Hotel",
"location":"New York"
}'Before getting started, ensure the following are installed on your system:
- Java Development Kit (JDK) 21+
- MySQL Server 8.0+
- Maven 3.6+
- Git (Optional)
git clone https://github.com/your-repo/ai-spring-boot-hotel-booking.git
cd ai-spring-boot-hotel-bookingCREATE DATABASE hotel_booking_db
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;Update the following properties in src/main/resources/application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/hotel_booking_db
spring.datasource.username=root
spring.datasource.password=your_passwordmvn clean installmvn spring-boot:runCustomize the application by editing the application.properties file.
# Server Configuration
server.port=8080
# Database Configuration
spring.datasource.url=jdbc:mysql://localhost:3306/hotel_booking_db
spring.datasource.username=root
spring.datasource.password=root
# Hibernate/JPA
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
# Logging
logging.level.root=INFO
logging.level.com.dipdeveloper.ai_spring_boot_hotel_booking=DEBUG
# Swagger / OpenAPI
springdoc.swagger-ui.enabled=trueChoose any of the following methods to start the project.
mvn spring-boot:runmvn clean package
java -jar target/ai-spring-boot-hotel-booking-0.0.1-SNAPSHOT.jar- Import the project into your preferred IDE.
- Open
AiSpringBootHotelBookingApplication. - Run it as a Java application.
- Make sure the MySQL server is running.
- Verify the database credentials.
- Confirm the database has been created.
- Update the server port:
server.port=8081- Or stop the process using port 8080.
- Clean the project:
mvn clean- Verify your Java installation:
java -version- Rebuild dependencies:
mvn clean install -UFor additional guidance, refer to GETTING_STARTED.md.
Contributions are always welcome!
- Fork this repository.
- Create a new feature branch.
- Commit your changes.
- Push your branch.
- Open a Pull Request.
This project is distributed under the Apache License 2.0. See the LICENSE file for complete details.
Hotel Booking System Development Team
- πΊ YouTube: Dip Developer
- π» GitHub: TheDipDeveloper
Special thanks to the following technologies and communities:
- Spring Boot
- Spring Data JPA
- SpringDoc OpenAPI
- MySQL
If you encounter any issues:
- Review the project documentation.
- Check the application logs.
- Search existing GitHub Issues.
- Create a new issue with detailed information if needed.
- Hotel Management APIs
- Room Management APIs
- Booking Management APIs
- Swagger Documentation
- Enhanced validation
- Additional REST endpoints
- More advanced features
| Metric | Value |
|---|---|
| Java Classes | 29 |
| REST APIs | 7 |
| Database Tables | 3 |
| Documentation Files | 5 |
| Approx. Lines of Code | 1,000+ |
- Layered Architecture
- RESTful API Design
- Spring Data JPA Integration
- MySQL Support
- Exception Handling
- Request Validation
- Swagger Documentation
- Transaction Management
- Clean Code Practices