How naushikmaurya/supply-chain works
Purpose and Entry Points
This repository is an end-to-end inventory-risk engine for quick-commerce dark stores. It turns SKU-warehouse sales, inventory, and lead-time data into risk scores, demand forecasts, simulated stockout outcomes, optimized safety-stock recommendations, and rupee-denominated impact.
Primary execution paths:
• Full batch pipeline: run_pipeline.py
• Interactive analytics UI: dashboard/app.py
• Synthetic source-data generation: src/generate_data.py
Data Foundation and Persistence
Raw operational inputs are CSVs in data/sales.csv, data/inventory.csv, data/skus.csv, and data/warehouses.csv. src/generate_data.py creates the synthetic, parameterized panel when needed.
src/db.py is the ETL and validation boundary: it loads source data into a SQLite schema with warehouse, SKU, sales, and inventory relationships, enforcing referential integrity before analytical stages consume the data. SQLite is the internal system-of-record/runtime boundary; CSVs are both source and published-result formats.
Risk Metrics Layer
src/risk_metrics.py computes descriptive operational risk by SKU and warehouse: customer service level, demand and lead-time variability, RPN, and stockout/excess risk indicators. This stage converts validated historical state into interpretable baseline risk features.
Its output feeds forecast and decision stages and is represented for downstream consumption in outputs/risk_table.csv.
Forecasting Layer
src/forecasting.py produces per-SKU/warehouse demand projections using Holt-Winters time-series forecasting. It supplies forward demand means and uncertainty rather than relying exclusively on trailing averages.
The forecast boundary is intentionally separable from later stages: optimization consumes demand distribution parameters rather than being coupled to Holt-Winters implementation. Published forecasts reside in outputs/forecast_table.csv.
Simulation Layer
src/simulation.py models replenishment risk with Monte Carlo sampling over stochastic demand and lead time. For each SKU-warehouse policy, it estimates stockout probability, expected stockout units, excess inventory, and distributional outcomes.
This is the key bridge from abstract risk measures and forecasts to operational failure likelihoods. Simulation results are materialized in outputs/simulation_table.csv for optimization and dashboard comparison.
Safety-Stock Optimization
src/optimization.py searches safety-stock candidates against holding and stockout costs. The current stock policy is included as a candidate, creating a no-regret constraint: recommendations cannot be worse than the status quo under the modeled cost function.
The optimized policy and before/after measures are persisted to outputs/optimization_table.csv. This stage is the decision boundary: earlier modules estimate risk, while this module selects an inventory action.
Financial Translation and Interface
src/financial_impact.py converts simulated and optimized policy outcomes into holding cost, lost-margin stockout cost, net savings, and annualized financial impact. Its business-facing output is outputs/financial_impact_table.csv.
dashboard/app.py is a Streamlit interface over the generated outputs, presenting fleet risk, optimized-versus-baseline comparisons, category views, and interactive stress/what-if analysis. It is a read/presentation layer over batch-produced analytical artifacts, not the core pipeline executor.
Runtime and Dependencies
The system runs as Python batch jobs plus a Streamlit application. Major analytical capabilities include SQLite ETL, classical time-series forecasting, numerical Monte Carlo simulation, and grid-search optimization. It has no stated external production API dependency; the dataset is generated locally and all published artifacts are local CSVs.
Main entry points: db.py Validated SQLite Store · run_pipeline.py Batch Pipeline · simulation.py Replenishment Simulation · risk_metrics.py Risk Metrics
Components 18
Data Foundation
- Synthetic Data Generator · Creates the local parameterized operational panel.
src/generate_data.py - Sales Data
data/sales.csv - Inventory Data
data/inventory.csv - SKU Master
data/skus.csv - Warehouse Master
data/warehouses.csv - Validated SQLite Store · Loads relational source data and enforces referential integrity.
src/db.py
Batch Analytics
- Batch Pipeline · Orchestrates the end-to-end analytical run.
run_pipeline.py - Risk Metrics · Computes service, variability, RPN, stockout, and excess indicators.
src/risk_metrics.py - Demand Forecasting · Produces SKU-warehouse demand means and uncertainty.
src/forecasting.py - Replenishment Simulation · Estimates stockout, excess, and distributional policy outcomes.
src/simulation.py - Safety-Stock Optimizer · Selects a no-worse-than-current policy under modeled costs.
src/optimization.py - Financial Impact · Converts policy outcomes into savings and annualized rupee impact.
src/financial_impact.py
Published Artifacts
- Risk Table
outputs/risk_table.csv - Forecast Table
outputs/forecast_table.csv - Simulation Table
outputs/simulation_table.csv - Optimization Table
outputs/optimization_table.csv - Financial Impact Table
outputs/financial_impact_table.csv
Other components
- Analytics Dashboard · Presents risk, comparisons, category views, and what-if analysis.
dashboard/app.py
Connections 32
- Synthetic Data Generator → Sales Data: generates
- Synthetic Data Generator → Inventory Data: generates
- Synthetic Data Generator → SKU Master: generates
- Synthetic Data Generator → Warehouse Master: generates
- Sales Data → Validated SQLite Store: loads
- Inventory Data → Validated SQLite Store: loads
- SKU Master → Validated SQLite Store: loads
- Warehouse Master → Validated SQLite Store: loads
- Validated SQLite Store → Risk Metrics: validated history
- Validated SQLite Store → Demand Forecasting: demand history
- Risk Metrics → Demand Forecasting: risk features
- Risk Metrics → Replenishment Simulation: baseline risk
- Demand Forecasting → Replenishment Simulation: demand distribution
- Replenishment Simulation → Safety-Stock Optimizer: policy outcomes
- Safety-Stock Optimizer → Financial Impact: optimized policy
- Replenishment Simulation → Financial Impact: baseline outcomes
- Risk Metrics → Risk Table: publishes
- Demand Forecasting → Forecast Table: publishes
- Replenishment Simulation → Simulation Table: publishes
- Safety-Stock Optimizer → Optimization Table: publishes
- Financial Impact → Financial Impact Table: publishes
- Risk Table → Analytics Dashboard: reads
- Forecast Table → Analytics Dashboard: reads
- Simulation Table → Analytics Dashboard: reads
- Optimization Table → Analytics Dashboard: reads
- Financial Impact Table → Analytics Dashboard: reads
- Batch Pipeline → Validated SQLite Store: runs
- Batch Pipeline → Risk Metrics: runs
- Batch Pipeline → Demand Forecasting: runs
- Batch Pipeline → Replenishment Simulation: runs
- Batch Pipeline → Safety-Stock Optimizer: runs
- Batch Pipeline → Financial Impact: runs