# lala850307-glitch/retail-workforce-planner architecture

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

- Interactive diagram: https://gitdiagram.com/lala850307-glitch/retail-workforce-planner
- Repository: https://github.com/lala850307-glitch/retail-workforce-planner

## Overview

1. **What this repo is**
   - `Retail-Workforce-Planner` is a Python-based workforce planning application for retail staffing.
   - The repo combines a lightweight web UI, forecasting/audit logic, and offline model/data-generation scripts.

2. **Top-level application entry**
   - `main.py` is the likely application entrypoint and orchestration layer.
   - It probably wires the web pages to the backend services in `api/` and serves the templates in `templates/`.

3. **Presentation layer**
   - `templates/index.html` appears to be the landing page.
   - `templates/smart_staffing_forecast.html` is the main forecasting UI.
   - `templates/Labor Efficiency Audit.html` is the audit/reporting UI.
   - `api/retail.js` suggests client-side behavior for the pages, likely handling form interactions, visual updates, or async requests.

4. **Forecasting service boundary**
   - `api/forecast_service.py` is the core runtime forecasting layer.
   - It likely loads the trained staffing model and feature metadata, transforms input store/workload data, and produces staffing recommendations or demand forecasts.
   - This is the main boundary between the UI and the predictive model artifacts.

5. **Audit/analysis service boundary**
   - `api/audit_service.py` likely evaluates labor efficiency or staffing quality against expected demand.
   - It probably consumes forecast outputs or operational inputs to produce audit-style insights for the “Labor Efficiency Audit” page.
   - This is a second business workflow separate from the main forecast flow.

6. **Model artifacts**
   - `models/retail_staffing_model_v1.pkl` is the saved trained model.
   - `models/feature_columns.pkl` stores the expected input feature schema used at inference time.
   - `models/requirements.txt` indicates the model environment has its own dependency set, which is important if training/inference differs from the main app runtime.

7. **Training and offline pipeline**
   - `scripts/model_training_pipeline.py` is the training workflow that likely builds the versioned model artifact.
   - This separates model development from the serving path, so the web app depends on prebuilt `.pkl` outputs rather than retraining on startup.

8. **Forecast generation pipeline**
   - `scripts/q2_forecast_engine.py` appears to generate a quarterly forecast batch, likely using the trained model and operational assumptions.
   - The generated output is stored in `output_data/2026_Q2_Hybrid_Forecast.csv`, which suggests an offline batch artifact consumed for reporting or download.

9. **Synthetic/master data generation**
   - `data_scripts/gen_master_data.py` likely creates the canonical input dataset used for training or simulation.
   - `data_scripts/gen_2025_ops.py` and `data_scripts/gen_2026_ops.py` appear to generate operational scenarios for specific planning periods.
   - `scripts/data_simulator_2026.py` suggests simulated 2026 operational inputs used to drive forecasts or testing.

10. **Data flow across the repo**
   - The offline path is: generated/master data and simulated operations → training pipeline → saved model and feature list → forecast engine → CSV outputs.
   - The online path is: user interacts with HTML/JS UI → `main.py` routes to `api/forecast_service.py` or `api/audit_service.py` → results are rendered back to the templates.

11. **Key architectural boundary**
   - The most important separation is between **serving** and **offline analytics**.
   - Runtime web requests should depend only on precomputed artifacts in `models/` and `output_data/`, while training and scenario generation live in `scripts/` and `data_scripts/`.

12. **What to show in an architecture diagram**
   - Draw three main zones: UI/templates, API/service layer, and offline ML/data pipelines.
   - Show the model artifact store as a shared dependency between the training pipeline and forecast service.
   - Show CSV output as a batch artifact produced by forecast scripts, not as a live database or external service.

Main entry points: [`main.py`](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/main.py) (Main app), [`scripts/model_training_pipeline.py`](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/scripts/model_training_pipeline.py) (Training pipeline), [`scripts/q2_forecast_engine.py`](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/scripts/q2_forecast_engine.py) (Batch forecast), [`api/forecast_service.py`](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/api/forecast_service.py) (Forecast API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Presentation"]
  node_index_page["Home page<br/>template<br/>[index.html]"]
  node_forecast_page["Forecast UI<br/>template"]
  node_audit_page["Audit UI<br/>template"]
  node_retail_js["Browser JS<br/>client script<br/>[retail.js]"]
end

subgraph group_services["Runtime Services"]
  node_main["Main app<br/>entrypoint<br/>[main.py]"]
  node_forecast_service["Forecast API"]
  node_audit_service["Audit API<br/>[audit_service.py]"]
end

subgraph group_offline["Offline Pipelines"]
  node_train_pipeline["Training pipeline<br/>ml pipeline"]
  node_forecast_engine["Batch forecast<br/>batch job"]
  node_data_simulator["Data simulator"]
  node_master_data["Master data<br/>data generator<br/>[gen_master_data.py]"]
  node_ops_2025["2025 ops<br/>data generator<br/>[gen_2025_ops.py]"]
  node_ops_2026["2026 ops<br/>data generator<br/>[gen_2026_ops.py]"]
end

subgraph group_artifacts["Model Artifacts"]
  node_model_file[("Model pickle<br/>artifact")]
  node_feature_file[("Feature schema<br/>artifact")]
  node_output_csv["Forecast CSV<br/>batch output"]
end

node_main -->|"serves"| node_index_page
node_main -->|"serves"| node_forecast_page
node_main -->|"serves"| node_audit_page
node_forecast_page -->|"uses"| node_retail_js
node_audit_page -->|"uses"| node_retail_js
node_main -->|"calls"| node_forecast_service
node_main -->|"calls"| node_audit_service
node_forecast_service -->|"loads"| node_model_file
node_forecast_service -->|"loads"| node_feature_file
node_audit_service -.->|"reuses"| node_forecast_service
node_train_pipeline -->|"trains on"| node_master_data
node_train_pipeline -->|"ingests"| node_ops_2025
node_train_pipeline -->|"ingests"| node_ops_2026
node_train_pipeline -->|"writes"| node_model_file
node_train_pipeline -->|"writes"| node_feature_file
node_data_simulator -->|"generates"| node_ops_2026
node_forecast_engine -->|"uses"| node_model_file
node_forecast_engine -->|"uses"| node_feature_file
node_forecast_engine -->|"produces"| node_output_csv
node_forecast_engine -.->|"consumes"| node_data_simulator

click node_main "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/main.py"
click node_forecast_service "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/api/forecast_service.py"
click node_audit_service "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/api/audit_service.py"
click node_index_page "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/templates/index.html"
click node_forecast_page "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/templates/smart_staffing_forecast.html"
click node_audit_page "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/templates/Labor Efficiency Audit.html"
click node_retail_js "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/api/retail.js"
click node_train_pipeline "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/scripts/model_training_pipeline.py"
click node_forecast_engine "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/scripts/q2_forecast_engine.py"
click node_data_simulator "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/scripts/data_simulator_2026.py"
click node_master_data "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/data_scripts/gen_master_data.py"
click node_ops_2025 "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/data_scripts/gen_2025_ops.py"
click node_ops_2026 "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/data_scripts/gen_2026_ops.py"
click node_model_file "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/models/retail_staffing_model_v1.pkl"
click node_feature_file "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/models/feature_columns.pkl"
click node_output_csv "https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/output_data/2026_Q2_Hybrid_Forecast.csv"

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_index_page,node_forecast_page,node_audit_page,node_retail_js toneBlue
class node_main,node_forecast_service,node_audit_service toneAmber
class node_train_pipeline,node_forecast_engine,node_data_simulator,node_master_data,node_ops_2025,node_ops_2026 toneMint
class node_model_file,node_feature_file,node_output_csv toneRose
```

## Components

### Presentation

Web pages and client-side interactions for staffing and audit workflows.

- [Home page](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/templates/index.html): template · Landing page for the application. · `templates/index.html`
- [Forecast UI](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/templates/smart_staffing_forecast.html): template · Primary staffing forecast user interface. · `templates/smart_staffing_forecast.html`
- [Audit UI](https://github.com/lala850307-glitch/retail-workforce-planner/blob/HEAD/templates/Labor%20Efficiency%20Audit.html): template · Labor efficiency audit and reporting page. · `templates/Labor Efficiency Audit.html`
- [Browser JS](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/api/retail.js): client script · Client-side behavior for the web pages, including interaction and async updates. · `api/retail.js`

### Runtime Services

Application entrypoint and request-time business logic.

- [Main app](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/main.py): entrypoint · Application entrypoint that wires the UI to backend services. · `main.py`
- [Forecast API](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/api/forecast_service.py): service · Runtime forecasting boundary that prepares inputs and produces staffing recommendations. · `api/forecast_service.py`
- [Audit API](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/api/audit_service.py): service · Runtime labor-efficiency analysis service for audit-style reporting. · `api/audit_service.py`

### Offline Pipelines

Training, simulation, and batch forecast generation outside the web app.

- [Training pipeline](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/scripts/model_training_pipeline.py): ml pipeline · Offline workflow that builds the versioned staffing model artifact. · `scripts/model_training_pipeline.py`
- [Batch forecast](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/scripts/q2_forecast_engine.py): batch job · Offline quarterly forecast generation workflow. · `scripts/q2_forecast_engine.py`
- [Data simulator](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/scripts/data_simulator_2026.py): simulator · Generates simulated 2026 operational inputs for forecasting and testing. · `scripts/data_simulator_2026.py`
- [Master data](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/data_scripts/gen_master_data.py): data generator · Creates canonical training or planning datasets. · `data_scripts/gen_master_data.py`
- [2025 ops](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/data_scripts/gen_2025_ops.py): data generator · Generates 2025 operational planning scenarios. · `data_scripts/gen_2025_ops.py`
- [2026 ops](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/data_scripts/gen_2026_ops.py): data generator · Generates 2026 operational planning scenarios. · `data_scripts/gen_2026_ops.py`

### Model Artifacts

Persisted model inputs and outputs shared between offline and runtime flows.

- [Model pickle](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/models/retail_staffing_model_v1.pkl): artifact · Saved trained staffing model used at inference time. · `models/retail_staffing_model_v1.pkl`
- [Feature schema](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/models/feature_columns.pkl): artifact · Persisted feature-column list required by the model at inference time. · `models/feature_columns.pkl`
- [Forecast CSV](https://github.com/lala850307-glitch/retail-workforce-planner/blob/main/output_data/2026_Q2_Hybrid_Forecast.csv): batch output · Generated quarterly forecast output artifact. · `output_data/2026_Q2_Hybrid_Forecast.csv`

## Connections

- Main app → Home page: serves · Routes users to the landing page.
- Main app → Forecast UI: serves · Renders the staffing forecast experience.
- Main app → Audit UI: serves · Renders the audit experience.
- Forecast UI → Browser JS: uses · Forecast UI depends on browser-side interactions.
- Audit UI → Browser JS: uses · Audit UI depends on browser-side interactions.
- Main app → Forecast API: calls · Application entrypoint dispatches forecast requests.
- Main app → Audit API: calls · Application entrypoint dispatches audit requests.
- Forecast API → Model pickle: loads · Inference service loads the trained staffing model.
- Forecast API → Feature schema: loads · Inference service loads expected feature metadata.
- Audit API → Forecast API: reuses · Audit analysis can build on forecast outputs or logic.
- Training pipeline → Master data: trains on · Training pipeline consumes canonical datasets.
- Training pipeline → 2025 ops: ingests · Uses operational scenarios as training inputs.
- Training pipeline → 2026 ops: ingests · Can incorporate planning scenarios for model development.
- Training pipeline → Model pickle: writes · Produces the versioned model artifact.
- Training pipeline → Feature schema: writes · Persists the feature schema used at inference time.
- Data simulator → 2026 ops: generates · Produces simulated 2026 operational inputs.
- Batch forecast → Model pickle: uses · Batch forecast workflow relies on the trained model.
- Batch forecast → Feature schema: uses · Batch forecast workflow relies on feature metadata.
- Batch forecast → Forecast CSV: produces · Writes the quarterly forecast artifact.
- Batch forecast → Data simulator: consumes · May consume simulated operational inputs.
