This repository contains the Reviews & Ratings Service for the E-commerce ecosystem. It is a specialized microservice built to handle high-volume user feedback, comments, and interactions (likes/dislikes) using a non-relational database for scalability and flexibility.
- Review Management: Users can create, update, and list reviews for products.
- Interaction System: Support for complex user interactions:
- Comments: Nested discussions on specific reviews.
- Reactions: Like and Dislike functionality for both Reviews and Comments.
- Aggregations: Efficient calculation of product rating averages and summaries using MongoDB Aggregation Framework.
- Event-Driven Updates: Utilizes RabbitMQ to handle reaction events asynchronously (e.g., updating counters when a review is liked).
- Reactive Security: JWT-based stateless authentication.
- Language: Java 21
- Framework: Spring Boot 3.5.3
- Database: MongoDB (NoSQL)
- Messaging: RabbitMQ
- Documentation: OpenAPI (Swagger UI)
- Build Tool: Gradle
- Observability: Prometheus & Micrometer
This service follows a Hexagonal/Clean Architecture approach with a strong focus on asynchronous processing.
src/main/java/com/example/productsreview/
├── api/ # REST Controllers (Entry points)
├── domain/ # Entities (Review, Comment) and Business Logic
├── listener/ # RabbitMQ Listeners (Event handlers)
├── repository/ # MongoDB Data Access Layer
└── service/ # Business Use Cases
The service relies on RabbitMQ to decouple high-frequency interactions.
- Listeners:
ReviewReactionListener,CommentReactionListener. - Events:
ReviewLikedEvent,CommentAddedEvent,ProductRatingUpdatedEvent.
Create a .env file in the root directory. You can use .env.example as a template:
# Authentication
ISSUER=your_auth_issuer_url
# MongoDB
MONGO_INITDB_ROOT_USERNAME=mongo
MONGO_INITDB_ROOT_PASSWORD=secret
SPRING_DATA_MONGODB_HOST=mongodb
SPRING_DATA_MONGODB_PORT=27017
SPRING_DATA_MONGODB_DATABASE=review_db
# RabbitMQ
RABBITMQ_DEFAULT_USER=guest
RABBITMQ_DEFAULT_PASS=guest
SPRING_RABBITMQ_HOST=rabbitmq
SPRING_RABBITMQ_PORT=5672Note: Place your RSA keys (
private_key.pemandpublic_key.pem) insrc/main/resources/certs/to enable JWT verification.
This service is designed to run within the larger E-commerce docker network.
-
Ensure the shared network exists:
docker network create shared_ecommerce_network
-
Start the service:
docker-compose up -d --build
-
Access the Endpoints:
- API Base:
http://localhost:8081/reviews/api - Swagger Docs:
http://localhost:8081/reviews/api/docs - Prometheus Metrics:
http://localhost:8081/reviews/api/actuator/prometheus
- API Base:
If you prefer to run it locally without Docker (requires local MongoDB and RabbitMQ instances):
-
Build:
./gradlew clean build -x test -
Run:
java -jar build/libs/app.jar
The API follows RESTful standards. You can explore the endpoints via Swagger UI running at /reviews/api/docs.
Key Endpoints:
POST /reviews: Create a review.GET /reviews/product/{productId}: Get reviews for a product.POST /reviews/{reviewId}/comments: Add a comment.POST /reviews/{reviewId}/react: Like/Dislike a review.
- Fork the repository.
- Create a feature branch (
git checkout -b feature/NewFeature). - Commit your changes.
- Push to the branch.
- Open a Pull Request.