# agnare/waretwin architecture

> Architecture diagram of the GitHub repository agnare/waretwin, 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/agnare/waretwin
- Repository: https://github.com/agnare/waretwin

## Overview

WareTwin is a warehouse digital twin: a Python simulator updates warehouse operations, FastAPI exposes snapshots and events, and a React/Three.js client presents live operations. The main workflow runs from the simulation tick through persisted state and a WebSocket snapshot to the dashboard. Distinct product branches include shipment and inbound operations, inventory and analytics, alerts/events, authentication, and synthetic-camera data generation with CV detection. Relationships are limited to those shown in the excerpts, SOURCE INDEX, or README; unsampled subsystems are represented by their exact tree paths.

Main entry points: [`frontend/src/App.tsx`](https://github.com/agnare/waretwin/blob/master/frontend/src/App.tsx) (Dashboard router), [`backend/app/main.py`](https://github.com/agnare/waretwin/blob/master/backend/app/main.py) (FastAPI services), [`backend/app/api/cv.py`](https://github.com/agnare/waretwin/blob/master/backend/app/api/cv.py) (Detection endpoints), [`frontend/src/capture/CaptureApp.tsx`](https://github.com/agnare/waretwin/blob/master/frontend/src/capture/CaptureApp.tsx) (Camera capture screen)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_operations["Warehouse operations"]
  node_simulator["Warehouse simulator<br/>[engine.py]"]
  node_domain["Warehouse domain model<br/>[models.py]"]
end

subgraph group_backend["Backend services"]
  node_database[("SQL database<br/>[db.py]")]
  node_api["FastAPI services<br/>[main.py]"]
  node_state_api["State and event API<br/>[routes.py]"]
  node_operations_api["Actions and alerts"]
  node_auth_api["Authentication and users<br/>[auth.py]"]
  node_auth_core["Roles and tokens<br/>[auth.py]"]
end

subgraph group_frontend["Dashboard and 3D"]
  node_shipments["Shipment operations<br/>[Shipments.tsx]"]
  node_inbound["Inbound operations<br/>[Inbound.tsx]"]
  node_inventory["Inventory<br/>[Inventory.tsx]"]
  node_insights["KPIs and analytics<br/>[Analytics.tsx]"]
  node_alerts_events["Alerts and event log"]
  node_sites["Site comparison<br/>[Sites.tsx]"]
  node_auth_ui["Login and user admin<br/>[auth.ts]"]
  node_app["Dashboard router<br/>[App.tsx]"]
  node_twin_hook["Live state subscription<br/>[useTwin.ts]"]
  node_api_client["HTTP and WS client<br/>[api.ts]"]
  node_scene["Warehouse 3D scene"]
end

subgraph group_cv["Camera and vision"]
  node_capture["Camera capture screen<br/>[CaptureApp.tsx]"]
  node_dataset_api["Dataset endpoints<br/>[dataset.py]"]
  node_cv_api["Detection endpoints<br/>[cv.py]"]
  node_detector["Object detector<br/>[detector.py]"]
  node_cv_zones["Dock zone matching<br/>[zones.py]"]
  node_cv_tracking["Object tracking<br/>[tracker.py]"]
end

node_operator(("Warehouse operator"))
node_browser(("Browser"))

node_operator -->|"uses"| node_app
node_app -->|"subscribes through"| node_twin_hook
node_twin_hook -->|"uses URLs"| node_api_client
node_twin_hook -->|"loads snapshots"| node_api
node_api -->|"broadcasts snapshots"| node_twin_hook
node_api -->|"ticks and snapshots"| node_simulator
node_simulator -->|"updates state"| node_domain
node_database -->|"maps entities"| node_domain
node_state_api -->|"builds snapshots"| node_simulator
node_state_api -->|"queries state"| node_database
node_operations_api -->|"reads and writes"| node_database
node_auth_api -->|"uses token roles"| node_auth_core
node_auth_api -->|"manages users"| node_database
node_app -->|"routes to"| node_shipments
node_app -->|"routes to"| node_inbound
node_app -->|"routes to"| node_inventory
node_app -->|"routes to"| node_insights
node_app -->|"routes to"| node_alerts_events
node_app -->|"routes to"| node_sites
node_app -->|"checks session"| node_auth_ui
node_shipments -.->|"requests operations"| node_api
node_inbound -.->|"requests operations"| node_api
node_scene -->|"renders snapshots"| node_api
node_capture -->|"renders scene objects"| node_scene
node_capture -->|"reads live state"| node_twin_hook
node_capture -->|"saves labeled frames"| node_dataset_api
node_capture -->|"requests detection"| node_cv_api
node_cv_api -->|"runs inference"| node_detector
node_cv_api -->|"matches dock zones"| node_cv_zones
node_cv_api -->|"uses tracking"| node_cv_tracking
node_cv_api -->|"logs events"| node_database
node_browser -->|"opens camera mode"| node_capture

click node_simulator "https://github.com/agnare/waretwin/blob/master/backend/app/sim/engine.py"
click node_domain "https://github.com/agnare/waretwin/blob/master/backend/app/models.py"
click node_database "https://github.com/agnare/waretwin/blob/master/backend/app/db.py"
click node_api "https://github.com/agnare/waretwin/blob/master/backend/app/main.py"
click node_state_api "https://github.com/agnare/waretwin/blob/master/backend/app/api/routes.py"
click node_operations_api "https://github.com/agnare/waretwin/tree/master/backend/app/api"
click node_auth_api "https://github.com/agnare/waretwin/blob/master/backend/app/api/auth.py"
click node_auth_core "https://github.com/agnare/waretwin/blob/master/backend/app/auth.py"
click node_shipments "https://github.com/agnare/waretwin/blob/master/frontend/src/pages/Shipments.tsx"
click node_inbound "https://github.com/agnare/waretwin/blob/master/frontend/src/pages/Inbound.tsx"
click node_inventory "https://github.com/agnare/waretwin/blob/master/frontend/src/pages/Inventory.tsx"
click node_insights "https://github.com/agnare/waretwin/blob/master/frontend/src/pages/Analytics.tsx"
click node_alerts_events "https://github.com/agnare/waretwin/tree/master/frontend/src/pages"
click node_sites "https://github.com/agnare/waretwin/blob/master/frontend/src/pages/Sites.tsx"
click node_auth_ui "https://github.com/agnare/waretwin/blob/master/frontend/src/auth.ts"
click node_app "https://github.com/agnare/waretwin/blob/master/frontend/src/App.tsx"
click node_twin_hook "https://github.com/agnare/waretwin/blob/master/frontend/src/useTwin.ts"
click node_api_client "https://github.com/agnare/waretwin/blob/master/frontend/src/api.ts"
click node_scene "https://github.com/agnare/waretwin/tree/master/frontend/src/scene"
click node_capture "https://github.com/agnare/waretwin/blob/master/frontend/src/capture/CaptureApp.tsx"
click node_dataset_api "https://github.com/agnare/waretwin/blob/master/backend/app/api/dataset.py"
click node_cv_api "https://github.com/agnare/waretwin/blob/master/backend/app/api/cv.py"
click node_detector "https://github.com/agnare/waretwin/blob/master/backend/app/cv/detector.py"
click node_cv_zones "https://github.com/agnare/waretwin/blob/master/backend/app/cv/zones.py"
click node_cv_tracking "https://github.com/agnare/waretwin/blob/master/backend/app/cv/tracker.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_simulator,node_domain,node_browser toneBlue
class node_database,node_api,node_state_api,node_operations_api,node_auth_api,node_auth_core toneAmber
class node_shipments,node_inbound,node_inventory,node_insights,node_alerts_events,node_sites,node_auth_ui,node_app,node_twin_hook,node_api_client,node_scene toneMint
class node_capture,node_dataset_api,node_cv_api,node_detector,node_cv_zones,node_cv_tracking toneRose
class node_operator toneIndigo
```

## Components

### Warehouse operations

- [Warehouse simulator](https://github.com/agnare/waretwin/blob/master/backend/app/sim/engine.py): `backend/app/sim/engine.py`
- [Warehouse domain model](https://github.com/agnare/waretwin/blob/master/backend/app/models.py): `backend/app/models.py`

### Backend services

- [SQL database](https://github.com/agnare/waretwin/blob/master/backend/app/db.py): `backend/app/db.py`
- [FastAPI services](https://github.com/agnare/waretwin/blob/master/backend/app/main.py): `backend/app/main.py`
- [State and event API](https://github.com/agnare/waretwin/blob/master/backend/app/api/routes.py): `backend/app/api/routes.py`
- [Actions and alerts](https://github.com/agnare/waretwin/tree/master/backend/app/api): `backend/app/api`
- [Authentication and users](https://github.com/agnare/waretwin/blob/master/backend/app/api/auth.py): `backend/app/api/auth.py`
- [Roles and tokens](https://github.com/agnare/waretwin/blob/master/backend/app/auth.py): `backend/app/auth.py`

### Dashboard and 3D

- [Shipment operations](https://github.com/agnare/waretwin/blob/master/frontend/src/pages/Shipments.tsx): `frontend/src/pages/Shipments.tsx`
- [Inbound operations](https://github.com/agnare/waretwin/blob/master/frontend/src/pages/Inbound.tsx): `frontend/src/pages/Inbound.tsx`
- [Inventory](https://github.com/agnare/waretwin/blob/master/frontend/src/pages/Inventory.tsx): `frontend/src/pages/Inventory.tsx`
- [KPIs and analytics](https://github.com/agnare/waretwin/blob/master/frontend/src/pages/Analytics.tsx): `frontend/src/pages/Analytics.tsx`
- [Alerts and event log](https://github.com/agnare/waretwin/tree/master/frontend/src/pages): `frontend/src/pages`
- [Site comparison](https://github.com/agnare/waretwin/blob/master/frontend/src/pages/Sites.tsx): `frontend/src/pages/Sites.tsx`
- [Login and user admin](https://github.com/agnare/waretwin/blob/master/frontend/src/auth.ts): `frontend/src/auth.ts`
- [Dashboard router](https://github.com/agnare/waretwin/blob/master/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Live state subscription](https://github.com/agnare/waretwin/blob/master/frontend/src/useTwin.ts): `frontend/src/useTwin.ts`
- [HTTP and WS client](https://github.com/agnare/waretwin/blob/master/frontend/src/api.ts): `frontend/src/api.ts`
- [Warehouse 3D scene](https://github.com/agnare/waretwin/tree/master/frontend/src/scene): `frontend/src/scene`

### Camera and vision

- [Camera capture screen](https://github.com/agnare/waretwin/blob/master/frontend/src/capture/CaptureApp.tsx): `frontend/src/capture/CaptureApp.tsx`
- [Dataset endpoints](https://github.com/agnare/waretwin/blob/master/backend/app/api/dataset.py): `backend/app/api/dataset.py`
- [Detection endpoints](https://github.com/agnare/waretwin/blob/master/backend/app/api/cv.py): `backend/app/api/cv.py`
- [Object detector](https://github.com/agnare/waretwin/blob/master/backend/app/cv/detector.py): `backend/app/cv/detector.py`
- [Dock zone matching](https://github.com/agnare/waretwin/blob/master/backend/app/cv/zones.py): `backend/app/cv/zones.py`
- [Object tracking](https://github.com/agnare/waretwin/blob/master/backend/app/cv/tracker.py): `backend/app/cv/tracker.py`

### Other components

- **Warehouse operator**
- **Browser**

## Connections

- Warehouse operator → Dashboard router: uses (evidence: `README.md`)
- Dashboard router → Live state subscription: subscribes through (evidence: `frontend/src/App.tsx`)
- Live state subscription → HTTP and WS client: uses URLs (evidence: `frontend/src/useTwin.ts`)
- Live state subscription → FastAPI services: loads snapshots (evidence: `frontend/src/useTwin.ts`)
- FastAPI services → Live state subscription: broadcasts snapshots (evidence: `backend/app/main.py`)
- FastAPI services → Warehouse simulator: ticks and snapshots (evidence: `backend/app/main.py`)
- Warehouse simulator → Warehouse domain model: updates state (evidence: `backend/app/sim/engine.py`)
- SQL database → Warehouse domain model: maps entities (evidence: `backend/app/db.py`)
- State and event API → Warehouse simulator: builds snapshots (evidence: `backend/app/api/routes.py`)
- State and event API → SQL database: queries state (evidence: `backend/app/api/routes.py`)
- Actions and alerts → SQL database: reads and writes (evidence: `backend/app/api/actions.py`)
- Authentication and users → Roles and tokens: uses token roles (evidence: `backend/app/api/auth.py`)
- Authentication and users → SQL database: manages users (evidence: `backend/app/api/auth.py`)
- Dashboard router → Shipment operations: routes to (evidence: `frontend/src/App.tsx`)
- Dashboard router → Inbound operations: routes to (evidence: `frontend/src/App.tsx`)
- Dashboard router → Inventory: routes to (evidence: `frontend/src/App.tsx`)
- Dashboard router → KPIs and analytics: routes to (evidence: `frontend/src/App.tsx`)
- Dashboard router → Alerts and event log: routes to (evidence: `frontend/src/App.tsx`)
- Dashboard router → Site comparison: routes to (evidence: `frontend/src/App.tsx`)
- Dashboard router → Login and user admin: checks session (evidence: `frontend/src/App.tsx`)
- Shipment operations → FastAPI services: requests operations
- Inbound operations → FastAPI services: requests operations
- Warehouse 3D scene → FastAPI services: renders snapshots (evidence: `README.md`)
- Camera capture screen → Warehouse 3D scene: renders scene objects (evidence: `frontend/src/capture/CaptureApp.tsx`)
- Camera capture screen → Live state subscription: reads live state (evidence: `frontend/src/capture/CaptureApp.tsx`)
- Camera capture screen → Dataset endpoints: saves labeled frames (evidence: `README.md`)
- Camera capture screen → Detection endpoints: requests detection (evidence: `README.md`)
- Detection endpoints → Object detector: runs inference (evidence: `backend/app/api/cv.py`)
- Detection endpoints → Dock zone matching: matches dock zones (evidence: `backend/app/api/cv.py`)
- Detection endpoints → Object tracking: uses tracking (evidence: `backend/app/api/cv.py`)
- Detection endpoints → SQL database: logs events (evidence: `backend/app/api/cv.py`)
- Browser → Camera capture screen: opens camera mode (evidence: `README.md`)
