Hotel Booking System
The Hotel Booking System is a robust application designed using Clean Architecture principles to ensure maintainability, scalability, and separation of concerns. The system is divided into four primary layers: API, Application, Domain, and Infrastructure.
1. API Layer
The API layer serves as the entry point for client interactions, providing RESTful endpoints that facilitate user interactions with the system. This layer uses ASP.NET Core's framework to handle incoming HTTP requests and responses. Here’s a summary of the key controllers:
-
AuthController: Manages user authentication and registration. It provides
endpoints for:
- User registration: POST api/auth
- Login: POST api/auth/login
-
BookingController: Handles booking operations, including:
- Creating bookings: POST api/booking
- Retrieving booking details: GET api/booking/{bookingId}
- Canceling bookings: DELETE api/booking/{bookingId}
- Obtaining booking PDFs: GET api/booking/{bookingId}/pdf
-
CityController: Manages cities within the system with endpoints for:
- Creating cities: POST api/city
- Updating cities: PUT api/city/{id}
- Deleting cities: DELETE api/city/{id}
- Retrieving city details: GET api/city/{id}
- Retrieving cities with associated hotels: GET api/city/{id}/with-hotels
- Retrieving popular cities: GET api/city/popular-cities
-
HotelController: Provides operations related to hotels, including:
- Creating hotels: POST api/hotel
- Updating hotels: PUT api/hotel/{hotelId}
- Deleting hotels: DELETE api/hotel/{hotelId}
- Searching hotels: GET api/hotel/search
- Retrieving hotels with reviews: GET api/hotel/{hotelId}/with-reviews
- Adding guest reviews: POST api/hotel/{hotelId}/reviews
- Deleting guest reviews: DELETE api/hotel/{hotelId}/reviews/{reviewId}
- Retrieving featured deals: GET api/hotel/featured-deals
- Retrieving recent hotels: GET api/hotel/recent-hotels
-
PaymentController: Manages payment transactions with endpoints for:
- Creating payments: POST api/payment
- Retrieving payment details: GET api/payment/{paymentId}
- Updating payment statuses: PATCH api/payment/{paymentId}/status
-
RoomController: Handles room operations within hotels with endpoints for:
- Creating rooms: POST api/room/{hotelId}
- Updating rooms: PUT api/room/{hotelId}/{roomId}
- Deleting rooms: DELETE api/room/{hotelId}/{roomId}
- Retrieving room details: GET api/room/{hotelId}/{roomId}
- Searching rooms: GET api/room/search
2. Application Layer
The Application layer is responsible for managing the business logic and use cases of the system. It defines the service interfaces and their implementations, such as IUserService, IBookingService, ICityService, IHotelService, IGuestReviewService, IPaymentService, and IRoomService. These services handle operations related to users, bookings, cities, hotels, guest reviews, payments, and rooms. They perform various tasks, including processing requests, interacting with the Domain layer to apply business rules, and managing validation.
Within this layer, JWT token management is handled to ensure secure user authentication and session management. JWT tokens are generated and validated here, facilitating secure communication between the client and the server. Additionally, password encryption is managed in the Application layer. Passwords are hashed and verified using secure encryption algorithms to protect user credentials.
FluentValidation is also utilized in the Application layer for input validation. It ensures data integrity by validating incoming requests and enforcing business rules before data is processed by the Domain layer. This approach helps maintain consistent and reliable data across the system.
3. Domain Layer
The Domain layer includes the core business logic and domain entities. It defines the core models such as User, Booking, City, Hotel, Room, GuestReview, and Payment. This layer focuses on encapsulating the business rules and domain logic, independent of the Application and Infrastructure layers.
4. Infrastructure Layer
The Infrastructure layer manages data access and external services. It includes Entity Framework Core for ORM and data management, ensuring persistence of domain entities in the database.
5. Unit Testing Project
The Unit Testing project is crucial for ensuring the reliability and correctness of the Hotel Booking System. It includes tests for various components of the system, including services and data validations.
Security and Error Handling
The system implements role-based authorization using policies like AdminPolicy and CustomerPolicy, ensuring that only authorized users can access certain endpoints. Error handling is managed through middleware that captures and processes exceptions globally, providing consistent and user-friendly error responses.
Conclusion
The Hotel Booking System's architecture leverages Clean Architecture principles to create a well-structured, maintainable, and scalable backend system. By separating concerns into distinct layers and incorporating best practices like EF Core, FluentValidation, JWT authentication, and secure password handling, the system provides a robust foundation for managing hotel bookings efficiently.