How vuthientan/be_cdw works
Project type and purpose
• This is a monolithic Spring Boot REST API for a food-ordering/inventory system.
• It exposes CRUD endpoints for users, roles, permissions, menu items, ingredients, carts, orders, reviews, stock-in batches, etc.
• It uses JWT + cookie filters for auth and also supports GitHub OAuth2 login, plus email notifications (account activation, password reset, invoices).
File structure
• Top-level:
– pom.xml, mvnw wrappers → Maven-built Spring Boot app
– src/main/java/com/cdw/cdw:
• configuration → security, JWT decoding, OAuth2 handlers, filters, message bundles
• controller → REST controllers (Authentication, User, MenuItem, Order, Inventory, Cart, Review, etc.)
• service → business logic for each domain area + EmailService + JwtPasswordResetService
• repository → Spring Data JPA repositories + Specifications for filtering
• domain/entity → JPA entities
• domain/dto → request/response DTOs for each endpoint
• mapper → MapStruct-style mappers between entities and DTOs
• exception → global and application exceptions
• CdwApplication.java → main class
– src/main/resources:
• application.yaml → configuration (DB, mail, security)
• db/migration → Flyway migrations
• templates → HTML email templates
• messages_*.properties → i18n messages
• No frontend code; purely a backend service.
README
• (Empty) — rely on file structure for insights.
a. Client (browser or mobile app)
b. API Gateway / HTTP interface (Spring MVC Controllers)
c. Security Layer
– JwtFromCookieFilter, CustomJwtDecoder, JwtAuthenticationEntryPoint, OAuth2LoginSuccessHandler
d. Service Layer (AuthenticationService, UserService, OrderService, IngredientService, CartService, StockInService, ReviewService, EmailService, etc.)
e. Data Layer
– Spring Data Repositories + JPA Entities
– Flyway migrations → RDBMS (PostgreSQL/MySQL/etc.)
f. External Services
– GitHub OAuth2 provider
– SMTP server (for sending emails)
Relationships and interactions
• Client → Controllers (HTTP request)
– pre-filter: JwtFromCookieFilter extracts JWT from cookie
– SecurityConfig routes unauthenticated endpoints (login, password reset) and protects others
– Controllers delegate to Services
• Services apply business logic, call Repositories
• Repositories → Database
• OAuth2LoginSuccessHandler on successful GitHub login → issue local JWT
• EmailService → SMTP server
• All error flows → GlobalException handler
Architectural patterns and principles
• Layered (Controller → Service → Repository → Database)
• DTO mapping via mappers to decouple domain from API models
• Specifications pattern for flexible queries
• Externalized configuration (application.yaml, .env)
• Flyway for DB versioning
• Template engine for email content