A production-style e-commerce backend built with Java 21 + Spring Boot. It covers the full purchase flow — registration, catalog browsing, cart, checkout, payment, and order fulfilment — with the operational concerns a real service needs: caching, rate limiting, database migrations, and containerised local infrastructure.
- Authentication & authorization — JWT-based login and registration, role-based access (
USER/ADMIN) via Spring Security - Catalog — products and categories with pagination, filtering, and Redis-backed caching
- Cart — add, update, and remove items with server-side price and stock validation
- Checkout & orders — order creation with an explicit state machine (
OrderStateTransition) so orders can never jump to an invalid status - Inventory — stock reservation and release, guarded by a dedicated
InventoryService - Payments — Xendit integration with a webhook endpoint that reconciles payment status back onto the order
- Shipping — pluggable shipping service with AWB tracking numbers (mock implementation included)
- Email — transactional email via SendGrid, wrapped in a retry policy
- Rate limiting — Resilience4j rate limiter on public endpoints
- Error handling — centralised exception handler returning consistent JSON error responses
- API docs — OpenAPI / Swagger UI generated from the controllers
| Layer | Technology |
|---|---|
| Language | Java 21 |
| Framework | Spring Boot 4, Spring Security, Spring Data JPA |
| Database | PostgreSQL, Flyway migrations |
| Cache | Redis |
| Auth | JJWT |
| Resilience | Resilience4j (rate limiter, retry) |
| Integrations | Xendit (payments), SendGrid (email) |
| Docs | springdoc-openapi |
| Testing | JUnit, Spring Security Test, MockMvc |
| Quality | SonarQube |
| Infra | Docker, Docker Compose |
controller -> service (interface + impl) -> repository -> entity
|
+-- model (request/response DTOs) + mapper
+-- config (security, jwt, redis, swagger, rate limit, integrations)
+-- common/errors (typed exceptions -> GenericExceptionHandler)
Every service is defined as an interface with a separate implementation, so integrations (payments, shipping, email) can be swapped or mocked in tests without touching the controllers.
Prerequisites: JDK 21, Docker, Maven (or the bundled mvnw)
# 1. Clone
git clone https://github.com/native-99/e-commerce.git
cd e-commerce
# 2. Start PostgreSQL, Redis, and SonarQube
docker compose up -d
# 3. Configure environment
# In src/main/resources/application.properties set:
# datasource url / username / password, redis host,
# jwt secret, xendit api key, sendgrid api key
# 4. Run (Flyway applies migrations on startup)
./mvnw spring-boot:runAPI docs: http://localhost:8080/swagger-ui.html
./mvnw test # run testsSchema is versioned with Flyway (src/main/resources/db/migration):
| Version | Change |
|---|---|
| V1 | products & categories |
| V2 | users & user_roles |
| V3 | roles + default role seed |
| V4 | user ↔ product relations |
| V5 | carts & cart_items |
| V6 | orders, order_items, user_addresses |
| V7 | AWB tracking number on orders |
| V8 | Xendit payment columns on orders |
A load-test/ suite is included to measure endpoint behaviour under concurrent traffic and to verify the rate limiter.
- Broader integration test coverage
- CI pipeline running tests + SonarQube on every push
- React frontend consuming this API