How suryadeepkoduri/openshop works
Project Type and Purpose
• This is a single‐service, RESTful e-commerce backend API built with Spring Boot.
• Responsibilities: user authentication (JWT), product/category management, cart & order handling, admin endpoints, enhanced request logging via MDC.
High-Level Components
A. API Layer (Controllers)
• Exposes REST endpoints grouped by domain:
• Public: ProductController, CategoryController, CartController, OrderController, UserController
• Admin: AdminProductController, AdminCategoryController, AdminOrderController
• Auth: AuthController
• GlobalExceptionHandler sits alongside to catch and normalize errors.
B. Service Layer
• Business logic interfaces (e.g., ProductService, OrderService) and their implementations (ProductServiceImpl, etc.).
• AuthenticationService, JwtService for token management.
C. Data Layer
• Spring Data JPA repositories (ProductRepository, OrderRepository, etc.).
• Entities mapping to MySQL tables: Product, Category, Cart, Order, User, etc.
D. Cross-Cutting Concerns
• Security: SecurityConfig defines HTTP/SecurityFilterChain, JwtAuthenticationFilter enforces JWT.
• Configuration: ApplicationConfiguration, DataSeeder (initial data load), OpenApiConfig (Swagger).
• Logging: MdcFilter and MdcUtil integrate SLF4J/Logback’s MDC context.
• DTO/Mapping: Request/Response DTOs and MapStruct mappers (OrderMapper, EntityMapper).
External Systems
• MySQL database (primary persistence).
• Swagger UI (API documentation endpoint).
• Clients: Web/Mobile front end or third-party integrators calling the HTTP API.
Relationships and Data Flows
1. Client → HTTP Request → Spring Filter Chain (MDC filter → JWT filter)
2. Filter Chain → Controller → Service → Repository → MySQL
3. Repository returns Entities → Service applies business rules → Mapper transforms to DTO → Controller returns JSON
4. Swagger UI serves OpenAPI docs from OpenApiConfig
5. DataSeeder (on startup) populates baseline data into MySQL
Architectural Patterns & Principles
• Layered (AKA “Onion” or “Hexagonal”) architecture: clear separation between API, business logic, and persistence.
• Dependency inversion: controllers depend on service interfaces, services depend on repositories via Spring DI.
• Single Responsibility: each package (config, controller, service, repository, entity, dto, mapper, filter, security) has well-defined concerns.
• Cross-cutting handled through filters and global exception handlers.
Technologies & Frameworks to Annotate
• Spring Boot (core framework)
• Spring Security with JWT
• Spring Data JPA (ORM)
• MapStruct (DTO ↔ Entity mapping)
• Lombok (boilerplate reduction)
• Swagger/OpenAPI
• SLF4J/Logback + MDC
• MySQL
Final Checklist
• [ ] Components: Client, Filters/Security, Controllers, Services, Repositories, MySQL, Swagger UI