ChainCommand is a supply chain risk and inventory operations platform combining CP-SAT constraint optimization, RL inventory policy, BOM management, supplier risk scoring, and CTB (Clear-to-Build) analysis.
pip install -e ".[dev]" # Install with dev deps
python -m chaincommand --demo # Run demo cycle
pytest tests/ -v # Run tests
ruff check chaincommand/ tests/ # Lint- CP-SAT Optimization: OR-Tools MILP solver for multi-supplier allocation
- RL Inventory Policy: PPO (Stable-Baselines3) with (s,S) baseline comparison
- BOM Management: Multi-tier BOM tree, explosion, where-used, cost rollup
- Supplier Risk Scoring: 5-factor rule-based + RandomForest ML blending
- CTB Dashboard: Clear-to-Build analysis with shortage detection
- ML Models: LSTM + XGBoost ensemble forecaster, Isolation Forest anomaly detector
- Event Bus: Async pub/sub for KPI violations and alerts
- AWS Backend: Optional S3/Redshift/Athena/QuickSight persistence
chaincommand/optimization/— CP-SAT MILP optimizer + benchmarkchaincommand/rl/— RL inventory environment, trainer, policychaincommand/bom/— BOM tree models + managerchaincommand/risk/— Supplier risk scoring (rule-based + ML)chaincommand/ctb/— Clear-to-Build analyzerchaincommand/models/— ML models (forecaster, anomaly_detector, optimizer)chaincommand/kpi/— 12-metric KPI enginechaincommand/events/— Async pub/sub event buschaincommand/api/— FastAPI REST + WebSocketchaincommand/aws/— AWS persistence (S3/Redshift/Athena/QuickSight)tests/— 100+ tests across test modules
All settings via CC_ env prefix or .env file. Key settings:
CC_ORTOOLS_RISK_LAMBDA: Risk-cost trade-off for CP-SAT (default: 0.3)CC_RL_TOTAL_TIMESTEPS: RL training steps (default: 50000)CC_BOM_DEFAULT_ASSEMBLIES: Synthetic BOM count (default: 5)CC_CTB_DEFAULT_BUILD_QTY: Default build quantity for CTB (default: 100)
pytest tests/ -v --tb=short # All tests
pytest tests/test_optimization/ # CP-SAT tests only
pytest tests/test_rl/ # RL inventory tests
pytest tests/test_bom/ # BOM tests
pytest tests/test_ctb/ # CTB tests
pytest tests/test_risk/ # Risk scoring tests- Always JSON-serialize datetime objects and numpy types before sending through WebSocket.
- After editing Python files, verify syntax with
python -m py_compile <file>. - Run
pytest tests/ -vafter code changes, not as a final step.
Core deps always installed. Optional groups:
pip install -e ".[ortools]"— OR-Tools CP-SATpip install -e ".[rl]"— Gymnasium + Stable-Baselines3pip install -e ".[all]"— Everything