# aiwithfahad/smart-retail-ml architecture

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

- Interactive diagram: https://gitdiagram.com/aiwithfahad/smart-retail-ml
- Repository: https://github.com/aiwithfahad/smart-retail-ml

## Overview

Smart Retail ML is a FastAPI dashboard for retail anomaly detection, demand forecasting, model experimentation, edge inference, and invoice OCR. Users authenticate, then operate these features through the browser dashboard and receive predictions, job results, or stored history. The map separates API orchestration, ML capabilities, persistence, and the browser client. Some route implementations and ML internals were not sampled, so those capability links are grounded in README documentation rather than inferred call chains.

Main entry points: [`app.py`](https://github.com/aiwithfahad/smart-retail-ml/blob/main/app.py) (FastAPI API), [`models`](https://github.com/aiwithfahad/smart-retail-ml/tree/main/models) (Model Artifacts), [`frontend/script.js`](https://github.com/aiwithfahad/smart-retail-ml/blob/main/frontend/script.js) (Dashboard UI), [`ml.py`](https://github.com/aiwithfahad/smart-retail-ml/blob/main/ml.py) (Anomaly Scoring)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Dashboard"]
  node_dashboard["Dashboard UI<br/>[script.js]"]
end

subgraph group_api["API and Identity"]
  node_api["FastAPI API<br/>[app.py]"]
  node_auth["JWT Auth<br/>[auth.py]"]
end

subgraph group_ml["ML Capabilities"]
  node_anomaly["Anomaly Scoring<br/>[ml.py]"]
  node_forecast["Demand Forecasting<br/>[ml.py]"]
  node_registry["Model Versions and A/B<br/>[ml.py]"]
  node_edge["Edge Inference<br/>[ml.py]"]
  node_vision["Invoice OCR<br/>[ml.py]"]
  node_automl["AutoML Search<br/>[ml.py]"]
  node_ocrdata["OCR Dataset"]
  node_models["Model Artifacts"]
end

subgraph group_data["Persistence"]
  node_store[("Retail Database<br/>[database.py]")]
  node_anomalyrecords[("Anomaly History<br/>[database.py]")]
  node_visionjobs[("Vision Jobs<br/>[database.py]")]
  node_experiments[("Experiment Leaderboard<br/>[database.py]")]
end

node_user(("User"))

node_user -->|"uses"| node_dashboard
node_dashboard -->|"calls endpoints"| node_api
node_api -->|"registers auth"| node_auth
node_api -->|"scores ticks"| node_anomaly
node_api -.->|"serves forecasts"| node_forecast
node_api -->|"serves model routes"| node_registry
node_api -.->|"serves edge routes"| node_edge
node_api -.->|"queues OCR jobs"| node_vision
node_api -.->|"serves AutoML routes"| node_automl
node_api -->|"queries and writes"| node_store
node_api -->|"stores scores"| node_anomalyrecords
node_api -->|"tracks jobs"| node_visionjobs
node_api -.->|"persists leaderboard"| node_experiments
node_vision -.->|"reads samples"| node_ocrdata
node_anomaly -.->|"loads detector"| node_models
node_forecast -.->|"loads versions"| node_models
node_registry -->|"reads metadata"| node_models
node_edge -.->|"loads inference model"| node_models

click node_dashboard "https://github.com/aiwithfahad/smart-retail-ml/blob/main/frontend/script.js"
click node_api "https://github.com/aiwithfahad/smart-retail-ml/blob/main/app.py"
click node_auth "https://github.com/aiwithfahad/smart-retail-ml/blob/main/auth.py"
click node_anomaly "https://github.com/aiwithfahad/smart-retail-ml/blob/main/ml.py"
click node_forecast "https://github.com/aiwithfahad/smart-retail-ml/blob/main/ml.py"
click node_registry "https://github.com/aiwithfahad/smart-retail-ml/blob/main/ml.py"
click node_edge "https://github.com/aiwithfahad/smart-retail-ml/blob/main/ml.py"
click node_vision "https://github.com/aiwithfahad/smart-retail-ml/blob/main/ml.py"
click node_automl "https://github.com/aiwithfahad/smart-retail-ml/blob/main/ml.py"
click node_ocrdata "https://github.com/aiwithfahad/smart-retail-ml/tree/main/data/raw/vision_ocr"
click node_models "https://github.com/aiwithfahad/smart-retail-ml/tree/main/models"
click node_store "https://github.com/aiwithfahad/smart-retail-ml/blob/main/database.py"
click node_anomalyrecords "https://github.com/aiwithfahad/smart-retail-ml/blob/main/database.py"
click node_visionjobs "https://github.com/aiwithfahad/smart-retail-ml/blob/main/database.py"
click node_experiments "https://github.com/aiwithfahad/smart-retail-ml/blob/main/database.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_dashboard,node_user toneBlue
class node_api,node_auth toneAmber
class node_anomaly,node_forecast,node_registry,node_edge,node_vision,node_automl,node_ocrdata,node_models toneMint
class node_store,node_anomalyrecords,node_visionjobs,node_experiments toneRose
```

## Components

### Dashboard

- [Dashboard UI](https://github.com/aiwithfahad/smart-retail-ml/blob/main/frontend/script.js): `frontend/script.js`

### API and Identity

- [FastAPI API](https://github.com/aiwithfahad/smart-retail-ml/blob/main/app.py): `app.py`
- [JWT Auth](https://github.com/aiwithfahad/smart-retail-ml/blob/main/auth.py): `auth.py`

### ML Capabilities

- [Anomaly Scoring](https://github.com/aiwithfahad/smart-retail-ml/blob/main/ml.py): `ml.py`
- [Demand Forecasting](https://github.com/aiwithfahad/smart-retail-ml/blob/main/ml.py): `ml.py`
- [Model Versions and A/B](https://github.com/aiwithfahad/smart-retail-ml/blob/main/ml.py): `ml.py`
- [Edge Inference](https://github.com/aiwithfahad/smart-retail-ml/blob/main/ml.py): `ml.py`
- [Invoice OCR](https://github.com/aiwithfahad/smart-retail-ml/blob/main/ml.py): `ml.py`
- [AutoML Search](https://github.com/aiwithfahad/smart-retail-ml/blob/main/ml.py): `ml.py`
- [OCR Dataset](https://github.com/aiwithfahad/smart-retail-ml/tree/main/data/raw/vision_ocr): `data/raw/vision_ocr`
- [Model Artifacts](https://github.com/aiwithfahad/smart-retail-ml/tree/main/models): `models`

### Persistence

- [Retail Database](https://github.com/aiwithfahad/smart-retail-ml/blob/main/database.py): `database.py`
- [Anomaly History](https://github.com/aiwithfahad/smart-retail-ml/blob/main/database.py): `database.py`
- [Vision Jobs](https://github.com/aiwithfahad/smart-retail-ml/blob/main/database.py): `database.py`
- [Experiment Leaderboard](https://github.com/aiwithfahad/smart-retail-ml/blob/main/database.py): `database.py`

### Other components

- **User**

## Connections

- User → Dashboard UI: uses (evidence: `README.md`)
- Dashboard UI → FastAPI API: calls endpoints (evidence: `frontend/script.js`)
- FastAPI API → JWT Auth: registers auth (evidence: `app.py`)
- FastAPI API → Anomaly Scoring: scores ticks (evidence: `app.py`)
- FastAPI API → Demand Forecasting: serves forecasts (evidence: `README.md`)
- FastAPI API → Model Versions and A/B: serves model routes (evidence: `app.py`)
- FastAPI API → Edge Inference: serves edge routes (evidence: `README.md`)
- FastAPI API → Invoice OCR: queues OCR jobs (evidence: `README.md`)
- FastAPI API → AutoML Search: serves AutoML routes (evidence: `README.md`)
- FastAPI API → Retail Database: queries and writes (evidence: `app.py`)
- FastAPI API → Anomaly History: stores scores (evidence: `app.py`)
- FastAPI API → Vision Jobs: tracks jobs (evidence: `app.py`)
- FastAPI API → Experiment Leaderboard: persists leaderboard (evidence: `README.md`)
- Invoice OCR → OCR Dataset: reads samples (evidence: `README.md`)
- Anomaly Scoring → Model Artifacts: loads detector (evidence: `README.md`)
- Demand Forecasting → Model Artifacts: loads versions (evidence: `README.md`)
- Model Versions and A/B → Model Artifacts: reads metadata
- Edge Inference → Model Artifacts: loads inference model (evidence: `README.md`)
