# rohitjg13/stupid-apple architecture

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

- Interactive diagram: https://gitdiagram.com/rohitjg13/stupid-apple
- Repository: https://github.com/rohitjg13/stupid-apple

## Overview

Intelligent Retail Analytics is an offline-first, edge-camera retail analytics product. Its main user workflow is uploading overhead and shelf clips in the web wizard, generating a clipset, starting a run, and viewing dashboard results. At runtime, sources feed interchangeable detectors; shopper, shelf, and queue analytics publish events that are persisted and aggregated for the API. The README documents additional POS and multi-store/cloud-aggregate capabilities. Connections for those documented but unsampled integrations are shown only where supported; unsampled implementation details are not inferred.

Main entry points: [`main.py`](https://github.com/rohitjg13/stupid-apple/blob/main/main.py) (Analytics runner), [`shopper/pipeline.py`](https://github.com/rohitjg13/stupid-apple/blob/main/shopper/pipeline.py) (Shopper analytics), [`shelf/pipeline.py`](https://github.com/rohitjg13/stupid-apple/blob/main/shelf/pipeline.py) (Shelf analytics), [`server.py`](https://github.com/rohitjg13/stupid-apple/blob/main/server.py) (Run server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Operator experience"]
  node_web["Wizard and dashboard<br/>[App.svelte]"]
  node_webapi["Web API client<br/>[api.js]"]
  node_server["Run server<br/>[server.py]"]
  node_autoconfig["Clipset generation<br/>[autoconfig.py]"]
end

subgraph group_runtime["Capture and inference"]
  node_config["Clipset configuration<br/>[config.py]"]
  node_main["Analytics runner<br/>[main.py]"]
  node_sources["Video sources"]
  node_frame["Frame contract<br/>[contract.py]"]
  node_reference["Reference detector<br/>[reference.py]"]
  node_yolo["YOLO detector<br/>[yolo.py]"]
end

subgraph group_analytics["Store analytics"]
  node_shopper["Shopper analytics<br/>[pipeline.py]"]
  node_tracker["Shopper tracking<br/>[tracker.py]"]
  node_tripwire["Entry and exit counts<br/>[tripwire.py]"]
  node_visits["Dwell and visits<br/>[visits.py]"]
  node_heatmap["Movement heatmaps<br/>[heatmap.py]"]
  node_shelf["Shelf analytics<br/>[pipeline.py]"]
  node_fill["Shelf fill monitor<br/>[fill.py]"]
  node_stockout["Stockout detection<br/>[stockout.py]"]
  node_planogram["Planogram compliance<br/>[planogram.py]"]
  node_inventory["Inventory tracking"]
  node_backend["Queue and POS events<br/>[pipeline.py]"]
  node_queue["Queue estimates<br/>[queue_model.py]"]
  node_staffing["Staffing advice<br/>[staffing.py]"]
end

subgraph group_services["Events and reporting"]
  node_bus["Event bus<br/>[bus.py]"]
  node_events["Event contract<br/>[events.py]"]
  node_sink["Event persistence<br/>[sink.py]"]
  node_db[("SQLite store<br/>[db.py]")]
  node_aggregates["KPI aggregation<br/>[aggregates.py]"]
  node_api["Analytics API<br/>[api.py]"]
  node_cloud["Aggregate cloud sync<br/>[cloud_sync.py]"]
  node_pos["POS CSV integration<br/>[pos_csv.py]"]
end

node_operator(("Store operator"))

node_operator -->|"uploads clips"| node_web
node_web -->|"requests data"| node_webapi
node_webapi -.->|"calls endpoints"| node_server
node_server -->|"generates clipset"| node_autoconfig
node_server -->|"loads settings"| node_config
node_server -->|"starts run"| node_main
node_main -->|"builds sources"| node_sources
node_sources -->|"yields frames"| node_frame
node_main -->|"selects backend"| node_reference
node_main -->|"selects backend"| node_yolo
node_reference -->|"emits results"| node_frame
node_yolo -->|"emits results"| node_frame
node_main -->|"processes overhead"| node_shopper
node_main -->|"processes shelf"| node_shelf
node_main -->|"processes queue cells"| node_backend
node_shopper -->|"tracks people"| node_tracker
node_shopper -->|"counts crossings"| node_tripwire
node_shopper -->|"measures dwell"| node_visits
node_shopper -->|"builds heatmap"| node_heatmap
node_shelf -->|"measures fill"| node_fill
node_shelf -->|"tracks stockouts"| node_stockout
node_shelf -->|"audits layout"| node_planogram
node_shelf -->|"tracks inventory"| node_inventory
node_backend -->|"estimates queues"| node_queue
node_backend -->|"requests advice"| node_staffing
node_shopper -->|"publishes events"| node_bus
node_shelf -->|"publishes events"| node_bus
node_backend -->|"publishes events"| node_bus
node_bus -->|"uses envelope"| node_events
node_bus -->|"delivers events"| node_sink
node_sink -->|"writes events"| node_db
node_server -->|"serves endpoints"| node_api
node_api -->|"provides KPIs"| node_aggregates
node_aggregates -.->|"reads history"| node_db
node_backend -.->|"optional POS input"| node_pos
node_aggregates -.->|"optional aggregate sync"| node_cloud

click node_web "https://github.com/rohitjg13/stupid-apple/blob/main/web/src/App.svelte"
click node_webapi "https://github.com/rohitjg13/stupid-apple/blob/main/web/src/lib/api.js"
click node_server "https://github.com/rohitjg13/stupid-apple/blob/main/server.py"
click node_autoconfig "https://github.com/rohitjg13/stupid-apple/blob/main/tools/autoconfig.py"
click node_config "https://github.com/rohitjg13/stupid-apple/blob/main/core/config.py"
click node_main "https://github.com/rohitjg13/stupid-apple/blob/main/main.py"
click node_sources "https://github.com/rohitjg13/stupid-apple/tree/main/sources"
click node_frame "https://github.com/rohitjg13/stupid-apple/blob/main/pl/contract.py"
click node_reference "https://github.com/rohitjg13/stupid-apple/blob/main/pl/reference.py"
click node_yolo "https://github.com/rohitjg13/stupid-apple/blob/main/pl/yolo.py"
click node_shopper "https://github.com/rohitjg13/stupid-apple/blob/main/shopper/pipeline.py"
click node_tracker "https://github.com/rohitjg13/stupid-apple/blob/main/shopper/tracker.py"
click node_tripwire "https://github.com/rohitjg13/stupid-apple/blob/main/shopper/tripwire.py"
click node_visits "https://github.com/rohitjg13/stupid-apple/blob/main/shopper/visits.py"
click node_heatmap "https://github.com/rohitjg13/stupid-apple/blob/main/shopper/heatmap.py"
click node_shelf "https://github.com/rohitjg13/stupid-apple/blob/main/shelf/pipeline.py"
click node_fill "https://github.com/rohitjg13/stupid-apple/blob/main/shelf/fill.py"
click node_stockout "https://github.com/rohitjg13/stupid-apple/blob/main/shelf/stockout.py"
click node_planogram "https://github.com/rohitjg13/stupid-apple/blob/main/shelf/planogram.py"
click node_inventory "https://github.com/rohitjg13/stupid-apple/blob/main/shelf/inventory_tracker.py"
click node_backend "https://github.com/rohitjg13/stupid-apple/blob/main/backend/pipeline.py"
click node_queue "https://github.com/rohitjg13/stupid-apple/blob/main/backend/queue_model.py"
click node_staffing "https://github.com/rohitjg13/stupid-apple/blob/main/backend/staffing.py"
click node_bus "https://github.com/rohitjg13/stupid-apple/blob/main/core/bus.py"
click node_events "https://github.com/rohitjg13/stupid-apple/blob/main/core/events.py"
click node_sink "https://github.com/rohitjg13/stupid-apple/blob/main/backend/sink.py"
click node_db "https://github.com/rohitjg13/stupid-apple/blob/main/backend/db.py"
click node_aggregates "https://github.com/rohitjg13/stupid-apple/blob/main/backend/aggregates.py"
click node_api "https://github.com/rohitjg13/stupid-apple/blob/main/backend/api.py"
click node_cloud "https://github.com/rohitjg13/stupid-apple/blob/main/backend/cloud_sync.py"
click node_pos "https://github.com/rohitjg13/stupid-apple/blob/main/backend/pos_csv.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_web,node_webapi,node_server,node_autoconfig toneBlue
class node_config,node_main,node_sources,node_frame,node_reference,node_yolo toneAmber
class node_shopper,node_tracker,node_tripwire,node_visits,node_heatmap,node_shelf,node_fill,node_stockout,node_planogram,node_inventory,node_backend,node_queue,node_staffing toneMint
class node_bus,node_events,node_sink,node_db,node_aggregates,node_api,node_cloud,node_pos toneRose
class node_operator toneIndigo
```

## Components

### Operator experience

- [Wizard and dashboard](https://github.com/rohitjg13/stupid-apple/blob/main/web/src/App.svelte): `web/src/App.svelte`
- [Web API client](https://github.com/rohitjg13/stupid-apple/blob/main/web/src/lib/api.js): `web/src/lib/api.js`
- [Run server](https://github.com/rohitjg13/stupid-apple/blob/main/server.py): `server.py`
- [Clipset generation](https://github.com/rohitjg13/stupid-apple/blob/main/tools/autoconfig.py): `tools/autoconfig.py`

### Capture and inference

- [Clipset configuration](https://github.com/rohitjg13/stupid-apple/blob/main/core/config.py): `core/config.py`
- [Analytics runner](https://github.com/rohitjg13/stupid-apple/blob/main/main.py): `main.py`
- [Video sources](https://github.com/rohitjg13/stupid-apple/tree/main/sources): `sources`
- [Frame contract](https://github.com/rohitjg13/stupid-apple/blob/main/pl/contract.py): `pl/contract.py`
- [Reference detector](https://github.com/rohitjg13/stupid-apple/blob/main/pl/reference.py): `pl/reference.py`
- [YOLO detector](https://github.com/rohitjg13/stupid-apple/blob/main/pl/yolo.py): `pl/yolo.py`

### Store analytics

- [Shopper analytics](https://github.com/rohitjg13/stupid-apple/blob/main/shopper/pipeline.py): `shopper/pipeline.py`
- [Shopper tracking](https://github.com/rohitjg13/stupid-apple/blob/main/shopper/tracker.py): `shopper/tracker.py`
- [Entry and exit counts](https://github.com/rohitjg13/stupid-apple/blob/main/shopper/tripwire.py): `shopper/tripwire.py`
- [Dwell and visits](https://github.com/rohitjg13/stupid-apple/blob/main/shopper/visits.py): `shopper/visits.py`
- [Movement heatmaps](https://github.com/rohitjg13/stupid-apple/blob/main/shopper/heatmap.py): `shopper/heatmap.py`
- [Shelf analytics](https://github.com/rohitjg13/stupid-apple/blob/main/shelf/pipeline.py): `shelf/pipeline.py`
- [Shelf fill monitor](https://github.com/rohitjg13/stupid-apple/blob/main/shelf/fill.py): `shelf/fill.py`
- [Stockout detection](https://github.com/rohitjg13/stupid-apple/blob/main/shelf/stockout.py): `shelf/stockout.py`
- [Planogram compliance](https://github.com/rohitjg13/stupid-apple/blob/main/shelf/planogram.py): `shelf/planogram.py`
- [Inventory tracking](https://github.com/rohitjg13/stupid-apple/blob/main/shelf/inventory_tracker.py): `shelf/inventory_tracker.py`
- [Queue and POS events](https://github.com/rohitjg13/stupid-apple/blob/main/backend/pipeline.py): `backend/pipeline.py`
- [Queue estimates](https://github.com/rohitjg13/stupid-apple/blob/main/backend/queue_model.py): `backend/queue_model.py`
- [Staffing advice](https://github.com/rohitjg13/stupid-apple/blob/main/backend/staffing.py): `backend/staffing.py`

### Events and reporting

- [Event bus](https://github.com/rohitjg13/stupid-apple/blob/main/core/bus.py): `core/bus.py`
- [Event contract](https://github.com/rohitjg13/stupid-apple/blob/main/core/events.py): `core/events.py`
- [Event persistence](https://github.com/rohitjg13/stupid-apple/blob/main/backend/sink.py): `backend/sink.py`
- [SQLite store](https://github.com/rohitjg13/stupid-apple/blob/main/backend/db.py): `backend/db.py`
- [KPI aggregation](https://github.com/rohitjg13/stupid-apple/blob/main/backend/aggregates.py): `backend/aggregates.py`
- [Analytics API](https://github.com/rohitjg13/stupid-apple/blob/main/backend/api.py): `backend/api.py`
- [Aggregate cloud sync](https://github.com/rohitjg13/stupid-apple/blob/main/backend/cloud_sync.py): `backend/cloud_sync.py`
- [POS CSV integration](https://github.com/rohitjg13/stupid-apple/blob/main/backend/pos_csv.py): `backend/pos_csv.py`

### Other components

- **Store operator**

## Connections

- Store operator → Wizard and dashboard: uploads clips
- Wizard and dashboard → Web API client: requests data (evidence: `web/src/App.svelte`)
- Web API client → Run server: calls endpoints
- Run server → Clipset generation: generates clipset (evidence: `server.py`)
- Run server → Clipset configuration: loads settings (evidence: `server.py`)
- Run server → Analytics runner: starts run (evidence: `server.py`)
- Analytics runner → Video sources: builds sources (evidence: `main.py`)
- Video sources → Frame contract: yields frames (evidence: `sources/sim.py`)
- Analytics runner → Reference detector: selects backend (evidence: `main.py`)
- Analytics runner → YOLO detector: selects backend (evidence: `main.py`)
- Reference detector → Frame contract: emits results (evidence: `pl/reference.py`)
- YOLO detector → Frame contract: emits results (evidence: `pl/yolo.py`)
- Analytics runner → Shopper analytics: processes overhead (evidence: `main.py`)
- Analytics runner → Shelf analytics: processes shelf (evidence: `main.py`)
- Analytics runner → Queue and POS events: processes queue cells (evidence: `backend/pipeline.py`)
- Shopper analytics → Shopper tracking: tracks people (evidence: `shopper/pipeline.py`)
- Shopper analytics → Entry and exit counts: counts crossings (evidence: `shopper/pipeline.py`)
- Shopper analytics → Dwell and visits: measures dwell (evidence: `shopper/pipeline.py`)
- Shopper analytics → Movement heatmaps: builds heatmap (evidence: `shopper/pipeline.py`)
- Shelf analytics → Shelf fill monitor: measures fill (evidence: `shelf/pipeline.py`)
- Shelf analytics → Stockout detection: tracks stockouts (evidence: `shelf/pipeline.py`)
- Shelf analytics → Planogram compliance: audits layout (evidence: `shelf/pipeline.py`)
- Shelf analytics → Inventory tracking: tracks inventory (evidence: `shelf/pipeline.py`)
- Queue and POS events → Queue estimates: estimates queues (evidence: `backend/pipeline.py`)
- Queue and POS events → Staffing advice: requests advice (evidence: `backend/pipeline.py`)
- Shopper analytics → Event bus: publishes events (evidence: `shopper/pipeline.py`)
- Shelf analytics → Event bus: publishes events (evidence: `shelf/pipeline.py`)
- Queue and POS events → Event bus: publishes events (evidence: `backend/pipeline.py`)
- Event bus → Event contract: uses envelope
- Event bus → Event persistence: delivers events (evidence: `main.py`)
- Event persistence → SQLite store: writes events (evidence: `backend/sink.py`)
- Run server → Analytics API: serves endpoints (evidence: `server.py`)
- Analytics API → KPI aggregation: provides KPIs
- KPI aggregation → SQLite store: reads history
- Queue and POS events → POS CSV integration: optional POS input
- KPI aggregation → Aggregate cloud sync: optional aggregate sync
