SShop is a Spring Boot REST API for an eCommerce system. It provides authentication, user management, product catalog management, categories, cart operations, order processing, image handling, and PayOS payment integration.
- Key Features
- Tech Stack
- System Requirements
- Installation & Setup
- Security Configuration
- API Documentation
- Project Structure
- Database
- Testing
- JWT authentication with access and refresh tokens
- Redis-backed access token blacklist for logout and password changes
- Role-based access control with
User,Admin, andManager - Protected endpoints with Spring Security
- Account lock support
- User registration and login
- Logout with access-token invalidation
- Change password for the authenticated user
- Forgot password and reset password flows backed by Redis reset tokens and SMTP email delivery
- Current profile retrieval
- Admin user creation and update
- Role update, lock, and unlock actions
- Product CRUD operations
- Product filtering by brand ID, category ID, product name full-text search, and price range
- Product writes reference existing brand and category records by ID
- Brand separation from product rows for safer catalog growth
- Product inventory tracking
- Category CRUD operations
- Category lookup by ID or name
- Pagination support for category listing
- Brand CRUD operations
- Brand lookup by ID or name
- Pagination support for brand listing
- Add, update, and remove cart items
- Cart item update/remove uses
cartItemIdsemantics on/api/v1/cart/items/{itemId} - Retrieve current cart and total amount
- Place orders from the current cart
- Track current user's order history
- Cancel the current user's own order when the current status allows transition to
CANCELED - Update order status for admin and manager roles
- Upload multiple product images
- Download stored images
- Update or delete existing images
- Create PayOS checkout links
- Receive PayOS webhook callbacks
- Mark a payment as canceled from the frontend when the user exits the PayOS flow
- Recreate a fresh PayOS checkout link after a canceled payment instead of reusing an old processed link
- Spring Boot 3.5.6
- Spring Security
- Spring Data JPA
- Spring Validation
- MySQL 8.0+
- Hibernate
- Flyway
- springdoc OpenAPI
- Swagger UI
- Lombok
- MapStruct
- Maven Wrapper
- Java 17 or higher
- MySQL 8.0+
- Maven 3.6+ or the included Maven Wrapper
git clone https://github.com/sangtn13/spring-ecommerce-api.git
cd spring-ecommerce-apiCopy src/main/resources/application.properties.template to src/main/resources/application.properties.
Update the values in src/main/resources/application.properties:
server.port=5050
spring.datasource.url=jdbc:mysql://localhost:3306/your_database_name?connectionTimeZone=Asia/Ho_Chi_Minh
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.data.redis.host=localhost
spring.data.redis.port=6379
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=YOUR_SMTP_USERNAME
spring.mail.password=YOUR_SMTP_PASSWORD_OR_APP_PASSWORD
api.prefix=/api/v1
sshop.app.jwtSecret=PLEASE_GENERATE_YOUR_OWN_JWT_SECRET_KEY_HERE
sshop.app.jwtExpirationMs=3600000
sshop.app.refreshTokenExpirationMs=604800000
sshop.app.passwordResetTokenExpirationMs=900000
sshop.app.resetPasswordBaseUrl=http://localhost:3000/reset-password
sshop.mail.fromName=SShop
sshop.mail.fromAddress=YOUR_SMTP_USERNAME
sshop.mail.supportEmail=support@example.com
sshop.seed.user.password=
sshop.seed.admin.password=
payos.client-id=
payos.api-key=
payos.checksum-key=
payos.return-url-base=
payos.cancel-url-base=Example:
CREATE DATABASE sshop_db;Then point spring.datasource.url to that database.
Seed accounts are created only if you provide values for:
sshop.seed.user.passwordsshop.seed.admin.password
If configured, the application can create:
admin@gmail.comwith roleAdminuser1@gmail.comtouser5@gmail.comwith roleUser
.\mvnw.cmd spring-boot:run.\mvnw.cmd clean install
java -jar target/sshop-0.0.1-SNAPSHOT.jarThe application runs by default at:
http://localhost:5050
The repository includes docker-compose.yaml for:
- MySQL
- Redis
- SonarQube
- PostgreSQL for SonarQube
Before running Docker Compose, copy .env.example to .env and update the values used by Compose.
If the Spring Boot app runs on your machine while Redis runs in Docker, keep:
spring.data.redis.host=localhost
spring.data.redis.port=6379If the app later runs in Docker on the same Compose network, set:
REDIS_HOST=redis
REDIS_PORT=6379
For password reset email, fill these placeholders in src/main/resources/application.properties:
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your-smtp-username
MAIL_PASSWORD=your-smtp-password-or-app-password
MAIL_FROM_NAME=SShop
MAIL_FROM_ADDRESS=your-sender-address
MAIL_SUPPORT_EMAIL=support@example.com
RESET_PASSWORD_BASE_URL=http://localhost:3000/reset-password
RESET_PASSWORD_BASE_URL should point to your frontend page that reads the token query parameter and lets the user submit a new password.
/api/v1/auth/login/api/v1/auth/register/api/v1/auth/refresh/api/v1/auth/forgot-password/api/v1/auth/reset-password/api/v1/products/**/api/v1/categories/**/api/v1/brands/**/api/v1/payments/payos-webhook
/api/v1/auth/logout/api/v1/auth/change-password/api/v1/users/**/api/v1/orders/**/api/v1/cart/api/v1/cart/**/api/v1/images/**/api/v1/payments/orders/**
Adminmanages usersAdminandManagermanage products, categories, images, and order status updates
- API reference:
FRONTEND_API.md - Swagger UI:
http://localhost:5050/swagger-ui.html - OpenAPI docs:
http://localhost:5050/api-docs
src/
βββ main/
β βββ java/com/ecommerce/sshop/
β β βββ controller/ # REST controllers
β β βββ service/ # Business logic
β β βββ repository/ # Data access layer
β β βββ model/ # Entities
β β βββ dto/ # Response/data transfer models
β β βββ request/ # Request payload models
β β βββ response/ # Common response wrappers
β β βββ exception/ # Exception handling
β β βββ security/ # Security configuration
β β βββ enums/ # Enums
β β βββ data/ # Data initialization
β β βββ SshopApplication.java
β βββ resources/
β βββ application.properties.template
β βββ db/migration/
βββ test/
- users / roles: authentication and authorization
- brands / products / categories / images: product catalog
- carts / cart_items: shopping cart state
- orders / order_items / payments: checkout and payment lifecycle
- Flyway migrations are stored in
src/main/resources/db/migration - JPA timezone is configured for
Asia/Ho_Chi_Minh
Run tests with:
.\mvnw.cmd test