A comprehensive production planning and inventory management platform built with Python Flask, featuring machine learning capabilities for demand forecasting and production scheduling.
- Multi-role Access Control: Admin, Sales, Warehouse, Factory, and Viewer roles
- Order Management: Complete order lifecycle from creation to shipment
- Inventory Management: Real-time stock tracking with automatic updates
- Production Planning: Work order management and production scheduling
- Machine Learning: Demand forecasting with LightGBM and ETA prediction
- RESTful API: Comprehensive API for all operations with OpenAPI documentation
- Authoritative Inventory: Platform manages all stock movements automatically
- Check-and-Reserve: Automatic inventory allocation with production request creation
- Production Flow: Seamless PR β WO β Receipt β Allocation workflow
- ETA Calculation: ML-driven delivery time estimates with confidence intervals
- Audit Trail: Complete tracking of all system changes
- Flask Application Factory: Modular architecture with blueprints
- SQLAlchemy ORM: Database abstraction with SQLite default (PostgreSQL ready)
- Role-based Security: JWT tokens for API, Flask-Login for web interface
- Service Layer: Clean separation of business logic
- Responsive UI: Bootstrap-based templates for all user roles
- Docker Ready: Full containerization with docker-compose
- Python 3.8+
- SQLite (included) or PostgreSQL (optional)
- Git
# Clone repository
git clone <repository-url>
cd ml-PR_v0.1
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# or .venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Setup environment
cp .env.example .env
# Initialize database
export FLASK_APP=src.app:create_app
flask db init
flask db migrate -m "Initial migration"
flask db upgrade
# Generate demo data
python scripts/generate_demo_data.py
# Run application
flask run --host=0.0.0.0 --port=5000- Web Interface: http://localhost:5000
- Default Credentials:
- Admin:
admin/password - Sales:
sales/password - Warehouse:
warehouse/password - Factory:
factory/password
- Admin:
src/
βββ app.py # Flask application factory
βββ config.py # Configuration management
βββ models_db.py # SQLAlchemy models
βββ schemas.py # Marshmallow validation schemas
βββ auth.py # Authentication utilities
βββ blueprints/ # Flask blueprints for each module
β βββ main.py # Landing page and routing
β βββ auth.py # Login/logout functionality
β βββ sales.py # Sales order management
β βββ warehouse.py # Inventory and receipts
β βββ factory.py # Production management
β βββ admin.py # User and system management
β βββ ml.py # ML model management
β βββ api.py # REST API endpoints
βββ services/ # Business logic layer
β βββ inventory_service.py # Inventory operations
β βββ order_service.py # Order processing
β βββ production_service.py # Production management
β βββ ml_service.py # Machine learning
β βββ planner_service.py # Production planning
βββ templates/ # Jinja2 templates
βββ static/ # CSS, JS, images
- Reference Data: Sectors, Lines, SKUs, Line Capabilities
- Inventory: Stock levels, movements, reservations
- Orders: Customer orders with items and status tracking
- Production: Production requests, work orders, receipts
- Users & Auth: Role-based access control
- ML Models: Model registry with versioning
- Audit: Complete change tracking
- Sales creates order β System assigns
NEWstatus - Check-and-Reserve β Allocates available inventory
- Production Requests β Created for shortages automatically
- Work Orders β Factory schedules production
- Completion β Production creates receipts
- Allocation β System allocates completed production
- Shipping β Sales ships when fully allocated
- Receipts β Warehouse creates incoming goods receipts
- Confirmation β System updates stock levels automatically
- Movements β All changes tracked with audit trail
- Reservations β Automatic allocation for orders
- Adjustments β Manual corrections with approval
- Demand Forecast β ML models predict requirements
- Capacity Planning β Greedy algorithm optimizes schedules
- ETA Calculation β Delivery estimates with confidence
- Real-time Updates β ETAs adjust based on progress
- Algorithm: LightGBM with feature engineering
- Features: Time-based, lag, rolling statistics, seasonality
- Validation: Rolling origin cross-validation
- Metrics: sMAPE, MAPE, MAE with per-SKU tracking
- ETA Calculation: Multi-factor scheduling with uncertainty
- Capacity Planning: Greedy algorithm with optional OR-Tools
- Confidence Scoring: Historical performance-based estimates
- Version Control: Full model registry with metadata
- A/B Testing: Model comparison and promotion
- Explainability: SHAP values for prediction interpretation
POST /api/auth/login
{
"username": "sales",
"password": "password"
}# Create order
POST /api/sales/orders
{
"customer_id": 1001,
"customer_name": "Acme Corp",
"items": [{"sku_id": 1, "qty": 100}]
}
# Check and reserve inventory
POST /api/sales/orders/1/check-and-reserve# Get inventory levels
GET /api/warehouse/inventory
# Create receipt
POST /api/warehouse/receipts
{
"supplier": "Supplier A",
"items": [{"sku_id": 1, "qty": 50, "batch": "B123"}]
}
# Confirm receipt
POST /api/warehouse/receipts/1/confirm# Get production requests
GET /api/factory/prs
# Create work order
POST /api/factory/wo
{
"pr_id": 1,
"sku_id": 1,
"line_id": 1,
"qty_planned": 100
}
# Complete work order
POST /api/factory/wo/1/complete
{
"qty_done": 95,
"notes": "Minor quality issues"
}# Train model
POST /api/ml/train
{
"model": "lgbm",
"retrain": true
}
# Generate forecast
POST /api/ml/forecast
{
"horizon": 7,
"skus": [1, 2, 3]
}
# Calculate ETA
POST /api/planner/eta
{
"items": [{"sku_id": 1, "qty_needed": 100}],
"use_solver": false
}# Run all tests
pytest
# Run with coverage
pytest --cov=src --cov-report=html
# Run specific test categories
pytest tests/unit/
pytest tests/integration/# Build and run with Docker Compose
docker-compose up -d
# View logs
docker-compose logs -f web
# Scale workers (if using Celery)
docker-compose up -d --scale worker=3- Development: SQLite (included)
- Production: PostgreSQL recommended
- Migrations: Flask-Migrate for schema changes
- Web Servers: Multiple gunicorn workers
- Background Tasks: Celery + Redis for async processing
- Load Balancing: Nginx or cloud load balancer
- Monitoring: Application and database metrics
- Authentication: JWT tokens with expiration
- Authorization: Role-based access control
- Input Validation: Marshmallow schemas
- SQL Injection: SQLAlchemy ORM protection
- XSS Protection: Flask built-in security
- Application:
/api/healthendpoint - Database: Connection validation
- ML Models: Model availability and performance
- Application Logs: Structured logging with levels
- Audit Trail: Complete change tracking
- Performance: Request timing and metrics
- Flask Debug Mode: Detailed error pages
- Database Browser: SQLite inspection tools
- API Testing: Built-in test client
- Code Style: Follow PEP 8 with black formatting
- Testing: Maintain test coverage above 80%
- Documentation: Update README and API docs
- Database: Use migrations for schema changes
- Security: Review authentication and authorization
This project is licensed under the MIT License - see the LICENSE file for details.
- Database Issues: Check SQLite permissions, try
flask db upgrade - Import Errors: Verify virtual environment activation
- Permission Errors: Ensure data directories are writable
- ML Errors: Verify demo data exists and models directory is writable
- Documentation: See
RUN_INSTRUCTIONS.mdfor detailed setup - API Docs: Available at
/api/docswhen implemented - Demo Data: Run
python scripts/generate_demo_data.py
For additional support, check the comprehensive documentation and test the application with provided demo credentials.