Scalable • Resilient • Observable • Event-Driven
- 🎯 Overview
- ✨ Key Features
- 🏗️ Architecture
- 🛠️ Tech Stack
- 🚀 Quick Start
- 📊 Service Details
- 🔧 Configuration
- 📈 Monitoring & Observability
- 🧪 Testing
- 🤝 Contributing
- 📜 License
This project demonstrates a real-world microservices architecture for supply chain management, showcasing best practices in distributed systems design. Built with Spring Cloud ecosystem, it provides a robust foundation for scalable enterprise applications.
- 🔄 Event-Driven Architecture with Apache Kafka
- 🛡️ Fault Tolerance with Circuit Breakers
- 🔍 Full Observability with distributed tracing
- 🚪 API Gateway as single entry point
- 📊 Centralized Logging with ELK Stack
- 🔐 Secure Authentication & Authorization
- ⚙️ Externalized Configuration management
|
|
graph TB
Client[👤 Client] --> Gateway[🚪 API Gateway]
Gateway --> Auth[🔐 Auth Server]
Gateway --> Product[🛍️ Product Service]
Gateway --> Order[📦 Order Service]
Order -->|Sync Call| Inventory[📋 Inventory Service]
Order -->|Async Event| Kafka[🔄 Kafka]
Kafka --> Notification[🔔 Notification Service]
Product --> MongoDB[(🍃 MongoDB)]
Order --> MySQL1[(🗄️ MySQL)]
Inventory --> MySQL2[(🗄️ MySQL)]
subgraph "🛠️ Infrastructure"
Eureka[🔍 Eureka Server]
Config[⚙️ Config Server]
Zipkin[📊 Zipkin]
ELK[📈 ELK Stack]
end
subgraph "🔧 External Config"
GitHub[📁 GitHub]
Vault[🔐 HashiCorp Vault]
end
Config --> GitHub
Config --> Vault
style Client fill:#e1f5fe
style Gateway fill:#f3e5f5
style Kafka fill:#fff3e0
style ELK fill:#e8f5e8
Each microservice follows a clean, layered architecture:
┌─────────────────────────────────────┐
│ 🌐 API Layer │
│ (Controllers & DTOs) │
├─────────────────────────────────────┤
│ 💼 Business Layer │
│ (Services & Domain) │
├─────────────────────────────────────┤
│ 🗄️ Persistence Layer │
│ (Repositories & Entities) │
├─────────────────────────────────────┤
│ 🔌 Integration Layer │
│ (Message Queues & External) │
└─────────────────────────────────────┘
Requirement | Version | Purpose |
---|---|---|
☕ Java JDK | 17+ | Runtime environment |
🐳 Docker | 20.10+ | Containerization |
🐳 Docker Compose | 2.0+ | Multi-container orchestration |
🔨 Maven | 3.8+ | Build automation |
💾 Available RAM | 8GB+ | Running all services |
# Clone the repository
git clone https://github.com/your-username/spring-boot-microservices.git
cd spring-boot-microservices
# Start the entire stack
make up
# OR
docker-compose up -d && ./scripts/start-services.sh
Click to expand manual setup instructions
# Start backing services
docker-compose up -d mongodb mysql kafka zookeeper elasticsearch kibana zipkin
# Wait for services to be ready
./scripts/wait-for-services.sh
# 1. Configuration Server
cd config-server && mvn spring-boot:run &
# 2. Discovery Server
cd discovery-server && mvn spring-boot:run &
# 3. Gateway
cd api-gateway && mvn spring-boot:run &
# 4. Business Services
cd product-service && mvn spring-boot:run &
cd inventory-service && mvn spring-boot:run &
cd order-service && mvn spring-boot:run &
cd notification-service && mvn spring-boot:run &
After startup, check these endpoints:
Service | URL | Status |
---|---|---|
🚪 API Gateway | http://localhost:8080 | |
🔍 Eureka Dashboard | http://localhost:8761 | |
📊 Zipkin Tracing | http://localhost:9411 | |
📈 Kibana Logs | http://localhost:5601 |
🛍️ Product Service
Purpose: Manages product catalog and inventory display
Tech Stack: Spring Boot + MongoDB + Spring Data MongoDB
Key Features:
- ✅ Product CRUD operations
- ✅ Category management
- ✅ Search and filtering
- ✅ Product recommendations
API Endpoints:
GET /api/products # List all products
GET /api/products/{id} # Get product details
POST /api/products # Create new product
PUT /api/products/{id} # Update product
DELETE /api/products/{id} # Delete product
GET /api/products/search # Search products
📦 Order Service
Purpose: Handles complete order lifecycle management
Tech Stack: Spring Boot + MySQL + JPA + Kafka Producer
Key Features:
- ✅ Order creation and management
- ✅ Inventory validation (sync call)
- ✅ Payment processing integration
- ✅ Order status tracking
- ✅ Event publishing for notifications
API Endpoints:
POST /api/orders # Create new order
GET /api/orders/{id} # Get order details
GET /api/orders/user/{id} # Get user orders
PUT /api/orders/{id}/status # Update order status
DELETE /api/orders/{id} # Cancel order
📋 Inventory Service
Purpose: Real-time inventory tracking and management
Tech Stack: Spring Boot + MySQL + JPA + Redis Cache
Key Features:
- ✅ Stock level management
- ✅ Real-time availability checks
- ✅ Low stock alerts
- ✅ Inventory reservations
- ✅ Audit trail for stock changes
API Endpoints:
GET /api/inventory/{productId} # Check stock
POST /api/inventory/reserve # Reserve stock
POST /api/inventory/release # Release reservation
PUT /api/inventory/{productId} # Update stock
GET /api/inventory/low-stock # Get low stock items
🔔 Notification Service
Purpose: Multi-channel customer notifications
Tech Stack: Spring Boot + Kafka Consumer + Email/SMS APIs
Key Features:
- ✅ Email notifications
- ✅ SMS alerts
- ✅ Push notifications
- ✅ Notification templates
- ✅ Delivery tracking
Supported Events:
- 📧 Order confirmation
- 📱 Shipping updates
⚠️ Low stock alerts- 🎉 Promotional offers
Profile | Purpose | Config Source |
---|---|---|
local |
Development | Local files |
dev |
Development server | Config Server + GitHub |
staging |
Pre-production | Config Server + Vault |
prod |
Production | Config Server + Vault + Encryption |
config-repo/
├── application.yml # Global configuration
├── application-{profile}.yml # Profile-specific config
├── api-gateway.yml # Gateway routing rules
├── product-service.yml # Product service config
├── order-service.yml # Order service config
└── inventory-service.yml # Inventory service config
# Example security configuration
security:
oauth2:
client:
registration:
gateway:
client-id: ${OAUTH2_CLIENT_ID}
client-secret: ${OAUTH2_CLIENT_SECRET}
scope: read,write
resource-server:
jwt:
issuer-uri: ${JWT_ISSUER_URI}
Zipkin Integration provides end-to-end request tracing:
- 📊 Request flow visualization
- ⏱️ Latency analysis
- 🔍 Error detection
- 📈 Performance bottleneck identification
Prometheus + Grafana stack for metrics:
- 📈 JVM metrics
- 🌐 HTTP request metrics
- 💾 Database connection pools
- 🔄 Kafka consumer lag
- 💿 Custom business metrics
ELK Stack for log aggregation:
{
"timestamp": "2024-01-15T10:30:00Z",
"service": "order-service",
"traceId": "abc123def456",
"spanId": "789ghi012jkl",
"level": "INFO",
"message": "Order created successfully",
"userId": "user-123",
"orderId": "order-456"
}
Each service exposes comprehensive health endpoints:
GET /actuator/health # Overall health
GET /actuator/info # Service information
GET /actuator/metrics # Prometheus metrics
GET /actuator/env # Environment details
🔬 Unit Tests
|
🔄 Integration Tests
|
🌐 E2E Tests
|
# Run all tests
mvn clean test
# Run specific test categories
mvn test -Dgroups="unit"
mvn test -Dgroups="integration"
mvn test -Dgroups="e2e"
# Generate coverage report
mvn jacoco:report
Service | Unit Tests | Integration Tests | Coverage |
---|---|---|---|
Product Service | ✅ 45 tests | ✅ 12 tests | 92% |
Order Service | ✅ 38 tests | ✅ 15 tests | 88% |
Inventory Service | ✅ 32 tests | ✅ 10 tests | 90% |
Notification Service | ✅ 28 tests | ✅ 8 tests | 85% |
spring-boot-microservices/
├── 📁 services/
│ ├── 🚪 api-gateway/ # Spring Cloud Gateway
│ ├── 🔐 auth-server/ # OAuth2 Authorization Server
│ ├── ⚙️ config-server/ # Spring Cloud Config
│ ├── 🔍 discovery-server/ # Eureka Discovery Server
│ ├── 🛍️ product-service/ # Product management
│ ├── 📦 order-service/ # Order processing
│ ├── 📋 inventory-service/ # Inventory management
│ └── 🔔 notification-service/ # Notification handling
├── 📁 infrastructure/
│ ├── 🐳 docker/ # Docker configurations
│ ├── ☸️ kubernetes/ # K8s manifests
│ └── 📊 monitoring/ # Grafana dashboards
├── 📁 config-repo/ # External configuration
├── 📁 scripts/ # Automation scripts
├── 📁 docs/ # Documentation
├── 🐳 docker-compose.yml # Local development stack
├── 📋 Makefile # Build automation
└── 📖 README.md # This file
We welcome contributions! Please see our Contributing Guide for details.
- 🍴 Fork the repository
- 🌿 Create a feature branch:
git checkout -b feature/amazing-feature
- 💫 Make your changes with tests
- ✅ Ensure all tests pass:
mvn clean verify
- 📝 Commit your changes:
git commit -m 'feat: add amazing feature'
- 🚀 Push to the branch:
git push origin feature/amazing-feature
- 📬 Open a Pull Request
- Follow Conventional Commits
- Maintain test coverage above 85%
- Update documentation for new features
- Follow the existing code style
Found a bug? Please open an issue with:
- 🔍 Description: What went wrong?
- 🔄 Steps to reproduce: How can we recreate it?
- 🎯 Expected behavior: What should happen?
- 💻 Environment: OS, Java version, etc.
Special thanks to:
- 🌟 Spring Team for the amazing Spring Cloud ecosystem
- 🚀 Netflix OSS for pioneering microservices patterns
- 🐳 Docker Community for containerization standards
- 👥 All Contributors who make this project better