This project is a microservices-based e-commerce application built using Spring Boot, Spring Cloud, Spring Security, Eureka, and API Gateway.
It demonstrates a distributed architecture where different services (User Management, Products, Cart, Authentication, Gateway, and Eureka) work together to provide a scalable and secure e-commerce platform.
- Microservices architecture with Spring Boot
- Centralized service discovery via Eureka
- API Gateway for routing & authentication
- Secure OAuth2/JWT-based authentication
- Independent services for Users, Products, Cart, Orders, Shipments, and Notifications
- Feign Client communication between services
- Exception handling via
@ControllerAdvice
- Location:
eurekaserver/ - Registers and discovers all microservices dynamically.
- Acts as the central registry for service communication.
- Location:
gatewayserver/ - Routes incoming requests to the correct microservice.
- Provides centralized authentication, authorization, and request filtering.
- Key files:
WebSecurityConfig.java→ Configures Spring Security.JwtAuthoritiesConverter.java→ Extracts authorities from JWT.
- Location:
auth-client/ - Handles OAuth2 and authentication client configurations.
- Provides secure interaction with User Management service.
- Example:
WebClientConfiguration.javasets up a secure WebClient.
- Location:
user-management/ - Handles user registration, authentication, and authorization.
- Provides APIs for creating users and checking credentials.
- Integrates with Cart Service via
CartFeignClient.java. - Key components:
AuthorizationServerConfig.java→ OAuth2 authorization server.UserController.java→ Handles user-related REST endpoints.UserService.java→ Business logic for user management.
- Location:
products/ - Manages products and categories.
- Provides CRUD operations on products.
- Key components:
ProductController.java→ Handles product-related requests.ProductService.java→ Contains business logic.ProductRepository.java&CategoryRepository.java.
- Location:
cart/ - Manages shopping cart functionality.
- Stores products added by users to their cart.
- Key components:
CartController.java→ Handles cart operations.CartService.java→ Business logic for managing cart items.CartRepository.java&CartProductRepository.java.
- Authentication is handled via OAuth2 and JWT tokens.
- The User Management Service issues tokens after successful login/registration.
- The API Gateway validates JWT tokens before routing requests.
- Role-based access control (RBAC) is implemented using Spring Security.
| Service | Endpoint Example | Description |
|---|---|---|
| User Management | /users/register |
Register a new user |
| User Management | /users/login |
Authenticate & get JWT token |
| Product Service | /products |
Get all products |
| Product Service | /products/{id} |
Get product by ID |
| Cart Service | /cart/{userId} |
Get cart for a user |
| Cart Service | /cart/{userId}/add |
Add item to user’s cart |
| Order Service | /orders/create |
Create a new order |
| Notification Service | /notifications/send |
Send notification to seller |
| Shipment Service | /shipments/create |
Create a new shipment |
| Order Service | /orders/{id}/status |
Update order status |
- Backend: Spring Boot, Spring Cloud, Spring Security, OAuth2
- Service Discovery: Netflix Eureka
- API Gateway: Spring Cloud Gateway
- Build Tool: Maven
- Database: configurable relational DB (default profile H2, can be switched to MySQL/Postgres)
- Communication: REST APIs, Feign Client
shopsphere/
│── auth-client/ # Handles authentication & OAuth2 client
│── cart/ # Manages shopping carts
│── eurekaserver/ # Service discovery (Eureka Server)
│── gatewayserver/ # API Gateway for routing & security
│── products/ # Product management service
│── user-management/ # User service with OAuth2 and Feign Client
- Java 17+
- Maven 3.8+
- Docker (optional, if containerizing)
- Clone the repository:
git clone <repo-url> cd ecommerce-main
- Start the Eureka Server:
cd eurekaserver mvn spring-boot:run - Start the Gateway Server:
cd gatewayserver mvn spring-boot:run - Start the Auth Client, User Management, Product, and Cart Services:
cd <service-folder> mvn spring-boot:run
- Access Eureka Dashboard:
http://localhost:8761