How pratikvmarathe/rbac-api-templete works
Project Type and Purpose
• This is a backend‐only, monolithic REST API built with Spring Boot (Java 17), designed as an RBAC (Role-Based Access Control) template.
• It exposes endpoints for user- and admin-level operations, secures them using JWT, and persists data in a relational database via Spring Data JPA.
High-Level Architectural Layers
• External Clients: any web/mobile client or API consumer.
• Edge/HTTP Layer: embedded Tomcat, CORS, and security filters.
• API Layer: Spring MVC controllers handling HTTP requests.
• Business Layer: service classes encapsulating domain logic.
• Data Layer: Spring Data repositories for CRUD on User and Token entities.
• Infrastructure: JWT utilities, validators, exception handlers.
• Persistence: relational database (e.g., PostgreSQL/MySQL).
Main Components
a. Clients
• Web/App/UI or third-party scripts invoking REST endpoints
b. API Gateway/Edge (Optional)
• CORS filter (CorsConfig)
• Security filter chain (JwtAuthenticationFilter, SecurityConfig)
c. Controllers
• UserController (user-level endpoints)
• AdminController (admin-level endpoints)
d. Services
• UserService
• UserTokenService
• CustomReactiveUserDetailsService (integrates with Spring Security)
e. Repositories
• UserRepository
• UserTokenModelRepository
• Projection interfaces (e.g., UserProfilePictureUrlProjection)
f. Utilities & Validators
• JwtUtil, SecretKeyUtil, PostalCodePatterns
• PhoneNumberValidator, PostalCodeValidator
• JwtReactiveAuthenticationManager
g. Database
• Tables for User, Role, UserTokenModel
h. Exception Handling
• TokenNotAvailableException
Relationships and Data Flows
• Flow through CORS & JWT filters → SecurityConfig establishes AuthenticationManager → JwtAuthenticationFilter validates tokens.
• After passing security, request → appropriate Controller.
• Controller delegates to Service layer (UserService / UserTokenService).
• Services call Repository interfaces → Database.
• Repositories return entities/projections → Services → Controllers → HTTP response → Clients.
• Exception flow: show TokenNotAvailableException thrown by Service/Filter and handled by a global exception handler (if any).
Architectural Patterns & Design Principles
• Layered (Onion/Clean) architecture: clearly separate presentation (controllers), business (services), and data (repositories).
• Use of Spring Security filter chain for authentication & authorization.
• Role-based access enforced in SecurityConfig and at controller method level.
• JWT stateless authentication—no server-side sessions.
• Validation via annotations & custom validators (e.g., @ValidPostalCode).
Detailed Component Breakdown (to include
• SopManagementSystemApplication (entry point)
• CorsConfig → applies CORS filters
• SecurityConfig → defines HTTP security rules, role mapping
• JwtAuthenticationFilter → intercepts requests, extracts & validates token
• JwtUtil & SecretKeyUtil → sign/verify JWT, manage secret keys
• Controllers (AdminController, UserController) → define REST endpoints
• Services → encapsulate business rules, token generation, user lookup
• CustomReactiveUserDetailsService & JwtReactiveAuthenticationManager → integrate with Spring Security for reactive flows
• Repositories → interface to database (CRUD, custom projections)
• Validators → enforce phone/postal code formats via annotations
• Exception classes → handle errors (e.g., missing token)