This repository hosts the core Backend Service for the E-commerce Microservices system. It provides a robust RESTful API handling products, users, shopping carts, orders, and authentication using a modern tech stack.
- Authentication & Security:
- Stateless authentication via JWT (RS256 signing).
- Role-based access control (RBAC).
- Custom Security Filters and OAuth2 Resource Server implementation.
- Product Catalog:
- Complete CRUD for Products and Categories.
- Image hosting integration with Cloudinary.
- Review and Rating system.
- Shopping Logic:
- Persistent Shopping Cart management.
- Stock validation and management.
- Checkout process with
PaymentRequestintegration.
- Event-Driven Architecture:
- Asynchronous event handling using RabbitMQ (e.g.,
CommentAddedEvent,PaymentConcludedEvent). - Decoupled listeners for high scalability.
- Asynchronous event handling using RabbitMQ (e.g.,
- Database Management:
- Versioned database migrations using Flyway.
- Optimized PostgreSQL schema.
- Observability:
- Metrics exposure via Spring Actuator and Prometheus.
- Health checks and detailed application info.
- Language: Java 21
- Framework: Spring Boot 3.2.5
- Database: PostgreSQL
- Messaging: RabbitMQ
- Migration: Flyway
- Documentation: OpenAPI (Swagger UI)
- Build Tool: Gradle
- Containerization: Docker & Docker Compose
The application follows a clean layered architecture:
src/main/java/org/wesley/ecommerce/
├── application/ # Controllers, DTOs, Requests/Responses
├── config/ # Configuration classes (Security, RabbitMQ, Swagger, Cloudinary)
├── domain/ # Entities, Enums, Repositories, Custom Exceptions
├── service/ # Business Logic and Interfaces
└── utility/ # Helper classes
To run the application, you must configure the environment variables. Create a .env file in the root directory based on .env.example:
# Database
POSTGRES_HOST=db
POSTGRES_DB=ecommerce_db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your_password
# JWT
ISSUER=your_issuer_name
# Cloudinary (Image Hosting)
CLOUDINARY_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
# RabbitMQ
RABBITMQ_DEFAULT_USER=guest
RABBITMQ_DEFAULT_PASS=guest
SPRING_RABBITMQ_HOST=rabbitmq
SPRING_RABBITMQ_PORT=5672Note: Ensure you have the RSA keys (
private_key.pemandpublic_key.pem) located insrc/main/resources/certs/for JWT signing.
The easiest way to run the API along with the Database and Exporters is using Docker Compose.
-
Build and Start:
docker-compose up -d --build
-
Access the services:
- API:
http://localhost:8080/ecommerce/api - Swagger UI:
http://localhost:8080/ecommerce/api/docs/swagger-ui/index.html - Prometheus Metrics:
http://localhost:8080/ecommerce/api/actuator/prometheus
- API:
-
Prerequisites:
- JDK 21
- PostgreSQL running locally
- RabbitMQ running locally
-
Install Dependencies:
./gradlew clean build -x test -
Run the Application:
./gradlew bootRun --args='--spring.profiles.active=dev'
The API is fully documented using OpenAPI/Swagger. Once the application is running, you can access the interactive documentation at:
URL: /ecommerce/api/docs
- Fork the repository.
- Create a feature branch (
git checkout -b feature/NewEndpoint). - Commit your changes (
git commit -m 'Add new endpoint for X'). - Push to the branch (
git push origin feature/NewEndpoint). - Open a Pull Request.
This project is licensed under the MIT License.