Skip to content

khan-o07/real-time-supply-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

License: MIT GitHub stars GitHub forks GitHub issues Build Status

🌟 A production-ready microservices architecture built with Spring Cloud 🌟

Scalable β€’ Resilient β€’ Observable β€’ Event-Driven


πŸ“‹ Table of Contents


🎯 Overview

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.

🌟 What Makes This Special?

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

✨ Key Features

πŸͺ Business Services

  • πŸ›οΈ Product Catalog - MongoDB-powered product management
  • πŸ“¦ Order Processing - Complete order lifecycle management
  • πŸ“‹ Inventory Tracking - Real-time stock management
  • πŸ”” Smart Notifications - Event-driven customer alerts

πŸ› οΈ Infrastructure Services

  • πŸšͺ API Gateway - Request routing & filtering
  • πŸ” Service Discovery - Dynamic service registration
  • βš™οΈ Config Server - Centralized configuration
  • πŸ” Auth Server - Security & token management

πŸ—οΈ Architecture

🌐 System Overview

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
Loading

πŸ›οΈ Service Architecture Pattern

Each microservice follows a clean, layered architecture:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚             🌐 API Layer            β”‚
β”‚        (Controllers & DTOs)         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚           πŸ’Ό Business Layer         β”‚
β”‚        (Services & Domain)          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         πŸ—„οΈ Persistence Layer       β”‚
β”‚      (Repositories & Entities)      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚        πŸ”Œ Integration Layer         β”‚
β”‚    (Message Queues & External)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Core Framework

Spring Boot Spring Cloud Java

Messaging & Events

Apache Kafka RabbitMQ

Databases

MongoDB MySQL Redis

Infrastructure

Docker Kubernetes Nginx

Monitoring & Observability

Elasticsearch Kibana Grafana Prometheus

Security & Config

Vault OAuth2


πŸš€ Quick Start

πŸ“‹ Prerequisites

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

⚑ One-Command Setup

# 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

πŸ”§ Manual Setup

Click to expand manual setup instructions

1️⃣ Infrastructure Services

# 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

2️⃣ Core Services (in order)

# 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 &

🎯 Verify Installation

After startup, check these endpoints:

Service URL Status
πŸšͺ API Gateway http://localhost:8080 Status
πŸ” Eureka Dashboard http://localhost:8761 Status
πŸ“Š Zipkin Tracing http://localhost:9411 Status
πŸ“ˆ Kibana Logs http://localhost:5601 Status

πŸ“Š Service Details

πŸ›οΈ 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

πŸ”§ Configuration

🌍 Environment Profiles

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

βš™οΈ Key Configuration Files

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

πŸ” Security Configuration

# 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}

πŸ“ˆ Monitoring & Observability

πŸ” Distributed Tracing

Zipkin Integration provides end-to-end request tracing:

  • πŸ“Š Request flow visualization
  • ⏱️ Latency analysis
  • πŸ” Error detection
  • πŸ“ˆ Performance bottleneck identification

πŸ“Š Metrics & Monitoring

Prometheus + Grafana stack for metrics:

  • πŸ“ˆ JVM metrics
  • 🌐 HTTP request metrics
  • πŸ’Ύ Database connection pools
  • πŸ”„ Kafka consumer lag
  • πŸ’Ώ Custom business metrics

πŸ“ Centralized Logging

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"
}

πŸ₯ Health Checks

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

πŸ§ͺ Testing

πŸ§ͺ Test Strategy

πŸ”¬ Unit Tests

  • JUnit 5
  • Mockito
  • Testcontainers
  • 90%+ coverage

πŸ”„ Integration Tests

  • Spring Boot Test
  • Test slices
  • Database testing
  • API contract testing

🌐 E2E Tests

  • REST Assured
  • Cucumber
  • Docker Compose
  • Full stack testing

πŸš€ Running 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

πŸ“Š Test Coverage

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%

πŸ“ Project Structure

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

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

🌟 How to Contribute

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch: git checkout -b feature/amazing-feature
  3. πŸ’« Make your changes with tests
  4. βœ… Ensure all tests pass: mvn clean verify
  5. πŸ“ Commit your changes: git commit -m 'feat: add amazing feature'
  6. πŸš€ Push to the branch: git push origin feature/amazing-feature
  7. πŸ“¬ Open a Pull Request

πŸ“‹ Development Guidelines

  • Follow Conventional Commits
  • Maintain test coverage above 85%
  • Update documentation for new features
  • Follow the existing code style

πŸ› Reporting Issues

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.

πŸ† Acknowledgments

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


⭐ If you found this project helpful, please give it a star! ⭐

Happy coding! πŸš€

About

Spring Boot microservices ecosystem with Kafka, Eureka, Zipkin, API Gateway & Circuit Breakers. Production-ready supply chain demo.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages