This project serves as a comprehensive blueprint for building modern, scalable, and maintainable backend systems. It's a fully functional e-commerce platform MVP meticulously designed with a modular monolith architecture. This pragmatic approach offers the development velocity of a traditional monolith while laying a solid foundation for a future-proof, seamless evolution into a microservices-based system.
The platform implements the entire customer lifecycle, from user authentication and product browsing to order processing and payment simulation, all while ensuring data integrity and high performance through a thoughtful technology stack.
- Event-Driven Core: Modules communicate asynchronously via an internal Spring
ApplicationEventBus. This decouples domains (e.g.,Orderservice doesn't know aboutInventorystock logic) and eliminates runtime dependencies. - Optimized Data Persistence: A strategic use of PostgreSQL for transactional, relational data (users, orders) and Redis for high-throughput, ephemeral data (shopping carts), ensuring both data integrity and performance.
- Robust Security Model: End-to-end security with Spring Security, featuring JWT-based authentication and role-based authorization (
USER/ADMIN) to protect sensitive endpoints. - Production-Grade Testing Strategy: A multi-layered testing approach ensures reliability:
- Unit Tests (Mockito) for isolated business logic.
- Integration Tests (MockMvc) for the API layer.
- Data-Layer Tests (Testcontainers) for true-to-production database interactions.
- Full Context Integration Tests to verify the event-driven flows across modules.
- Automated & Reliable Development Pipeline: A complete CI/CD workflow using GitHub Actions automatically builds the project, runs the entire test suite, and provides immediate feedback, ensuring that the main branch is always stable.
- Database Lifecycle Management: Schema changes are managed, versioned, and applied automatically and safely using Flyway.
| Category | Technology / Library | Purpose |
|---|---|---|
| Core Framework | Java 21, Spring Boot 3.5 | Foundation for the entire application. |
| Data & Persistence | Spring Data JPA, Hibernate, PostgreSQL | Relational data storage and ORM. |
| In-Memory & Cache | Spring Data Redis, Redis | High-performance storage for user carts. |
| Security | Spring Security, JSON Web Tokens (jjwt) | Authentication, authorization, and securing API endpoints. |
| Database Mgmt | Flyway | Version-controlled database migrations. |
| API & Web | Spring Web (MVC), RESTful Principles | Exposing the application's functionality via a clean API. |
| DevOps & CI/CD | Docker, Docker Compose, GitHub Actions | Containerization, local environment setup, and automated CI pipeline. |
| Testing | JUnit 5, Mockito, Testcontainers, MockMvc | Ensuring code quality and reliability at all levels. |
| Utilities | Lombok, MapStruct | Reducing boilerplate code for entities and DTO mapping. |
- Java 21 (or higher)
- Docker & Docker Compose
- An API client like Postman or
curl.
-
Clone the repository:
git clone https://github.com/iwkms99/E-commerceMicroservicesPlatform.git cd E-commerceMicroservicesPlatform -
Launch infrastructure: This single command starts PostgreSQL and Redis containers with all the necessary configurations.
docker-compose up -d
-
Run the application: You can run the app from your favorite IDE by executing the
mainmethod inEcommerceApplication.javaor via the Gradle wrapper../gradlew bootRun
The server will start on
http://localhost:8080.
-
Register a user:
curl -X POST http://localhost:8080/api/v1/users/register \ -H "Content-Type: application/json" \ -d '{"email":"[email protected]", "password":"password123", "firstName":"Test", "lastName":"User"}'
-
Log in to get a token:
TOKEN=$(curl -s -X POST http://localhost:8080/api/v1/auth/login \ -H "Content-Type: application/json" \ -d '{"email":"[email protected]", "password":"password123"}' | jq -r .token) echo "Your JWT is: $TOKEN"
(Requires
jqto be installed. Otherwise, copy the token manually from the response.) -
Get your user details using the token:
curl -X GET http://localhost:8080/api/v1/users/me \ -H "Authorization: Bearer $TOKEN"
This project provides a solid foundation. Here are some potential next steps to evolve it further:
- Implement Compensating Transactions (Saga Pattern): Enhance reliability by creating compensating actions for failed events (e.g., automatically refunding a payment if stock reservation fails).
- Extract First Microservice: Choose a module (e.g.,
UserorCatalog) and extract it into a standalone Spring Boot service, replacing internal calls with REST or message queue communication. - Introduce a Message Broker: Replace the internal Spring Event Bus with a robust message broker like RabbitMQ or Kafka to prepare for a distributed environment.
- Add Advanced Catalog Features: Implement full-text search with Elasticsearch and add filtering/pagination.
- Containerize the Application: Write a
Dockerfilefor the application itself and orchestrate the entire stack with a production-readydocker-compose.yml.
This project was developed as a deep dive into modern software architecture and best practices. Feel free to explore, fork, and use it as a reference for your own work.