Skip to content

kimhieu-dev/e-commerce-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

219 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

e-commerce-backend

Backend for E-commerce System - Built with Spring Boot & MySQL. Focuses on Order Processing, Inventory Integrity, and Async Tracking Logs.

Java Spring Boot MySQL License: MIT


Table of Contents


Overview

Tech Stack

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

Features

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

System Architecture

Client (Postman / Frontend)
        │
        ▼
  Controller Layer   
        │
        ▼
  Service Layer      
        │
        ▼
  Repository Layer   
        │
        ▼
     MySQL DB

Follows a standard 3-layer architecture (Controller → Service → Repository) for separation of concerns.


Database Design

Core tables: user, role, product, category, order, order_item, cart, cart_item

ER Diagram: copy diagram from docs location and paste to drawdb.app


API Endpoints

Base URL: http://localhost:8080/api/v1

Full docs available at: http://localhost:8080/swagger-ui.html

Getting Started

Prerequisites

  • Java 17+
  • MySQL 8.0+
  • Maven 3.8+

Steps

# 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:run

The server starts at http://localhost:8080


Environment Variables

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=8080

Note: Never commit .env to Git. It is listed in .gitignore.


What I Learned

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

Roadmap

  • Add Redis for caching product list
  • Integrate VNPay / Stripe for payment
  • Write integration tests
  • Dockerize the application
  • Deploy to Railway / Render

Contact

[Nguyen Kim Hieu]
📧 nguyenkimhieu.dev@gmail.com 🔗 LinkedIn
🐙 GitHub


About

Backend for E-commerce System - Built with Spring Boot & MySQL. Focuses on Order Management, Inventory Integrity, and Async Tracking Logs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages