How arunsri7/book-my-room works
Project Type and Purpose
• This is a backend microservice (no bundled frontend) implementing a RESTful booking system (“Book My Room”) for multi-tenant resource management.
• Built with Spring Boot (Java 17), MongoDB, JWT-based auth, layered MVC architecture.
• Exposes REST endpoints (defined in controllers) for company, user, resource, and booking management.
File-Structure Analysis
• src/main/java/com/bookmyroom
• config: SecurityConfig.java (Spring Security + JWT filter)
• controller: REST controllers (Auth, Company, User, Resource, Booking)
• service + service/impl: business logic layer
• repository: MongoRepository interfaces
• model: domain entities (Company, User, Resource, Booking, etc.)
• security: CustomUserDetails, JwtService, JwtAuthenticationFilter
• exception: custom exceptions + global handler
• src/main/resources/application.yml: configuration (DB URI, JWT secrets, ports)
• Dockerfile & docker-compose.yml: containerization (app + MongoDB)
• Postman collection for API testing
Key Components
a. Clients
• API clients (e.g., Postman, future frontend or mobile apps)
b. API Layer
• Spring MVC Controllers
c. Security Layer
• JwtAuthenticationFilter → JwtService → CustomUserDetailsService
• SecurityConfig defines filter chain, endpoints’ access rules
d. Business Logic Layer
• Service interfaces and implementations (BookingServiceImpl, CompanyServiceImpl, etc.)
• Applies multi-tenant checks & role-based access
e. Data Access Layer
• Spring Data MongoDB Repositories
f. Database
• MongoDB (one database, multi-tenant via companyId)
g. Infrastructure
• Docker + Docker-Compose orchestrating the Spring Boot app and MongoDB
Component Interactions and Data Flow
1. Client → HTTP Request → Controller (e.g., /api/bookings)
2. Controller → SecurityConfig ensures JWT filter runs
3. JwtAuthenticationFilter validates token via JwtService → loads user via CustomUserDetailsService
4. Authenticated request enters controller method → calls appropriate Service
5. Service layer → applies business rules + multi-tenant isolation → calls Repository
6. Repository → executes MongoDB queries → returns domain objects
7. Service → transforms/validates results → Controller → serializes response to JSON → Client
8. For login: AuthController issues JWT token based on credentials
Architectural Patterns & Principles
• Layered (Controller → Service → Repository)
• MVC-style separation
• Stateless JWT authentication
• Multi-tenant isolation enforced at service/repository layer
• Exception handling via GlobalExceptionHandler (cross-cutting concern)