This is the backend for the E-Commerce, designed to handle secure data persistence, user authentication, and product management. It serves as the RESTful API for the Flutter Mobile Client.
- Language: Java 25
- Framework: Spring Boot 4.0.5 (Spring Web, Spring Data JPA)
- Security: Spring Security 6 with JWT (JSON Web Tokens)
- Database: Microsoft SQL Server
- Build Tool: Maven
The project follows a strict separation of concerns to ensure scalability and maintainability:
- Controller Layer: REST Endpoints and Request Mapping.
- Service Layer: Business logic, password encoding, and JWT generation.
- Repository Layer: Data persistence using Spring Data JPA.
- Security Layer: Custom JWT Filters and Role-Based Access Control (RBAC).
- JWT Stateless Auth: Custom
JwtAuthenticationFilterthat intercepts requests to validate Bearer tokens. - Role-Based Access (RBAC): Configured
SecurityConfigto restrict product/category management toADMINusers while allowingUSERaccess for browsing. - Global Exception Handling: Implemented
@RestControllerAdviceto provide clean, consistent JSON error responses for database conflicts (e.g., duplicate usernames) and runtime errors.
- Multi-Part File Support: Handles image uploads for products using
MultipartFile. - Static Resource Mapping: A custom
WebMvcConfigurermaps internal storage folders (user-photos/) to public URLs (/uploads/**) for consumption by the Flutter app.
The system manages relationships between Users, Products, and Categories with a focus on data integrity:
- Many-to-One Relationships: Products are linked to Categories.
- Transactional Integrity: Uses
@Transactionalto safely handle category deletions while preserving linked product data.
| Method | Endpoint | Access | Description |
|---|---|---|---|
POST |
/api/auth/register |
Public | Register new user (Default: ROLE_USER) |
POST |
/api/auth/login |
Public | Authenticate and receive JWT |
GET |
/api/products |
Public | View all products |
POST |
/api/products |
Admin | Add new product with image upload |
DELETE |
/api/categories/{id} |
Admin | Safely remove category (cascades to products) |
- Clone the repo:
git clone [https://github.com/Doeun-Panha/e-commerce-spring.git](https://github.com/Doeun-Panha/e-commerce-spring.git)