How huynhthinhphat/website_electronics_sale works
Project type and purpose
• This is a Spring-Boot backed monolithic REST API (“tip_b18_electronics-sales-be”) for an electronics e-commerce platform.
• The service exposes endpoints to manage accounts, authentication, products, categories, brands, carts, orders, reviews, images, statistics, payment (PayOS), email, and Excel exports.
File structure
• Top-level: Dockerfile, Maven wrapper, pom.xml, application.properties
• src/main/java/com/tip/b18/electronicsales:
• configurations (Cloudinary, CORS, Security, Redis, Swagger, Password)
• controllers (REST endpoints)
• dto (data transfer objects)
• entities (JPA domain models + base classes)
• repositories (Spring Data JPA interfaces)
• mappers (DTO↔entity mapping)
• services + impls (business logic)
• filters (JWT authentication)
• exceptions (custom exceptions & global handler)
• utils & validators
• src/main/resources/application.properties holds DB, Redis, Cloudinary, mail, payment configs.
• Dockerfile packages the Spring Boot jar into a container.
Key architectural insights from the readme/structure
• It uses layered MVC (Controller → Service → Repository → RDBMS)
• JWT-based stateless auth via a custom filter + Spring Security
• Redis for caching (or OTP/session storage)
• External integrations: Cloudinary (image storage), SMTP/email, PayOS payment gateway, Google OAuth
• Swagger for API docs
Main components & relationships
a. Internal components (monolith):
• API Gateway / Inbound HTTP (Spring Boot embedded Tomcat)
• Security Layer (CorsFilter, JwtAuthenticationFilter, SecurityConfig)
• Controller Layer (AccountController, ProductController, OrderController, etc.)
• Service Layer (AccountServiceImpl, ProductServiceImpl, PayOSServiceImpl, EmailServiceImpl, ExcelServiceImpl, etc.)
• Data Access Layer (Spring Data Repositories)
• Domain Model (JPA Entities)
• DTO Layer + Mappers
• Utility modules (Utils, Validators)
b. External components:
• Relational Database (MySQL/PostgreSQL)
• Redis Cache
• Cloudinary (image hosting)
• SMTP Email Server
• PayOS Payment Gateway
• Google OAuth Service
• Swagger UI (for docs)
c. Data flows & interactions:
1. Client → HTTP(S) → Security filter → Controller
2. Controller → Service (business logic)
3. Service ↔ Repository → RDBMS
4. Service ↔ Redis (caching, OTP)
5. Service → External APIs (Cloudinary, PayOS, Email, Google OAuth)
6. Controllers return DTOs
Architectural patterns & design principles
• Layered architecture (Separation of concerns)
• DTO mapping using Mapper classes for decoupling API model from persistence model
• Exception handling via a GlobalExceptionHandler
• Configuration via Spring’s @Configuration classes
• Stateless JWT authentication filter
• Use of interfaces + impls for easy testing and swapping implementations
Capturing essential elements
• Don’t omit the Security/Filter chain and DTO↔Entity mapping step
• Cross-cutting concerns: Configuration classes (Swagger, CORS), Global exception handling, Utilities