# drsadivural/shoplifter architecture

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

- Interactive diagram: https://gitdiagram.com/drsadivural/shoplifter
- Repository: https://github.com/drsadivural/shoplifter

## Overview

RetailGuard is a loss-prevention platform with a Japanese/English web console, an iOS responder app, a regional API and worker, and a store-local camera appliance. The central workflow is camera-edge event/evidence delivery to the API, followed by human incident review and a reasoned outcome in the web or mobile client. The README documents the product boundaries and API role; source-index references and excerpts support selected internal links. Unsampled router and edge details are represented at subsystem level, so their unverified internal flows are not expanded.

Main entry points: [`services/api/src/retailguard_api/app.py`](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/app.py) (API application), [`apps/ios/RetailGuard/App/AppState.swift`](https://github.com/drsadivural/shoplifter/blob/main/apps/ios/RetailGuard/App/AppState.swift) (iOS responder app), [`apps/web/src/pages/incidents.tsx`](https://github.com/drsadivural/shoplifter/blob/main/apps/web/src/pages/incidents.tsx) (Web console), [`services/api/src/retailguard_api/db.py`](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/db.py) (Tenant database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Responder clients"]
  node_webconsole["Web console<br/>[incidents.tsx]"]
  node_webroutes["Web route map<br/>[routes.tsx]"]
  node_webapi["Web API client<br/>[client.ts]"]
  node_iosapp["iOS responder app<br/>[AppState.swift]"]
  node_iosroutes["iOS destinations<br/>[Routes.swift]"]
  node_iosapi["iOS API client<br/>[APIClient.swift]"]
  node_preferences["App preferences"]
  node_push["Push registration<br/>[PushManager.swift]"]
end

subgraph group_backend["Regional backend"]
  node_api["API application<br/>[app.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_authorization["Access control<br/>[authz.py]"]
  node_dependencies["Request dependencies<br/>[deps.py]"]
  node_security["Session security<br/>[security.py]"]
  node_settings["Runtime settings<br/>[settings.py]"]
  node_db[("Tenant database<br/>[db.py]")]
  node_media["Evidence media<br/>[media.py]"]
end

subgraph group_edge["Store edge"]
  node_edgeagent["Edge appliance<br/>[agent.py]"]
  node_edgepipeline["Camera event pipeline<br/>[pipeline.py]"]
  node_edgeclient["Edge API client<br/>[client.py]"]
  node_cameras["Store cameras"]
end

subgraph group_domain["Review and operations"]
  node_incidentroutes["Incident endpoints<br/>[incidents.py]"]
  node_profileroutes["Profile endpoints<br/>[profiles.py]"]
  node_edgeroutes["Edge endpoints<br/>[edge.py]"]
  node_org["Organization operations<br/>[org.py]"]
  node_worker["Background worker<br/>[worker.py]"]
end

node_responder(("Retail responder"))
node_postgres[("PostgreSQL")]
node_apns["Apple Push service"]

node_responder -->|"reviews incidents"| node_webconsole
node_responder -->|"reviews incidents"| node_iosapp
node_webconsole -.->|"navigates"| node_webroutes
node_webroutes -->|"loads pages"| node_webconsole
node_webconsole -.->|"requests data"| node_webapi
node_webapi -->|"calls API"| node_api
node_iosapp -->|"navigates"| node_iosroutes
node_iosapp -->|"calls API"| node_iosapi
node_iosapp -->|"reads settings"| node_preferences
node_iosapp -->|"manages alerts"| node_push
node_push -->|"registers device"| node_iosapi
node_iosapi -->|"calls API"| node_api
node_api -->|"mounts router"| node_auth
node_api -->|"mounts router"| node_incidentroutes
node_api -->|"mounts router"| node_profileroutes
node_api -->|"mounts router"| node_edgeroutes
node_api -->|"mounts router"| node_org
node_auth -->|"checks access"| node_authorization
node_auth -->|"uses security"| node_security
node_authorization -->|"audits actions"| node_db
node_db -->|"loads database URL"| node_settings
node_db -->|"queries"| node_postgres
node_api -->|"loads configuration"| node_settings
node_edgeroutes -->|"receives edge events"| node_edgeagent
node_edgeagent -.->|"runs pipeline"| node_edgepipeline
node_edgeagent -.->|"uses client"| node_edgeclient
node_edgepipeline -->|"processes camera input"| node_cameras
node_edgeclient -->|"sends events"| node_edgeroutes
node_incidentroutes -.->|"handles evidence"| node_media
node_worker -->|"processes queued work"| node_db
node_worker -->|"handles media tasks"| node_media
node_worker -->|"sends notifications"| node_apns

click node_webconsole "https://github.com/drsadivural/shoplifter/blob/main/apps/web/src/pages/incidents.tsx"
click node_webroutes "https://github.com/drsadivural/shoplifter/blob/main/apps/web/src/routes.tsx"
click node_webapi "https://github.com/drsadivural/shoplifter/blob/main/apps/web/src/api/client.ts"
click node_iosapp "https://github.com/drsadivural/shoplifter/blob/main/apps/ios/RetailGuard/App/AppState.swift"
click node_iosroutes "https://github.com/drsadivural/shoplifter/blob/main/apps/ios/RetailGuard/App/Routes.swift"
click node_iosapi "https://github.com/drsadivural/shoplifter/blob/main/apps/ios/RetailGuardCore/Sources/RetailGuardCore/Networking/APIClient.swift"
click node_preferences "https://github.com/drsadivural/shoplifter/blob/main/apps/ios/RetailGuard/Services/AppPreferences.swift"
click node_push "https://github.com/drsadivural/shoplifter/blob/main/apps/ios/RetailGuard/Services/PushManager.swift"
click node_api "https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/app.py"
click node_auth "https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/routers/auth.py"
click node_authorization "https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/authz.py"
click node_dependencies "https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/deps.py"
click node_security "https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/security.py"
click node_settings "https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/settings.py"
click node_db "https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/db.py"
click node_media "https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/media.py"
click node_incidentroutes "https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/routers/incidents.py"
click node_profileroutes "https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/routers/profiles.py"
click node_edgeroutes "https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/routers/edge.py"
click node_org "https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/routers/org.py"
click node_worker "https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/worker.py"
click node_edgeagent "https://github.com/drsadivural/shoplifter/blob/main/services/edge/src/retailguard_edge/agent.py"
click node_edgepipeline "https://github.com/drsadivural/shoplifter/blob/main/services/edge/src/retailguard_edge/pipeline.py"
click node_edgeclient "https://github.com/drsadivural/shoplifter/blob/main/services/edge/src/retailguard_edge/client.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_webconsole,node_webroutes,node_webapi,node_iosapp,node_iosroutes,node_iosapi,node_preferences,node_push toneBlue
class node_api,node_auth,node_authorization,node_dependencies,node_security,node_settings,node_db,node_media,node_postgres toneAmber
class node_edgeagent,node_edgepipeline,node_edgeclient,node_cameras toneMint
class node_incidentroutes,node_profileroutes,node_edgeroutes,node_org,node_worker toneRose
class node_responder,node_apns toneIndigo
```

## Components

### Responder clients

- [Web console](https://github.com/drsadivural/shoplifter/blob/main/apps/web/src/pages/incidents.tsx): `apps/web/src/pages/incidents.tsx`
- [Web route map](https://github.com/drsadivural/shoplifter/blob/main/apps/web/src/routes.tsx): `apps/web/src/routes.tsx`
- [Web API client](https://github.com/drsadivural/shoplifter/blob/main/apps/web/src/api/client.ts): `apps/web/src/api/client.ts`
- [iOS responder app](https://github.com/drsadivural/shoplifter/blob/main/apps/ios/RetailGuard/App/AppState.swift): `apps/ios/RetailGuard/App/AppState.swift`
- [iOS destinations](https://github.com/drsadivural/shoplifter/blob/main/apps/ios/RetailGuard/App/Routes.swift): `apps/ios/RetailGuard/App/Routes.swift`
- [iOS API client](https://github.com/drsadivural/shoplifter/blob/main/apps/ios/RetailGuardCore/Sources/RetailGuardCore/Networking/APIClient.swift): `apps/ios/RetailGuardCore/Sources/RetailGuardCore/Networking/APIClient.swift`
- [App preferences](https://github.com/drsadivural/shoplifter/blob/main/apps/ios/RetailGuard/Services/AppPreferences.swift): `apps/ios/RetailGuard/Services/AppPreferences.swift`
- [Push registration](https://github.com/drsadivural/shoplifter/blob/main/apps/ios/RetailGuard/Services/PushManager.swift): `apps/ios/RetailGuard/Services/PushManager.swift`

### Regional backend

- [API application](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/app.py): `services/api/src/retailguard_api/app.py`
- [Authentication](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/routers/auth.py): `services/api/src/retailguard_api/routers/auth.py`
- [Access control](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/authz.py): `services/api/src/retailguard_api/authz.py`
- [Request dependencies](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/deps.py): `services/api/src/retailguard_api/deps.py`
- [Session security](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/security.py): `services/api/src/retailguard_api/security.py`
- [Runtime settings](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/settings.py): `services/api/src/retailguard_api/settings.py`
- [Tenant database](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/db.py): `services/api/src/retailguard_api/db.py`
- [Evidence media](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/media.py): `services/api/src/retailguard_api/media.py`

### Store edge

- [Edge appliance](https://github.com/drsadivural/shoplifter/blob/main/services/edge/src/retailguard_edge/agent.py): `services/edge/src/retailguard_edge/agent.py`
- [Camera event pipeline](https://github.com/drsadivural/shoplifter/blob/main/services/edge/src/retailguard_edge/pipeline.py): `services/edge/src/retailguard_edge/pipeline.py`
- [Edge API client](https://github.com/drsadivural/shoplifter/blob/main/services/edge/src/retailguard_edge/client.py): `services/edge/src/retailguard_edge/client.py`
- **Store cameras**

### Review and operations

- [Incident endpoints](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/routers/incidents.py): `services/api/src/retailguard_api/routers/incidents.py`
- [Profile endpoints](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/routers/profiles.py): `services/api/src/retailguard_api/routers/profiles.py`
- [Edge endpoints](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/routers/edge.py): `services/api/src/retailguard_api/routers/edge.py`
- [Organization operations](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/routers/org.py): `services/api/src/retailguard_api/routers/org.py`
- [Background worker](https://github.com/drsadivural/shoplifter/blob/main/services/api/src/retailguard_api/worker.py): `services/api/src/retailguard_api/worker.py`

### Other components

- **Retail responder**
- **PostgreSQL**
- **Apple Push service**

## Connections

- Retail responder → Web console: reviews incidents (evidence: `README.md`)
- Retail responder → iOS responder app: reviews incidents (evidence: `README.md`)
- Web console → Web route map: navigates (evidence: `apps/web/src/routes.tsx`)
- Web route map → Web console: loads pages (evidence: `apps/web/src/routes.tsx`)
- Web console → Web API client: requests data
- Web API client → API application: calls API (evidence: `README.md`)
- iOS responder app → iOS destinations: navigates (evidence: `apps/ios/RetailGuard/App/Routes.swift`)
- iOS responder app → iOS API client: calls API (evidence: `apps/ios/RetailGuard/App/AppState.swift`)
- iOS responder app → App preferences: reads settings (evidence: `apps/ios/RetailGuard/App/AppState.swift`)
- iOS responder app → Push registration: manages alerts (evidence: `apps/ios/RetailGuard/App/AppState.swift`)
- Push registration → iOS API client: registers device (evidence: `apps/ios/RetailGuard/Services/PushManager.swift`)
- iOS API client → API application: calls API (evidence: `README.md`)
- API application → Authentication: mounts router (evidence: `services/api/src/retailguard_api/app.py`)
- API application → Incident endpoints: mounts router (evidence: `services/api/src/retailguard_api/app.py`)
- API application → Profile endpoints: mounts router (evidence: `services/api/src/retailguard_api/app.py`)
- API application → Edge endpoints: mounts router (evidence: `services/api/src/retailguard_api/app.py`)
- API application → Organization operations: mounts router (evidence: `services/api/src/retailguard_api/app.py`)
- Authentication → Access control: checks access (evidence: `services/api/src/retailguard_api/routers/auth.py`)
- Authentication → Session security: uses security (evidence: `services/api/src/retailguard_api/routers/auth.py`)
- Access control → Tenant database: audits actions (evidence: `services/api/src/retailguard_api/authz.py`)
- Tenant database → Runtime settings: loads database URL (evidence: `services/api/src/retailguard_api/db.py`)
- Tenant database → PostgreSQL: queries (evidence: `services/api/src/retailguard_api/db.py`)
- API application → Runtime settings: loads configuration (evidence: `services/api/src/retailguard_api/app.py`)
- Edge endpoints → Edge appliance: receives edge events (evidence: `README.md`)
- Edge appliance → Camera event pipeline: runs pipeline
- Edge appliance → Edge API client: uses client
- Camera event pipeline → Store cameras: processes camera input (evidence: `README.md`)
- Edge API client → Edge endpoints: sends events (evidence: `README.md`)
- Incident endpoints → Evidence media: handles evidence (evidence: `services/api/src/retailguard_api/routers/incidents.py`)
- Background worker → Tenant database: processes queued work (evidence: `services/api/src/retailguard_api/worker.py`)
- Background worker → Evidence media: handles media tasks (evidence: `services/api/src/retailguard_api/worker.py`)
- Background worker → Apple Push service: sends notifications (evidence: `README.md`)
