# pmduck486/shelfwise-stock-optimiser architecture

> Architecture diagram of the GitHub repository pmduck486/shelfwise-stock-optimiser, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pmduck486/shelfwise-stock-optimiser
- Repository: https://github.com/pmduck486/shelfwise-stock-optimiser

## Overview

ShelfWise prepares Walmart M5 data, forecasts store-item demand at several quantiles, converts forecasts into replenishment decisions, and evaluates those decisions through day-by-day replay. Its dashboard presents replay results, day-level decisions, forecast exploration, and LP shadow-price what-ifs. The README documents the end-to-end stages; source excerpts confirm key replay, forecasting, and dashboard wiring. Several forecast and dashboard pages were not sampled, so their internal relationships are limited to documented capabilities.

Main entry points: [`replay/engine.py`](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/replay/engine.py) (Daily replay), [`replay/store_model.py`](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/replay/store_model.py) (Newsvendor targets), [`dashboard/src/App.tsx`](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/dashboard/src/App.tsx) (Dashboard application), [`data_prep/prepare.py`](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/data_prep/prepare.py) (Data preparation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_prep["Data preparation<br/>[prepare.py]"]
end

subgraph group_forecast["Demand forecasting"]
  node_forecast_data["Forecast data<br/>[data.py]"]
  node_features["Feature engineering<br/>[features.py]"]
  node_quantile_model["Quantile models<br/>[model.py]"]
  node_calibration["Calibration and freeze<br/>[calibrate.py]"]
end

subgraph group_orders["Ordering and replay"]
  node_targets["Newsvendor targets<br/>[store_model.py]"]
  node_store_ilp["Store order ILP<br/>[store_ilp.py]"]
  node_shadow_prices["LP shadow prices<br/>[store_ilp.py]"]
  node_baselines["Ordering baselines<br/>[baselines.py]"]
  node_replay["Daily replay<br/>[engine.py]"]
  node_day_physics["Inventory accounting<br/>[replay.py]"]
  node_replay_checks["Replay checks and KPIs<br/>[kpis.py]"]
end

subgraph group_dashboard["Results dashboard"]
  node_export["Dashboard data export<br/>[export_data.py]"]
  node_dashboard_data["Dashboard data loading<br/>[data.ts]"]
  node_app["Dashboard application<br/>[App.tsx]"]
  node_day_page["Day decision view<br/>[DayDetail.tsx]"]
  node_shadow_page["Shadow price view<br/>[Shadow.tsx]"]
end

node_m5[("Walmart M5 data")]

node_m5 -->|"provides sales"| node_prep
node_prep -->|"prepares inputs"| node_forecast_data
node_forecast_data -->|"supplies sales"| node_features
node_features -->|"feeds features"| node_quantile_model
node_quantile_model -->|"calibrates forecasts"| node_calibration
node_calibration -->|"informs targets"| node_targets
node_targets -->|"sets order targets"| node_store_ilp
node_store_ilp -->|"relaxes cartons"| node_shadow_prices
node_targets -->|"provides decisions"| node_replay
node_baselines -->|"provides alternatives"| node_replay
node_replay -->|"executes decisions"| node_day_physics
node_replay -->|"checks ledger"| node_replay_checks
node_replay_checks -->|"supplies results"| node_export
node_export -->|"writes dashboard data"| node_dashboard_data
node_dashboard_data -->|"loads JSON"| node_app
node_app -->|"renders page"| node_day_page
node_app -->|"renders page"| node_shadow_page

click node_prep "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/data_prep/prepare.py"
click node_forecast_data "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/forecast/data.py"
click node_features "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/forecast/features.py"
click node_quantile_model "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/forecast/model.py"
click node_calibration "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/forecast/calibrate.py"
click node_targets "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/replay/store_model.py"
click node_store_ilp "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/analysis/store_ilp.py"
click node_shadow_prices "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/analysis/store_ilp.py"
click node_baselines "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/replay/baselines.py"
click node_replay "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/replay/engine.py"
click node_day_physics "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/optimize/replay.py"
click node_replay_checks "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/replay/kpis.py"
click node_export "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/dashboard/export_data.py"
click node_dashboard_data "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/dashboard/src/lib/data.ts"
click node_app "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/dashboard/src/App.tsx"
click node_day_page "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/dashboard/src/pages/DayDetail.tsx"
click node_shadow_page "https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/dashboard/src/pages/Shadow.tsx"

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_prep toneBlue
class node_forecast_data,node_features,node_quantile_model,node_calibration,node_m5 toneAmber
class node_targets,node_store_ilp,node_shadow_prices,node_baselines,node_replay,node_day_physics,node_replay_checks toneMint
class node_export,node_dashboard_data,node_app,node_day_page,node_shadow_page toneRose
```

## Components

### Data preparation

- [Data preparation](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/data_prep/prepare.py): `data_prep/prepare.py`

### Demand forecasting

- [Forecast data](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/forecast/data.py): `forecast/data.py`
- [Feature engineering](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/forecast/features.py): `forecast/features.py`
- [Quantile models](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/forecast/model.py): `forecast/model.py`
- [Calibration and freeze](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/forecast/calibrate.py): `forecast/calibrate.py`

### Ordering and replay

- [Newsvendor targets](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/replay/store_model.py): `replay/store_model.py`
- [Store order ILP](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/analysis/store_ilp.py): `analysis/store_ilp.py`
- [LP shadow prices](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/analysis/store_ilp.py): `analysis/store_ilp.py`
- [Ordering baselines](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/replay/baselines.py): `replay/baselines.py`
- [Daily replay](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/replay/engine.py): `replay/engine.py`
- [Inventory accounting](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/optimize/replay.py): `optimize/replay.py`
- [Replay checks and KPIs](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/replay/kpis.py): `replay/kpis.py`

### Results dashboard

- [Dashboard data export](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/dashboard/export_data.py): `dashboard/export_data.py`
- [Dashboard data loading](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/dashboard/src/lib/data.ts): `dashboard/src/lib/data.ts`
- [Dashboard application](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/dashboard/src/App.tsx): `dashboard/src/App.tsx`
- [Day decision view](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/dashboard/src/pages/DayDetail.tsx): `dashboard/src/pages/DayDetail.tsx`
- [Shadow price view](https://github.com/pmduck486/shelfwise-stock-optimiser/blob/main/dashboard/src/pages/Shadow.tsx): `dashboard/src/pages/Shadow.tsx`

### Other components

- **Walmart M5 data**

## Connections

- Walmart M5 data → Data preparation: provides sales (evidence: `README.md`)
- Data preparation → Forecast data: prepares inputs (evidence: `forecast/data.py`)
- Forecast data → Feature engineering: supplies sales (evidence: `forecast/features.py`)
- Feature engineering → Quantile models: feeds features (evidence: `README.md`)
- Quantile models → Calibration and freeze: calibrates forecasts (evidence: `README.md`)
- Calibration and freeze → Newsvendor targets: informs targets (evidence: `README.md`)
- Newsvendor targets → Store order ILP: sets order targets (evidence: `replay/store_model.py`)
- Store order ILP → LP shadow prices: relaxes cartons (evidence: `README.md`)
- Newsvendor targets → Daily replay: provides decisions (evidence: `README.md`)
- Ordering baselines → Daily replay: provides alternatives (evidence: `replay/engine.py`)
- Daily replay → Inventory accounting: executes decisions (evidence: `replay/engine.py`)
- Daily replay → Replay checks and KPIs: checks ledger (evidence: `replay/engine.py`)
- Replay checks and KPIs → Dashboard data export: supplies results (evidence: `README.md`)
- Dashboard data export → Dashboard data loading: writes dashboard data (evidence: `README.md`)
- Dashboard data loading → Dashboard application: loads JSON
- Dashboard application → Day decision view: renders page (evidence: `dashboard/src/App.tsx`)
- Dashboard application → Shadow price view: renders page (evidence: `dashboard/src/App.tsx`)
