How alivrick/web_backend_booking_hotel works
Main Components
• Backend API (Spring Boot): This is organized using a layered approach with controllers, services, repositories, models (entities), DTOs, and security configurations. It implements key functionalities such as hotel searching, booking management, real‑time room availability, payment integration, and authentication.
• Frontends (React + Vite): Although not part of the file tree, the README indicates three distinct UI modules – Admin, Rental, and User. Each interacts with the backend through designated REST APIs.
• Database: The backend interacts with a relational database (PostgreSQL/MySQL) to persist all data (users, hotels, bookings, payment records, etc.).
• External Services:
⁃ JWT & Authentication services (including token management, email confirmation, password recovery).
⁃ Payment Gateway (indicated by the VnPayService) for online deposits and full payments.
⁃ Email services for notifications (see EmailService usage).
Relationships and Interactions
• Frontend to Backend:
• The three separate frontends initiate RESTful API calls to the backend’s endpoints (e.g., AuthController, BookingController, HotelController).
• Authentication data flows through JWT (secured by filters such as AuthTokenFilter and handled in JwtUtils).
• Backend Internal Flow:
• Controllers receive external requests and delegate business logic to corresponding Services (BookingService, HotelService, UserService, etc.).
• Services perform operations and interact with the database using Repositories (like BookingRepository, HotelRepository, etc.).
• The Security Layer (WebSecurityConfig, JwtAuthEntryPoint, CorsConfig) governs access, while exceptions and DTOs (e.g., PaymentResDTO) facilitate error handling and data transfer.
• External Integrations:
• Payment integration is handled by the VnPayService where the system decides between deposit and full payment.
• Email confirmations and password resets are processed using an EmailService.
Architectural Patterns and Design Principles
• MVC Pattern: The backend naturally segments into controllers, services (business logic), and models/repositories (data persistence).
• Layered Architecture: Separation between presentation (controllers), business logic (services), and data access (repositories).
• Security Best Practices: JWT authentication along with multi-role access control.
• Extensibility: The use of DTOs and clearly defined service interfaces (IUserService, IHotelService, etc.) prepares the system for future enhancements.