Backend for E-commerce System - Built with Spring Boot & MySQL. Focuses on Order Processing, Inventory Integrity, and Async Tracking Logs.
- Overview
- Tech Stack
- Features
- System Architecture
- Database Design
- API Endpoints
- Getting Started
- Environment Variables
- Project Structure
- What I Learned
- Roadmap
- Contact
| Layer | Technology |
|---|---|
| Language | Java 21 |
| Framework | Spring Boot 4.0.5 |
| Security | Spring Security |
| Database | MySQL 9.6.0 |
| ORM | Spring Data JPA / Hibernate |
| Build Tool | Maven |
| Documentation | Swagger |
| Testing | JUnit 5, Mockito |
| Others | Lombok, MapStruct |
Authentication & Authorization
- Register / Login
- Role-based access (ADMIN, USER)
Product Management
- CRUD for products and categories
- Search, filter by category/price
- Pagination & sorting
Order Management
- Add to cart, update quantity, remove item
- Place order, view order history
- Order status flow:
PENDING → CONFIRMED → SHIPPED → DELIVERED
Client (Postman / Frontend)
│
▼
Controller Layer
│
▼
Service Layer
│
▼
Repository Layer
│
▼
MySQL DB
Follows a standard 3-layer architecture (Controller → Service → Repository) for separation of concerns.
Core tables: user, role, product, category, order, order_item, cart, cart_item
ER Diagram: copy diagram from docs location and paste to drawdb.app
Base URL: http://localhost:8080/api/v1
Full docs available at: http://localhost:8080/swagger-ui.html
- Java 17+
- MySQL 8.0+
- Maven 3.8+
# 1. Clone the repo
git clone https://github.com/kimhieu-dev/e-commerce-backend.git
cd ecommerce-springboot
# 2. Create the database
mysql -u root -p
CREATE DATABASE ecommerce_db;
# 3. Configure environment variables
cp .env.example .env
# Edit .env with your DB credentials and JWT secret
# 4. Run the application
mvn spring-boot:runThe server starts at http://localhost:8080
Create a .env file in the root directory (see .env.example):
DB_HOST=localhost
DB_PORT=3306
DB_NAME=ecommerce_db
DB_USERNAME=root
DB_PASSWORD=your_password
JWT_SECRET=your_jwt_secret_key_here
JWT_EXPIRATION=86400000
SERVER_PORT=8080Note: Never commit
.envto Git. It is listed in.gitignore.
This project helped me practice:
- Designing RESTful APIs following naming conventions
- Implementing JWT authentication with Spring Security
- Using Spring Data JPA with pagination and custom
@Query - Handling exceptions globally with
@RestControllerAdvice - Writing unit tests with JUnit 5 and Mockito
- Structuring a Spring Boot project with layered architecture
- Add Redis for caching product list
- Integrate VNPay / Stripe for payment
- Write integration tests
- Dockerize the application
- Deploy to Railway / Render
[Nguyen Kim Hieu]
📧 nguyenkimhieu.dev@gmail.com
🔗 LinkedIn
🐙 GitHub