Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 

Repository files navigation

lets-play

🌟 Spring Boot MongoDB Microservices CRUD API

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.

πŸ—οΈ Architecture Overview

Our application is composed of the following microservices:

  1. πŸ” Auth Service: Handles authentication and authorization
  2. πŸ‘€ User Service: Manages user-related operations
  3. πŸ›οΈ Product Service: Manages product-related operations
  4. πŸŒ‰ API Gateway: Entry point for all client requests, handles routing and load balancing

✨ Features

  • πŸ”€ 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

πŸ› οΈ Technology Stack

  • β˜• Java
  • πŸƒ Spring Boot
  • πŸ”’ Spring Security
  • πŸƒ Spring Cloud (for microservices communication)
  • πŸšͺ Spring Cloud Gateway
  • πŸƒ MongoDB
  • πŸ—οΈ Maven

πŸ”— API Endpoints

All requests go through the API Gateway (http://localhost:8080)

πŸ” Auth Service

  • POST /auth/login: User login
  • POST /auth/logout: User logout

πŸ‘€ User Service

  • POST /users: Create a new user
  • GET /users: Get all users (Admin only)
  • GET /users/{id}: Get a specific user
  • PUT /users/{id}: Update a user
  • DELETE /users/{id}: Delete a user

πŸ›οΈ Product Service

  • POST /products: Create a new product
  • GET /products: Get all products (No authentication required)
  • GET /products/{id}: Get a specific product
  • PUT /products/{id}: Update a product
  • DELETE /products/{id}: Delete a product

πŸš€ Setup and Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/spring-boot-mongodb-microservices-api.git
    
  2. Navigate to the project directory:

    cd spring-boot-mongodb-microservices-api
    
  3. Install dependencies for each service:

    mvn clean install -DskipTests
    
  4. Set up MongoDB:

    • Install MongoDB if you haven't already
    • Create separate databases for each service
    • Update the application.properties file in each service with the corresponding MongoDB connection details
  5. 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.

πŸ›‘οΈ Security Measures

  • πŸ”’ 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

πŸ”€ Inter-Service Communication

  • 🚌 Services communicate with each other using REST API calls
  • πŸ” Service discovery is handled by Eureka Server
  • πŸ”€ Load balancing is managed by Spring Cloud LoadBalancer

⚠️ Error Handling

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.

πŸ” Monitoring and Logging

  • πŸ“Š Distributed tracing is implemented using Spring Cloud Sleuth and Zipkin
  • πŸ“ˆ Metrics are collected using Micrometer and visualized with Prometheus and Grafana

πŸ§ͺ Testing

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.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors