187 lines
5.7 KiB
Markdown
187 lines
5.7 KiB
Markdown
|
|
# Production Service
|
||
|
|
|
||
|
|
Production planning and batch management service for the bakery management system.
|
||
|
|
|
||
|
|
## Overview
|
||
|
|
|
||
|
|
The Production Service handles all production-related operations including:
|
||
|
|
|
||
|
|
- **Production Planning**: Calculate daily requirements using demand forecasts and inventory levels
|
||
|
|
- **Batch Management**: Track production batches from start to finish
|
||
|
|
- **Capacity Management**: Equipment, staff, and time scheduling
|
||
|
|
- **Quality Control**: Yield tracking, waste management, efficiency metrics
|
||
|
|
- **Alert System**: Comprehensive monitoring and notifications
|
||
|
|
|
||
|
|
## Features
|
||
|
|
|
||
|
|
### Core Capabilities
|
||
|
|
- Daily production requirements calculation
|
||
|
|
- Production batch lifecycle management
|
||
|
|
- Real-time capacity planning and utilization
|
||
|
|
- Quality control tracking and metrics
|
||
|
|
- Comprehensive alert system with multiple severity levels
|
||
|
|
- Integration with inventory, orders, recipes, and sales services
|
||
|
|
|
||
|
|
### API Endpoints
|
||
|
|
|
||
|
|
#### Dashboard & Planning
|
||
|
|
- `GET /api/v1/tenants/{tenant_id}/production/dashboard-summary` - Production dashboard data
|
||
|
|
- `GET /api/v1/tenants/{tenant_id}/production/daily-requirements` - Daily production planning
|
||
|
|
- `GET /api/v1/tenants/{tenant_id}/production/requirements` - Requirements for procurement
|
||
|
|
|
||
|
|
#### Batch Management
|
||
|
|
- `POST /api/v1/tenants/{tenant_id}/production/batches` - Create production batch
|
||
|
|
- `GET /api/v1/tenants/{tenant_id}/production/batches/active` - Get active batches
|
||
|
|
- `GET /api/v1/tenants/{tenant_id}/production/batches/{batch_id}` - Get batch details
|
||
|
|
- `PUT /api/v1/tenants/{tenant_id}/production/batches/{batch_id}/status` - Update batch status
|
||
|
|
|
||
|
|
#### Scheduling & Capacity
|
||
|
|
- `GET /api/v1/tenants/{tenant_id}/production/schedule` - Production schedule
|
||
|
|
- `GET /api/v1/tenants/{tenant_id}/production/capacity/status` - Capacity status
|
||
|
|
|
||
|
|
#### Alerts & Monitoring
|
||
|
|
- `GET /api/v1/tenants/{tenant_id}/production/alerts` - Production alerts
|
||
|
|
- `POST /api/v1/tenants/{tenant_id}/production/alerts/{alert_id}/acknowledge` - Acknowledge alerts
|
||
|
|
|
||
|
|
#### Analytics
|
||
|
|
- `GET /api/v1/tenants/{tenant_id}/production/metrics/yield` - Yield metrics
|
||
|
|
|
||
|
|
## Service Integration
|
||
|
|
|
||
|
|
### Shared Clients Used
|
||
|
|
- **InventoryServiceClient**: Stock levels, ingredient availability
|
||
|
|
- **OrdersServiceClient**: Demand requirements, customer orders
|
||
|
|
- **RecipesServiceClient**: Recipe requirements, ingredient calculations
|
||
|
|
- **SalesServiceClient**: Historical sales data
|
||
|
|
- **NotificationServiceClient**: Alert notifications
|
||
|
|
|
||
|
|
### Authentication
|
||
|
|
Uses shared authentication patterns with tenant isolation:
|
||
|
|
- JWT token validation
|
||
|
|
- Tenant access verification
|
||
|
|
- User permission checks
|
||
|
|
|
||
|
|
## Configuration
|
||
|
|
|
||
|
|
Key configuration options in `app/core/config.py`:
|
||
|
|
|
||
|
|
### Production Planning
|
||
|
|
- `PLANNING_HORIZON_DAYS`: Days ahead for planning (default: 7)
|
||
|
|
- `PRODUCTION_BUFFER_PERCENTAGE`: Safety buffer for production (default: 10%)
|
||
|
|
- `MINIMUM_BATCH_SIZE`: Minimum batch size (default: 1.0)
|
||
|
|
- `MAXIMUM_BATCH_SIZE`: Maximum batch size (default: 100.0)
|
||
|
|
|
||
|
|
### Capacity Management
|
||
|
|
- `DEFAULT_WORKING_HOURS_PER_DAY`: Standard working hours (default: 12)
|
||
|
|
- `MAX_OVERTIME_HOURS`: Maximum overtime allowed (default: 4)
|
||
|
|
- `CAPACITY_UTILIZATION_TARGET`: Target utilization (default: 85%)
|
||
|
|
|
||
|
|
### Quality Control
|
||
|
|
- `MINIMUM_YIELD_PERCENTAGE`: Minimum acceptable yield (default: 85%)
|
||
|
|
- `QUALITY_SCORE_THRESHOLD`: Minimum quality score (default: 8.0)
|
||
|
|
|
||
|
|
### Alert Thresholds
|
||
|
|
- `CAPACITY_EXCEEDED_THRESHOLD`: Capacity alert threshold (default: 100%)
|
||
|
|
- `PRODUCTION_DELAY_THRESHOLD_MINUTES`: Delay alert threshold (default: 60)
|
||
|
|
- `LOW_YIELD_ALERT_THRESHOLD`: Low yield alert (default: 80%)
|
||
|
|
|
||
|
|
## Database Models
|
||
|
|
|
||
|
|
### ProductionBatch
|
||
|
|
- Complete batch tracking from planning to completion
|
||
|
|
- Status management (pending, in_progress, completed, etc.)
|
||
|
|
- Cost tracking and yield calculations
|
||
|
|
- Quality metrics integration
|
||
|
|
|
||
|
|
### ProductionSchedule
|
||
|
|
- Daily production scheduling
|
||
|
|
- Capacity planning and tracking
|
||
|
|
- Staff and equipment assignments
|
||
|
|
- Performance metrics
|
||
|
|
|
||
|
|
### ProductionCapacity
|
||
|
|
- Resource availability tracking
|
||
|
|
- Equipment and staff capacity
|
||
|
|
- Maintenance scheduling
|
||
|
|
- Utilization monitoring
|
||
|
|
|
||
|
|
### QualityCheck
|
||
|
|
- Quality control measurements
|
||
|
|
- Pass/fail tracking
|
||
|
|
- Defect recording
|
||
|
|
- Corrective action management
|
||
|
|
|
||
|
|
### ProductionAlert
|
||
|
|
- Comprehensive alert system
|
||
|
|
- Multiple severity levels
|
||
|
|
- Action recommendations
|
||
|
|
- Resolution tracking
|
||
|
|
|
||
|
|
## Alert System
|
||
|
|
|
||
|
|
### Alert Types
|
||
|
|
- **Capacity Exceeded**: When production requirements exceed available capacity
|
||
|
|
- **Production Delay**: When batches are delayed beyond thresholds
|
||
|
|
- **Cost Spike**: When production costs exceed normal ranges
|
||
|
|
- **Low Yield**: When yield percentages fall below targets
|
||
|
|
- **Quality Issues**: When quality scores consistently decline
|
||
|
|
- **Equipment Maintenance**: When equipment needs maintenance
|
||
|
|
|
||
|
|
### Severity Levels
|
||
|
|
- **Critical**: WhatsApp + Email + Dashboard + SMS
|
||
|
|
- **High**: WhatsApp + Email + Dashboard
|
||
|
|
- **Medium**: Email + Dashboard
|
||
|
|
- **Low**: Dashboard only
|
||
|
|
|
||
|
|
## Development
|
||
|
|
|
||
|
|
### Setup
|
||
|
|
```bash
|
||
|
|
# Install dependencies
|
||
|
|
pip install -r requirements.txt
|
||
|
|
|
||
|
|
# Set up database
|
||
|
|
# Configure DATABASE_URL environment variable
|
||
|
|
|
||
|
|
# Run migrations
|
||
|
|
alembic upgrade head
|
||
|
|
|
||
|
|
# Start service
|
||
|
|
uvicorn app.main:app --reload
|
||
|
|
```
|
||
|
|
|
||
|
|
### Testing
|
||
|
|
```bash
|
||
|
|
# Run tests
|
||
|
|
pytest
|
||
|
|
|
||
|
|
# Run with coverage
|
||
|
|
pytest --cov=app
|
||
|
|
```
|
||
|
|
|
||
|
|
### Docker
|
||
|
|
```bash
|
||
|
|
# Build image
|
||
|
|
docker build -t production-service .
|
||
|
|
|
||
|
|
# Run container
|
||
|
|
docker run -p 8000:8000 production-service
|
||
|
|
```
|
||
|
|
|
||
|
|
## Deployment
|
||
|
|
|
||
|
|
The service is designed for containerized deployment with:
|
||
|
|
- Health checks at `/health`
|
||
|
|
- Structured logging
|
||
|
|
- Metrics collection
|
||
|
|
- Database migrations
|
||
|
|
- Service discovery integration
|
||
|
|
|
||
|
|
## Architecture
|
||
|
|
|
||
|
|
Follows Domain-Driven Microservices Architecture:
|
||
|
|
- Clean separation of concerns
|
||
|
|
- Repository pattern for data access
|
||
|
|
- Service layer for business logic
|
||
|
|
- API layer for external interface
|
||
|
|
- Shared infrastructure for cross-cutting concerns
|