- JWT Authentication & Authorization - Centralized security through API Gateway with stateless token validation
- API Gateway - Single entry point for all client requests with intelligent routing and load balancing
- Service Registry (Eureka) - Automatic service discovery and registration for dynamic scaling
- Account Service - User management and authentication with MySQL database
- Product Service - Product catalog management with MongoDB for flexible document storage
- Order Service - Order processing with Cassandra for high-performance distributed data storage
- Payment Service - Payment processing with MySQL for ACID transaction compliance
- Synchronous HTTP calls via OpenFeign for real-time data exchange
- Asynchronous event-driven messaging through Kafka for scalable, decoupled operations
- Docker & Docker Compose
- Git
git clone https://github.com/ariannalangwang/Spring-Boot-Microservices.git
cd Spring-Boot-MicroservicesCreate a .env file in the root directory.
Use included .env.example as the .env template.
docker compose up -d- Eureka Dashboard: http://localhost:8761
- API Gateway: http://localhost:8088
- Kafka UI: http://localhost:8090
docker compose down
# Or if you want to remove all saved data so to have a clean-slate start next time:
docker compose down --volumesAll requests go through the API Gateway: http://localhost:8088
GET /api/accounts/healthPOST /api/accounts/register
Content-Type: application/json
{
"email": "user@example.com",
"firstName": "John",
"lastName": "Doe",
"password": "password123",
"shippingAddress": "123 Main St",
"billingAddress": "123 Main St",
"paymentMethod": "Credit Card"
}POST /api/accounts/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123"
}GET /api/accounts/user/{userId}
Authorization: Bearer <jwt-token>PUT /api/accounts/user/{userId}
Authorization: Bearer <jwt-token>
Content-Type: application/json
{
"email": "updated@example.com",
"firstName": "Jane",
"lastName": "Smith",
"password": "newpassword123",
"shippingAddress": "456 Oak St",
"billingAddress": "456 Oak St",
"paymentMethod": "Debit Card"
}DELETE /api/accounts/user/{userId}
Authorization: Bearer <jwt-token>GET /api/products/healthGET /api/products?page=0&size=10&sortBy=name&sortDir=ascGET /api/products/{productId}POST /api/products
Authorization: Bearer <admin-jwt-token>
Content-Type: application/json
{
"name": "iPhone 14",
"description": "Latest Apple smartphone",
"skuCode": "IPH14-128GB",
"price": 999.99,
"quantity": 50,
"pictureUrl": "https://example.com/iphone14.jpg"
}PUT /api/products/{productId}
Authorization: Bearer <admin-jwt-token>
Content-Type: application/json
{
"name": "iPhone 14 Pro",
"description": "Premium Apple smartphone",
"skuCode": "IPH14P-128GB",
"price": 1099.99,
"quantity": 30,
"pictureUrl": "https://example.com/iphone14pro.jpg"
}DELETE /api/products/{productId}
Authorization: Bearer <admin-jwt-token>GET /api/orders/healthPOST /api/orders
Authorization: Bearer <jwt-token>
Content-Type: application/json
{
"skuCode": "IPH14-128GB",
"quantity": 2
}Note: User ID is automatically extracted from JWT token
GET /api/orders?page=0&pageSize=20
Authorization: Bearer <jwt-token>Returns paginated orders for the authenticated user
GET /api/orders/{orderId}
Authorization: Bearer <jwt-token>Note: User context is automatically extracted from JWT token
DELETE /api/orders/{orderId}
Authorization: Bearer <jwt-token>Note: User context is automatically extracted from JWT token
GET /api/payments/healthGET /api/payments/users/{userId}?page=0&size=10
Authorization: Bearer <jwt-token>GET /api/payments/users/{userId}/orders/{orderId}
Authorization: Bearer <jwt-token>- Register a new user using the registration endpoint
- Login to get a JWT token from the response
- Copy the token from the login response
- Add Authorization header to subsequent requests:
- Header:
Authorization - Value:
Bearer <your-jwt-token>
- Header:
Comprehensive security implementation with JWT and role-based access:
- JWT-based authentication implemented in API Gateway
- Role-based authorization using custom
@RequireRoleannotation with AOP - Stateless security - no session management required
- Token validation at gateway level with user context propagation to downstream services
Full containerization strategy for modern deployment:
- Isolated environments - Each service and database runs in its own Docker container for complete isolation
- Easy scalability - Individual services can be scaled independently based on demand without affecting others
- Cloud-ready deployment - Containers can be easily deployed to any cloud platform (AWS ECS, GKE, Azure Container Instances)
The project uses @RestControllerAdvice for centralized exception handling:
- Validation errors -
@Validconstraint violations - Business logic exceptions - Custom exceptions like
InsufficientStockException - Database errors - Cassandra, MongoDB, MySQL connection issues
- Feign client errors - Service communication failures
- Generic exceptions - Catch-all error handling
Custom aspects for cross-cutting concerns:
@RequireRoleauthorization aspect - Intercepts method calls to check user roles- JWT token processing - Extracts user information from gateway headers
- Security enforcement - Prevents unauthorized access to admin endpoints
- Clean separation - Business logic separated from security concerns
Comprehensive validation using Jakarta Validation:
- Bean Validation -
@NotNull,@NotBlank,@Email,@Size,@Min,@Max - Custom constraints - SKU code pattern validation, price validation
- Method-level validation -
@Validatedcontrollers with parameter validation - Request body validation -
@Validon DTOs
Multiple pagination strategies implemented:
- Product Service: Standard Spring Data pagination with
Page<T>andPageable - Order Service: Cassandra-specific pagination using
Slice<T>for token-based paging - Payment Service: MySQL pagination with custom page response DTOs
- Configurable parameters: page size, sorting, and direction
