How byte2code/hotel-management-api works
1. This is a Spring Boot 3.3 / Java 17 backend named HotelDemoApplication, built with Maven and organized as a classic layered application: API controllers, service logic, JPA repositories, domain models, DTOs, and security/configuration.
2. The main business boundary is the hotel management domain. Core entities are Hotel, Room, User, and Booking, with enums for lifecycle/state such as RoomStatus and BookingStatus. These model the inventory and reservation workflow rather than any UI-specific behavior.
3. The API layer is split by resource: HotelController, RoomController, BookingController, UserController, and LoginController. Controllers handle HTTP request/response concerns and delegate all business rules to services.
4. The service layer contains the actual application logic: HotelService, RoomService, BookingService, and UserService. This is where validation, availability checks, booking confirmation/rejection, and user registration logic belong. The readme indicates booking creation includes date-range availability validation and returns a structured booking response.
5. Persistence is handled through Spring Data JPA repositories: HotelRepository, RoomRepository, BookingRepository, and UserRepository. These form the boundary to MySQL, which is the system of record for hotels, rooms, users, and bookings.
6. The DTO layer separates request/response payloads from entity persistence models. HotelRequest, RoomRequest, BookingRequest, UserRequest, and BookingResponse define the API contract and keep controllers from exposing entity internals directly.
7. Security is a major subsystem. HotelSecurityConfig and the readme show the app supports JWT resource-server style access, OAuth2 login, and method-level authorization with @PreAuthorize. Access control is role-based, with different permissions for normal users, authenticated hotel users, and admin-style operations.
8. External identity providers are part of the runtime architecture. The app integrates with Keycloak for JWT/OIDC-backed authentication and Google for OAuth2 login. The readme also notes that Google-authenticated users are mapped to local roles stored in the MySQL user table, so authorization depends on both external identity and local application data.
9. There is also a browser-facing view boundary. LoginController and src/main/resources/templates/login.html provide a Thymeleaf-based /login page for interactive sign-in, while the rest of the system is a REST API.
10. The main data flows are: user registration into the User table, hotel and room CRUD through service/repository layers, and booking creation that reads hotel/room/user records, validates availability, then persists a booking with a status outcome such as confirmed or rejected. Booking queries can be scoped by booking id, user id, or hotel id.
11. The endpoint surface is segmented by concern: /user/* for user management, /hotel/* for hotel operations, /hotel/rooms/* for room inventory, and /hotel/bookings/* for reservation workflows. Security rules are applied at endpoint and method level, not just globally.
12. Testing is focused on the service boundary. The repository includes unit/integration-style tests for BookingService and RoomService, plus a basic application bootstrap test, which suggests the business rules are expected to live primarily in the service layer rather than controllers.
13. For an architecture diagram, the clearest boundaries are: external actors and identity providers at the top, REST controllers as the entry layer, service layer as business orchestration, JPA repositories as persistence access, MySQL as the data store, and Thymeleaf as the only server-rendered UI component.
Main entry points: BookingService.java Booking service · HotelSecurityConfig.java Security config · RoomService.java Room service · HotelRepository.java Hotel repo
Components 21
Entry
Application bootstrap and startup boundary
- Hotel Demo · Main application bootstrap
src/main/java/com/cn/hotelDemo/HotelDemoApplication.java
API
HTTP controllers and request handling
- Hotels · Hotel management endpoints
src/main/java/com/cn/hotelDemo/controller/HotelController.java - Rooms · Room inventory endpoints
src/main/java/com/cn/hotelDemo/controller/RoomController.java - Bookings · Reservation endpoints
src/main/java/com/cn/hotelDemo/controller/BookingController.java - Users · User management endpoints
src/main/java/com/cn/hotelDemo/controller/UserController.java - Login · Serves the login page
src/main/java/com/cn/hotelDemo/controller/LoginController.java
Business
Domain services and orchestration
- Hotel service · Hotel CRUD and coordination
src/main/java/com/cn/hotelDemo/service/HotelService.java - Room service · Room inventory logic
src/main/java/com/cn/hotelDemo/service/RoomService.java - Booking service · Availability checks and booking outcomes
src/main/java/com/cn/hotelDemo/service/BookingService.java - User service · Registration and user lookup
src/main/java/com/cn/hotelDemo/service/UserService.java - Booking tests · Tests booking workflow behavior
src/test/java/com/cn/hotelDemo/service/BookingServiceTest.java - Room tests · Tests room service behavior
src/test/java/com/cn/hotelDemo/service/RoomServiceTest.java
Data
Persistence models and repositories
- Hotel repo · Hotel persistence access
src/main/java/com/cn/hotelDemo/repository/HotelRepository.java - Room repo · Room persistence access
src/main/java/com/cn/hotelDemo/repository/RoomRepository.java - Booking repo · Booking persistence access
src/main/java/com/cn/hotelDemo/repository/BookingRepository.java - User repo · User persistence access
src/main/java/com/cn/hotelDemo/repository/UserRepository.java
Security
Authentication and authorization
- Security config · JWT, OAuth2, and method security rules
src/main/java/com/cn/hotelDemo/config/HotelSecurityConfig.java
External
Identity providers and database
- Keycloak · JWT and OIDC authentication source
- Google · External OAuth2 login provider
- MySQL · System of record for hotels, rooms, users, and bookings
Connections 23
- Hotel Demo → Security config: loads · Application starts with security configuration
- Security config → Keycloak: trusts · Validates JWT/OIDC tokens from Keycloak
- Security config → Google: enables · Supports OAuth2 login via Google
- Security config → Hotels: protects · Applies endpoint and method authorization
- Security config → Login: protects · Controls access to interactive login flow
- Login → login.html: renders · Serves the Thymeleaf login page
- Hotels → Hotel service: delegates · Controller passes hotel requests to service
- Rooms → Room service: delegates · Controller passes room requests to service
- Bookings → Booking service: delegates · Controller passes booking requests to service
- Users → User service: delegates · Controller passes user requests to service
- Booking service → Hotel repo: reads · Loads hotel data for booking decisions
- Booking service → Room repo: reads · Checks room availability and inventory
- Booking service → User repo: reads · Verifies user data and ownership
- Booking service → Booking repo: writes · Persists booking results and status
- Hotel service → Hotel repo: uses · Persists and retrieves hotels
- Room service → Room repo: uses · Persists and retrieves rooms
- User service → User repo: uses · Persists and retrieves users
- Hotel repo → MySQL: stores in · Hotel records live in MySQL
- Room repo → MySQL: stores in · Room records live in MySQL
- Booking repo → MySQL: stores in · Booking records live in MySQL
- User repo → MySQL: stores in · User records live in MySQL
- Booking tests → Booking service: verifies · Exercises booking workflow rules
- Room tests → Room service: verifies · Exercises room service logic