Enterprise-grade microservices architecture for industrial weight management and billing operations
- Overview
- Features
- Architecture
- Quick Start
- Technology Stack
- Services
- API Documentation
- Monitoring
- Security
- Testing
- Contributing
- License
The Gan Shmuel Weight Management System is a comprehensive solution for managing industrial weighing operations at a juice factory. It handles truck weighing sessions, provider billing, shift management, and provider registration through a secure, scalable microservices architecture.
πΌ DevOps Portfolio Project - Demonstrates production-ready patterns with one-command local setup
- π Weight Management: Session-based truck weighing with IN/OUT tracking
- π° Billing System: Automated billing with provider-specific rates
- π₯ Shift Management: Operator performance tracking and shift handoffs
- π’ Provider Registration: Candidate approval workflow with admin panel
- π Real-time Monitoring: Prometheus metrics + Grafana dashboards
- π Enterprise Security: Rate limiting, API gateway, vulnerability scanning
- β Microservices Architecture - 4 independent backend services
- β API Gateway (Traefik v3) - Single entry point, load balancing ready
- β Real-time Health Monitoring - Live status indicators on landing page
- β Session-based Weighing - Links IN/OUT transactions for accurate net weight
- β Automated Billing - Calculates payments using provider-specific rates
- β Excel Integration - Upload/download rate sheets
- π API Gateway - Traefik v3 with automatic service discovery
- π‘οΈ Rate Limiting - Redis-backed DDoS protection
- π Monitoring Stack - Prometheus + Grafana with 200h retention
- π Security Scanning - Trivy v0.33.1, TruffleHog v3.90.11, GitGuardian v1.37.0
- π CI/CD Pipeline - Production-grade GitHub Actions with quality gates
- π³ Container Registry - GitHub Container Registry (ghcr.io)
- π Metrics & Alerts - Business and infrastructure metrics
- π§ Reproducible Builds - UV package manager with version pinning
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β EXTERNAL USERS β
β (Internet / Browser) β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β HTTP/HTTPS
βΌ
ββββββββββββββββββ
β API GATEWAY β β ONLY PORT EXPOSED: 80
β (Traefik v3) β
βββββ¬βββββββββββββ
β
βββββββββββββββββΌββββββββββββββββ¬ββββββββββββββββ
β β β β
βΌ βΌ βΌ βΌ
βββββββββββ βββββββββββ βββββββββββ βββββββββββ
β Weight β β Billing β β Shift β βProvider β
β Service β β Service β β Service β β Service β
β :5001 β β :5002 β β :5003 β β :5004 β
ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ
β β β β
βΌ βΌ βΌ βΌ
βββββββββββ βββββββββββ βββββββββββ βββββββββββ
βWeight DBβ βBilling β βShift DB β βProvider β
β MySQL β β DB β β+ Redis β β DB β
βββββββββββ β MySQL β βββββββββββ βPostgres β
βββββββββββ βββββββββββ
Attack Surface Reduced from 5 Ports to 1
- β External Access: Only API Gateway exposed (port 80)
- β Internal Services: Communicate via Docker network only
- β Databases: Never exposed externally
- β Rate Limiting: Redis-backed protection on all endpoints
- β Security Scanning: Daily automated scans
- Docker & Docker Compose
- Git
- 8GB RAM minimum (recommended 16GB)
-
Clone the repository
git clone https://github.com/ksalhab89/GanShmuel2.0.git cd GanShmuel2.0 -
Configure environment
cp .env.example .env # Edit .env with your configuration -
Start all services
docker-compose up -d
-
Populate test data (optional)
# Fast mode docker-compose --profile populate up populate-data # Realistic mode (simulates actual operations) docker-compose --profile populate run populate-data --realistic
Everything runs through port 80:
# Landing Page with Real-time Health Monitoring
open http://localhost/
# Backend Health Checks
curl http://localhost/api/weight/health
curl http://localhost/api/billing/health
curl http://localhost/api/shift/health
curl http://localhost/api/provider/health
# Monitoring & Operations
open http://localhost:9999/dashboard/ # Traefik Dashboard (credentials: see below)
open http://localhost:9090 # Prometheus
open http://localhost:3001 # Grafana (admin/admin)- Framework: FastAPI (Python 3.11)
- Package Manager: UV (pinned v0.5.20)
- Databases: MySQL 8.0, PostgreSQL 15, Redis 7
- ORM: SQLAlchemy 2.0 with async support
- Migrations: Alembic
- Testing: pytest with pytest-asyncio, >90% coverage
- Validation: Pydantic v2
- Rate Limiting: SlowAPI + Redis
- API Gateway: Traefik v3.0
- Containerization: Docker & Docker Compose (18 services)
- Monitoring: Prometheus + Grafana
- Security Scanning: Trivy v0.33.1, TruffleHog v3.90.11, GitGuardian v1.37.0
- CI/CD: GitHub Actions (production-grade workflows with quality gates)
- Container Registry: GitHub Container Registry (ghcr.io)
- Package Manager: UV with version pinning for reproducible builds
- Framework: React 18 with TypeScript
- Build Tool: Vite
- UI Library: Material-UI (MUI)
- State Management: TanStack Query (React Query)
- Routing: React Router v6
| Service | Port | Database | Gateway Route | Description |
|---|---|---|---|---|
| Weight Service | 5001* | MySQL | /api/weight/* |
Truck weighing operations & session management |
| Billing Service | 5002* | MySQL | /api/billing/* |
Provider billing & rate management |
| Shift Service | 5003* | MySQL + Redis | /api/shift/* |
Operator shift management & performance |
| Provider Service | 5004* | PostgreSQL | /api/provider/* |
Candidate registration & approval workflow |
| Frontend | 3000* | - | / |
React app with real-time health monitoring |
* Ports not exposed externally - access via API Gateway (port 80) only
Provider Service β Billing Service β Weight Service
β
Shift Service ββ
Interactive OpenAPI/Swagger documentation available for all services:
http://localhost/api/weight/docs
http://localhost/api/billing/docs
http://localhost/api/shift/docs
http://localhost/api/provider/docs
Weight Service:
# Create weighing session (truck entering)
curl -X POST http://localhost/api/weight/ \
-H "Content-Type: application/json" \
-d '{"direction":"in","bruto":15000,"truck_id":"ABC123","containers":["C1","C2"],"produce":"orange"}'
# Get weighing sessions
curl http://localhost/api/weight/?from=2025-01-01&to=2025-12-31Billing Service:
# Upload rates from Excel
curl -X POST http://localhost/api/billing/rates/upload \
-F "file=@rates.xlsx"
# Generate bill for provider
curl -X POST http://localhost/api/billing/bills/ \
-H "Content-Type: application/json" \
-d '{"provider_id":1,"from":"2025-01-01","to":"2025-01-31"}'All services expose metrics at /metrics endpoint:
- Request counts and latencies
- Database connection pool metrics
- Business metrics (transactions, bills, shifts)
- Custom application metrics
Access Prometheus UI: http://localhost:9090
Pre-configured dashboards for:
- Service health and uptime
- Request rates and error rates
- Database performance
- Business KPIs
Access Grafana: http://localhost:3001 (admin/admin)
Monitor API Gateway routing and traffic:
http://localhost:9999/dashboard/
Login: Username admin - Password in infrastructure/gateway/TRAEFIK_CREDENTIALS.txt
PUBLIC = "10 per minute" # Unauthenticated endpoints
AUTH_LOGIN = "5 per minute" # Prevent brute force
AUTH_REGISTER = "3 per minute" # Prevent spam
READ_LIGHT = "100 per minute" # Health checks, status
READ_HEAVY = "30 per minute" # Lists, searches
WRITE_LIGHT = "50 per minute" # Single record writes
WRITE_HEAVY = "10 per minute" # Batch operations
ADMIN = "20 per minute" # Admin operationsAutomated daily scans for:
- β Docker Images: Trivy vulnerability scanning
- β Python Dependencies: pip-audit + Safety
- β Secrets Detection: TruffleHog + GitGuardian
- β Configuration: Docker Compose validation
- Never commit
.envfiles - Use strong passwords (min 16 characters)
- Rotate credentials regularly
- Enable HTTPS in production (Let's Encrypt)
- Use secrets manager (Vault, AWS Secrets Manager)
# Provider Registration Service (69/69 tests)
cd provider-registration-service
pytest tests/ -v --cov=src --cov-report=html
# Weight Service
cd weight-service
pytest tests/ -v
# Billing Service
cd billing-service
pytest tests/ -v- Provider Service: >90% coverage, 69/69 tests passing
- Integration Tests: End-to-end API workflows
- Performance Tests: Concurrent request handling
- Security Tests: SQL injection, XSS prevention
Bruto (Gross Weight) = Neto (Net Fruit) + Truck Tara + Ξ£(Container Tara)
- Truck enters β POST
/weight(direction=in) β Records gross weight, creates session - Truck unloads containers
- Truck exits β POST
/weight(direction=out) β Records tare weight - System calculates net fruit weight using session ID
- Provider-specific rates override general rates (scope precedence)
- Bill calculation:
Neto weight Γ rate = payment amount - Only processes transactions for provider's registered trucks
- Candidate submits application β POST
/candidates - Admin reviews candidates β GET
/candidates - Admin approves β POST
/candidates/{id}/approveβ Auto-creates provider in billing service - Admin rejects β POST
/candidates/{id}/reject(optional rejection reason)
gan-shmuel-2/
βββ infrastructure/ # Gateway, monitoring, scripts
β βββ gateway/ # Traefik configuration
β βββ monitoring/ # Prometheus + Grafana
β βββ scripts/ # Operational scripts
βββ .github/workflows/ # CI/CD pipelines
βββ weight-service/ # Weight management
βββ billing-service/ # Billing & providers
βββ shift-service/ # Shift management
βββ provider-registration-service/ # Provider registration
βββ frontend/ # React TypeScript app
βββ populate-data/ # Test data generator
βββ docker-compose.yml # Service orchestration
βββ .env.example # Environment template
# View logs
docker-compose logs -f weight-service
# Restart service
docker-compose restart billing-service
# Rebuild service
docker-compose up -d --build weight-service
# Stop all services
docker-compose down
# Clean restart (remove volumes)
docker-compose down -v && docker-compose up -dContributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow existing code style (Black for Python, ESLint for TypeScript)
- Add tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting PR
- Keep commits atomic and well-described
This project is licensed under the MIT License - see the LICENSE file for details.
- FastAPI - Modern, fast web framework
- Traefik - Cloud-native API gateway
- Prometheus + Grafana - Monitoring excellence
- SlowAPI - Elegant rate limiting
- Trivy - Comprehensive security scanning
- GitHub Actions - Flexible CI/CD platform
- Issues: GitHub Issues
- API Docs: Available at
/docsendpoint for each service
- Microservices Architecture - 18-container orchestration
- API Gateway - Traefik v3 with service discovery
- Container Orchestration - Docker Compose with health checks
- Monitoring Stack - Prometheus + Grafana with metrics
- Security - Rate limiting, vulnerability scanning, security headers
- CI/CD Pipeline - Production-grade GitHub Actions workflows
- Real-time Health Monitoring - Live service status dashboard
- One-Command Setup -
docker-compose up -dto start everything
- Code Quality Gates - Type checking, linting, formatting enforced
- Security Scanning - Trivy, TruffleHog, GitGuardian with pinned versions
- Test Coverage - >90% coverage requirement, 69/69 tests passing
- Dependency Pinning - UV v0.5.20 for reproducible builds
- Optimized Startup - Health check polling instead of arbitrary waits
- Build Caching - Docker layer caching for faster CI runs
- API Gateway Pattern - Single entry point for all services
- Service Mesh Concepts - Internal service communication
- Observability - Metrics, health checks, dashboards
- Security Hardening - Attack surface reduction, automated scanning
- Infrastructure as Code - Complete docker-compose configuration
- Testing - 69/69 tests passing, >90% coverage
Demo & Credentials: See PORTFOLIO_SHOWCASE.md for access details and system walkthrough