# naushikmaurya/supply-chain architecture

> Architecture diagram of the GitHub repository naushikmaurya/supply-chain, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/naushikmaurya/supply-chain
- Repository: https://github.com/naushikmaurya/supply-chain

## Overview

#### 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: [`src/db.py`](https://github.com/naushikmaurya/supply-chain/blob/main/src/db.py) (Validated SQLite Store), [`run_pipeline.py`](https://github.com/naushikmaurya/supply-chain/blob/main/run_pipeline.py) (Batch Pipeline), [`src/simulation.py`](https://github.com/naushikmaurya/supply-chain/blob/main/src/simulation.py) (Replenishment Simulation), [`src/risk_metrics.py`](https://github.com/naushikmaurya/supply-chain/blob/main/src/risk_metrics.py) (Risk Metrics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data Foundation"]
  node_generator["Synthetic Data Generator<br/>Python job<br/>[generate_data.py]"]
  node_sales_csv["Sales Data<br/>raw CSV<br/>[sales.csv]"]
  node_inventory_csv["Inventory Data<br/>raw CSV<br/>[inventory.csv]"]
  node_skus_csv["SKU Master<br/>raw CSV<br/>[skus.csv]"]
  node_warehouses_csv["Warehouse Master<br/>raw CSV<br/>[warehouses.csv]"]
  node_etl_db[("Validated SQLite Store<br/>[db.py]")]
end

subgraph group_analytics["Batch Analytics"]
  node_pipeline{{"Batch Pipeline<br/>Python entry point<br/>[run_pipeline.py]"}}
  node_risk_metrics["Risk Metrics<br/>risk feature computation<br/>[risk_metrics.py]"]
  node_forecasting["Demand Forecasting<br/>Holt-Winters forecasting<br/>[forecasting.py]"]
  node_simulation["Replenishment Simulation<br/>Monte Carlo simulation<br/>[simulation.py]"]
  node_optimization["Safety-Stock Optimizer<br/>grid-search decision engine<br/>[optimization.py]"]
  node_financial["Financial Impact<br/>cost translation"]
end

subgraph group_outputs["Published Artifacts"]
  node_risk_output["Risk Table<br/>published CSV<br/>[risk_table.csv]"]
  node_forecast_output["Forecast Table<br/>published CSV<br/>[forecast_table.csv]"]
  node_simulation_output["Simulation Table<br/>published CSV"]
  node_optimization_output["Optimization Table<br/>published CSV"]
  node_financial_output["Financial Impact Table<br/>published CSV"]
end

node_dashboard["Analytics Dashboard<br/>Streamlit UI<br/>[app.py]"]

node_generator -->|"generates"| node_sales_csv
node_generator -->|"generates"| node_inventory_csv
node_generator -->|"generates"| node_skus_csv
node_generator -->|"generates"| node_warehouses_csv
node_sales_csv -->|"loads"| node_etl_db
node_inventory_csv -->|"loads"| node_etl_db
node_skus_csv -->|"loads"| node_etl_db
node_warehouses_csv -->|"loads"| node_etl_db
node_etl_db -->|"validated history"| node_risk_metrics
node_etl_db -->|"demand history"| node_forecasting
node_risk_metrics -->|"risk features"| node_forecasting
node_risk_metrics -->|"baseline risk"| node_simulation
node_forecasting -->|"demand distribution"| node_simulation
node_simulation -->|"policy outcomes"| node_optimization
node_optimization -->|"optimized policy"| node_financial
node_simulation -->|"baseline outcomes"| node_financial
node_risk_metrics -->|"publishes"| node_risk_output
node_forecasting -->|"publishes"| node_forecast_output
node_simulation -->|"publishes"| node_simulation_output
node_optimization -->|"publishes"| node_optimization_output
node_financial -->|"publishes"| node_financial_output
node_risk_output -->|"reads"| node_dashboard
node_forecast_output -->|"reads"| node_dashboard
node_simulation_output -->|"reads"| node_dashboard
node_optimization_output -->|"reads"| node_dashboard
node_financial_output -->|"reads"| node_dashboard
node_pipeline -.->|"runs"| node_etl_db
node_pipeline -.->|"runs"| node_risk_metrics
node_pipeline -.->|"runs"| node_forecasting
node_pipeline -.->|"runs"| node_simulation
node_pipeline -.->|"runs"| node_optimization
node_pipeline -.->|"runs"| node_financial

click node_pipeline "https://github.com/naushikmaurya/supply-chain/blob/main/run_pipeline.py"
click node_generator "https://github.com/naushikmaurya/supply-chain/blob/main/src/generate_data.py"
click node_sales_csv "https://github.com/naushikmaurya/supply-chain/blob/main/data/sales.csv"
click node_inventory_csv "https://github.com/naushikmaurya/supply-chain/blob/main/data/inventory.csv"
click node_skus_csv "https://github.com/naushikmaurya/supply-chain/blob/main/data/skus.csv"
click node_warehouses_csv "https://github.com/naushikmaurya/supply-chain/blob/main/data/warehouses.csv"
click node_etl_db "https://github.com/naushikmaurya/supply-chain/blob/main/src/db.py"
click node_risk_metrics "https://github.com/naushikmaurya/supply-chain/blob/main/src/risk_metrics.py"
click node_forecasting "https://github.com/naushikmaurya/supply-chain/blob/main/src/forecasting.py"
click node_simulation "https://github.com/naushikmaurya/supply-chain/blob/main/src/simulation.py"
click node_optimization "https://github.com/naushikmaurya/supply-chain/blob/main/src/optimization.py"
click node_financial "https://github.com/naushikmaurya/supply-chain/blob/main/src/financial_impact.py"
click node_risk_output "https://github.com/naushikmaurya/supply-chain/blob/main/outputs/risk_table.csv"
click node_forecast_output "https://github.com/naushikmaurya/supply-chain/blob/main/outputs/forecast_table.csv"
click node_simulation_output "https://github.com/naushikmaurya/supply-chain/blob/main/outputs/simulation_table.csv"
click node_optimization_output "https://github.com/naushikmaurya/supply-chain/blob/main/outputs/optimization_table.csv"
click node_financial_output "https://github.com/naushikmaurya/supply-chain/blob/main/outputs/financial_impact_table.csv"
click node_dashboard "https://github.com/naushikmaurya/supply-chain/blob/main/dashboard/app.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_generator,node_sales_csv,node_inventory_csv,node_skus_csv,node_warehouses_csv,node_etl_db toneBlue
class node_pipeline,node_risk_metrics,node_forecasting,node_simulation,node_optimization,node_financial toneAmber
class node_risk_output,node_forecast_output,node_simulation_output,node_optimization_output,node_financial_output toneMint
class node_dashboard toneNeutral
```

## Components

### Data Foundation

- [Synthetic Data Generator](https://github.com/naushikmaurya/supply-chain/blob/main/src/generate_data.py): Python job · Creates the local parameterized operational panel. · `src/generate_data.py`
- [Sales Data](https://github.com/naushikmaurya/supply-chain/blob/main/data/sales.csv): raw CSV · `data/sales.csv`
- [Inventory Data](https://github.com/naushikmaurya/supply-chain/blob/main/data/inventory.csv): raw CSV · `data/inventory.csv`
- [SKU Master](https://github.com/naushikmaurya/supply-chain/blob/main/data/skus.csv): raw CSV · `data/skus.csv`
- [Warehouse Master](https://github.com/naushikmaurya/supply-chain/blob/main/data/warehouses.csv): raw CSV · `data/warehouses.csv`
- [Validated SQLite Store](https://github.com/naushikmaurya/supply-chain/blob/main/src/db.py): ETL and system of record · Loads relational source data and enforces referential integrity. · `src/db.py`

### Batch Analytics

- [Batch Pipeline](https://github.com/naushikmaurya/supply-chain/blob/main/run_pipeline.py): Python entry point · Orchestrates the end-to-end analytical run. · `run_pipeline.py`
- [Risk Metrics](https://github.com/naushikmaurya/supply-chain/blob/main/src/risk_metrics.py): risk feature computation · Computes service, variability, RPN, stockout, and excess indicators. · `src/risk_metrics.py`
- [Demand Forecasting](https://github.com/naushikmaurya/supply-chain/blob/main/src/forecasting.py): Holt-Winters forecasting · Produces SKU-warehouse demand means and uncertainty. · `src/forecasting.py`
- [Replenishment Simulation](https://github.com/naushikmaurya/supply-chain/blob/main/src/simulation.py): Monte Carlo simulation · Estimates stockout, excess, and distributional policy outcomes. · `src/simulation.py`
- [Safety-Stock Optimizer](https://github.com/naushikmaurya/supply-chain/blob/main/src/optimization.py): grid-search decision engine · Selects a no-worse-than-current policy under modeled costs. · `src/optimization.py`
- [Financial Impact](https://github.com/naushikmaurya/supply-chain/blob/main/src/financial_impact.py): cost translation · Converts policy outcomes into savings and annualized rupee impact. · `src/financial_impact.py`

### Published Artifacts

- [Risk Table](https://github.com/naushikmaurya/supply-chain/blob/main/outputs/risk_table.csv): published CSV · `outputs/risk_table.csv`
- [Forecast Table](https://github.com/naushikmaurya/supply-chain/blob/main/outputs/forecast_table.csv): published CSV · `outputs/forecast_table.csv`
- [Simulation Table](https://github.com/naushikmaurya/supply-chain/blob/main/outputs/simulation_table.csv): published CSV · `outputs/simulation_table.csv`
- [Optimization Table](https://github.com/naushikmaurya/supply-chain/blob/main/outputs/optimization_table.csv): published CSV · `outputs/optimization_table.csv`
- [Financial Impact Table](https://github.com/naushikmaurya/supply-chain/blob/main/outputs/financial_impact_table.csv): published CSV · `outputs/financial_impact_table.csv`

### Other components

- [Analytics Dashboard](https://github.com/naushikmaurya/supply-chain/blob/main/dashboard/app.py): Streamlit UI · Presents risk, comparisons, category views, and what-if analysis. · `dashboard/app.py`

## Connections

- 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
