Microservices Architecture with API Gateway, Eureka, Auth, User, Product Services, and Common Module
This project implements a microservices architecture using Spring Boot and Spring Cloud. It consists of the following components:
- API Gateway: Routes and filters incoming requests.
- Auth Service: Handles user authentication and issues JWT tokens.
- User Service: Manages user data.
- Product Service: Manages products and catalogs.
- Eureka Server: Service discovery and registration.
- Common Module: A shared library containing reusable classes (DTOs, utilities, exceptions, constants).
- Purpose: Provides shared components and reduces code duplication.
- Used by: Auth, User, and Product services.
- Contents:
- DTOs (Data Transfer Objects)
- Custom Exceptions
- Response Models (e.g.,
ApiResponse
) - Enums & Constants
- Utility Classes (e.g., JWT utility)
Each service includes the common module as a dependency:
<dependency>
<groupId>com.commonModule</groupId>
<artifactId>commonModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
This project implements a secure microservice-based architecture using JWT for authentication, Spring Cloud Gateway for routing, and Eureka for service discovery.
-
Login
Clients send aPOST /api/auth/login
request with user credentials. -
Token Issuance
The Auth Service validates the credentials and issues a JWT token. -
Authorization
Clients include the token in theAuthorization: Bearer <token>
header for secure endpoints. -
Gateway Validation
The API Gateway verifies the JWT token before forwarding the request to internal services.
- Base URL Prefix:
/api/**
- Responsibilities:
- Route external requests to internal services
- Validate JWT tokens for secure endpoints
Route Prefix | Service |
---|---|
/api/auth/** |
Auth Service |
/api/users/** |
User Service |
/api/products/** |
Product Service |
-
Endpoints:
POST /auth/login
– Authenticate user and return JWT tokenPOST /auth/register
– Register a new user
-
Uses:
- Common DTOs and exception handling from
commonmodule
- Common DTOs and exception handling from
-
Endpoints:
GET /users/{id}
– Retrieve user by IDPUT /users/{id}
– Update user details
-
Uses:
- DTOs,
ApiResponse
, and shared exceptions fromcommonmodule
- DTOs,
-
Endpoints:
GET /products
– List all productsPOST /products
– Add a new product
-
Uses:
- Shared models and exception handling from
commonmodule
- Shared models and exception handling from
- URL:
http://localhost:8761/
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/