Skip to content

Repository files navigation

Hotel Booking System - Spring Boot 4

A lightweight Spring Boot 4 backend application for managing hotels, rooms, and bookings using a clean layered architecture.

Spring Boot Java MySQL License


πŸ“‘ Table of Contents


🌟 Overview

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

✨ Core Features

🏨 Hotel Management

  • Add new hotels
  • Retrieve hotel information
  • Maintain hotel and room relationships

πŸ›οΈ Room Management

  • Create and manage rooms
  • Store room pricing details
  • Associate rooms with hotels and bookings

πŸ“… Booking Management

  • Register new bookings
  • View booking records
  • Store guest and reservation details

βœ… Validation & Exception Handling

  • Request validation
  • Custom exception classes
  • Global exception handling mechanism

πŸ“– API Documentation

  • Interactive Swagger UI
  • API request and response reference

πŸ—οΈ Architecture

Layered Design

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         Controller Layer            β”‚
β”‚      (REST API Endpoints)           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚          Service Layer              β”‚
β”‚    (Business Logic & Validation)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        Repository Layer             β”‚
β”‚   (Database Access Operations)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚          Entity Layer               β”‚
β”‚       (Domain Models)               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚          MySQL Database             β”‚
β”‚        (Persistent Storage)         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Getting Started

1. Prerequisites

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 -p

2. Create the Database

CREATE DATABASE hotel_booking_db
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;

3. Configure the Application

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

4. Build and Launch

# 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.jar

5. Access the Application

Swagger UI : http://localhost:8080/swagger-ui.html
OpenAPI Docs: http://localhost:8080/api-docs
Base URL    : http://localhost:8080/api/v1

πŸ”Œ API Endpoints

The application exposes RESTful endpoints for managing hotels, rooms, and bookings.

🏨 Hotel APIs (3 Endpoints)

POST   /api/v1/hotels                     Create a new hotel
GET    /api/v1/hotels                     Retrieve all hotels
GET    /api/v1/hotels/{id}                Retrieve hotel details by ID

πŸ›οΈ Room APIs (2 Endpoints)

POST   /api/v1/rooms?hotelId={hotelId}    Add a room to a hotel
GET    /api/v1/rooms                      Retrieve all rooms

πŸ“… Booking APIs (2 Endpoints)

POST   /api/v1/bookings                   Create a new booking
GET    /api/v1/bookings                   Retrieve all bookings

Available Endpoints: 7


πŸ“š Documentation

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.

πŸ› οΈ Technology Stack

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

πŸ“ Project Structure

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

πŸ’Ύ Database Schema

The application consists of three primary database tables.

🏨 hotels

Column Type Constraint
id BIGINT Primary Key, Auto Increment
name VARCHAR(255) Not Null
location VARCHAR(255) Not Null

πŸ›οΈ rooms

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

πŸ“… bookings

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

πŸ” Validation Rules

The application validates incoming requests before processing them.

Hotel

  • Name is mandatory (2–100 characters)
  • Location is mandatory

Room

  • Room Number is required
  • Price must be greater than zero
  • Hotel ID is required

Booking

  • Guest Name is required
  • Check-in Date is required
  • Check-out Date is required
  • Room ID is required

πŸ§ͺ Testing

Testing with Swagger UI (Recommended)

  1. Start the application using:
    mvn spring-boot:run
  2. Visit http://localhost:8080/swagger-ui.html
  3. Expand any endpoint.
  4. Click Try it out.
  5. Provide the required values and execute the request.

Testing with cURL

Retrieve all hotels:

curl http://localhost:8080/api/v1/hotels

Create a hotel:

curl -X POST http://localhost:8080/api/v1/hotels \
  -H "Content-Type: application/json" \
  -d '{
    "name":"Test Hotel",
    "location":"New York"
  }'

πŸ“¦ Installation

System Requirements

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)

Installation Steps

1. Clone the Repository

git clone https://github.com/your-repo/ai-spring-boot-hotel-booking.git
cd ai-spring-boot-hotel-booking

2. Create the Database

CREATE DATABASE hotel_booking_db
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;

3. Configure the Database

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_password

4. Build the Project

mvn clean install

5. Launch the Application

mvn spring-boot:run

βš™οΈ Configuration

Customize 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=true

▢️ Running the Application

Choose any of the following methods to start the project.

Using Maven

mvn spring-boot:run

Using the Executable JAR

mvn clean package
java -jar target/ai-spring-boot-hotel-booking-0.0.1-SNAPSHOT.jar

Using an IDE

  1. Import the project into your preferred IDE.
  2. Open AiSpringBootHotelBookingApplication.
  3. Run it as a Java application.

🐞 Troubleshooting

Unable to Connect to MySQL

  • Make sure the MySQL server is running.
  • Verify the database credentials.
  • Confirm the database has been created.

Port Already in Use

  • Update the server port:
server.port=8081
  • Or stop the process using port 8080.

Build Errors

  • Clean the project:
mvn clean
  • Verify your Java installation:
java -version
  • Rebuild dependencies:
mvn clean install -U

For additional guidance, refer to GETTING_STARTED.md.


🀝 Contributing

Contributions are always welcome!

  1. Fork this repository.
  2. Create a new feature branch.
  3. Commit your changes.
  4. Push your branch.
  5. Open a Pull Request.

πŸ“„ License

This project is distributed under the Apache License 2.0. See the LICENSE file for complete details.


πŸ‘¨β€πŸ’» Author

Hotel Booking System Development Team

  • πŸ“Ί YouTube: Dip Developer
  • πŸ’» GitHub: TheDipDeveloper

πŸ™ Acknowledgments

Special thanks to the following technologies and communities:

  • Spring Boot
  • Spring Data JPA
  • SpringDoc OpenAPI
  • MySQL

πŸ“ž Support

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.

πŸ—ΊοΈ Roadmap

βœ… Version 1.0

  • Hotel Management APIs
  • Room Management APIs
  • Booking Management APIs
  • Swagger Documentation

πŸš€ Planned for Version 1.1

  • Enhanced validation
  • Additional REST endpoints
  • More advanced features

πŸ“Š Project Overview

Metric Value
Java Classes 29
REST APIs 7
Database Tables 3
Documentation Files 5
Approx. Lines of Code 1,000+

βœ… Project Highlights

  • Layered Architecture
  • RESTful API Design
  • Spring Data JPA Integration
  • MySQL Support
  • Exception Handling
  • Request Validation
  • Swagger Documentation
  • Transaction Management
  • Clean Code Practices

About

A RESTful Hotel Booking Management System built using Spring Boot, Spring Data JPA, MySQL, and Swagger OpenAPI.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages