This project is a microservices-based RESTful CRUD API built with Spring Boot and MongoDB, focusing on user and product management with centralized authentication and authorization.
Our application is composed of the following microservices:
- π Auth Service: Handles authentication and authorization
- π€ User Service: Manages user-related operations
- ποΈ Product Service: Manages product-related operations
- π API Gateway: Entry point for all client requests, handles routing and load balancing
- π Microservices Architecture
- π RESTful API design
- π€ User Management (CRUD operations)
- ποΈ Product Management (CRUD operations)
- π Centralized Authentication Service
- π Role-based Authorization (Admin and User roles)
- ποΈ MongoDB database for each service
- π Password hashing and salting
- π‘οΈ Input validation and security measures
- β Java
- π Spring Boot
- π Spring Security
- π Spring Cloud (for microservices communication)
- πͺ Spring Cloud Gateway
- π MongoDB
- ποΈ Maven
All requests go through the API Gateway (http://localhost:8080)
POST /auth/login: User loginPOST /auth/logout: User logout
POST /users: Create a new userGET /users: Get all users (Admin only)GET /users/{id}: Get a specific userPUT /users/{id}: Update a userDELETE /users/{id}: Delete a user
POST /products: Create a new productGET /products: Get all products (No authentication required)GET /products/{id}: Get a specific productPUT /products/{id}: Update a productDELETE /products/{id}: Delete a product
-
Clone the repository:
git clone https://github.com/yourusername/spring-boot-mongodb-microservices-api.git -
Navigate to the project directory:
cd spring-boot-mongodb-microservices-api -
Install dependencies for each service:
mvn clean install -DskipTests -
Set up MongoDB:
- Install MongoDB if you haven't already
- Create separate databases for each service
- Update the
application.propertiesfile in each service with the corresponding MongoDB connection details
-
Run the services:
mvn spring-boot:run -pl auth-service,user-service,product-service,api-gateway
The API Gateway will be available at http://localhost:8080.
- π Passwords are hashed and salted before storing in the database
- π‘οΈ Input validation is implemented to prevent MongoDB injection attacks
- π Sensitive user information is protected and not returned in API responses
- π HTTPS is used to protect data in transit
- π« JWT tokens are used for maintaining user sessions across microservices
- π Services communicate with each other using REST API calls
- π Service discovery is handled by Eureka Server
- π Load balancing is managed by Spring Cloud LoadBalancer
Each microservice is designed to handle exceptions gracefully and return appropriate HTTP status codes and error messages. The API Gateway provides an additional layer of error handling and response normalization.
- π Distributed tracing is implemented using Spring Cloud Sleuth and Zipkin
- π Metrics are collected using Micrometer and visualized with Prometheus and Grafana
Each microservice has its own set of unit and integration tests. Additionally, end-to-end tests are implemented to ensure the correct functioning of the entire system.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE.md file for details.