# khine282/emotionvision architecture

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

- Interactive diagram: https://gitdiagram.com/khine282/emotionvision
- Repository: https://github.com/khine282/emotionvision

## Overview

EmotionVision serves a browser dashboard and FastAPI API for camera management, live emotion detection, MJPEG streaming, and screenshot capture. The principal workflow registers or selects a camera, starts its processor, captures and analyzes frames, caches annotated frames for streaming, and persists detection or screenshot records in Supabase. The README documents the broader dashboard and REST capabilities; source excerpts show concrete route, processor, cache, and storage wiring, while omitted route bodies limit certainty about some operations.

Main entry points: [`services/detector_service.py`](https://github.com/khine282/emotionvision/blob/main/services/detector_service.py) (Detector routes), [`detector/camera_processor.py`](https://github.com/khine282/emotionvision/blob/main/detector/camera_processor.py) (Camera processor), [`detector/__init__.py`](https://github.com/khine282/emotionvision/blob/main/detector/__init__.py) (Detector orchestrator), [`detector/database.py`](https://github.com/khine282/emotionvision/blob/main/detector/database.py) (Camera registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and dashboard"]
  node_dashboard["Web dashboard<br/>[index.html]"]
  node_app["FastAPI application<br/>[main.py]"]
  node_routes["Detector routes"]
  node_mjpeg["MJPEG stream"]
end

subgraph group_runtime["Camera runtime"]
  node_orchestrator["Detector orchestrator<br/>[__init__.py]"]
  node_processor["Camera processor"]
  node_models["Model loader<br/>[models.py]"]
  node_frame_cache["Frame cache<br/>[frame_cache.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_persistence["Cloud persistence"]
  node_camera_registry["Camera registry<br/>[database.py]"]
  node_detections[("Detection records<br/>[database.py]")]
  node_screenshots[("Screenshot records<br/>[database.py]")]
end

node_browser(("Dashboard user"))
node_camera(("Webcam / RTSP"))
node_face_emotion["Face and emotion models"]
node_storage[("Screenshot storage")]

node_browser -->|"opens"| node_dashboard
node_dashboard -->|"requests"| node_app
node_app -->|"routes to"| node_routes
node_routes -->|"starts or stops"| node_orchestrator
node_routes -->|"manages cameras"| node_camera_registry
node_orchestrator -->|"loads cameras"| node_camera_registry
node_orchestrator -->|"loads models"| node_models
node_orchestrator -->|"starts processor"| node_processor
node_processor -->|"captures frames"| node_camera
node_models -->|"loads"| node_face_emotion
node_processor -->|"analyzes frames"| node_face_emotion
node_processor -->|"writes annotated frames"| node_frame_cache
node_routes -->|"reads latest frame"| node_frame_cache
node_routes -->|"returns stream"| node_mjpeg
node_mjpeg -->|"streams frames"| node_browser
node_processor -->|"writes detections"| node_detections
node_routes -->|"queries or deletes"| node_screenshots
node_processor -->|"uploads screenshot"| node_storage
node_routes -->|"deletes screenshot file"| node_storage
node_routes -->|"writes manual screenshot metadata"| node_screenshots
node_processor -->|"writes automatic screenshot metadata"| node_screenshots
node_config -->|"configures client"| node_camera_registry
node_config -->|"provides capture settings"| node_processor

click node_dashboard "https://github.com/khine282/emotionvision/blob/main/static/index.html"
click node_app "https://github.com/khine282/emotionvision/blob/main/main.py"
click node_routes "https://github.com/khine282/emotionvision/blob/main/services/detector_service.py"
click node_camera_registry "https://github.com/khine282/emotionvision/blob/main/detector/database.py"
click node_orchestrator "https://github.com/khine282/emotionvision/blob/main/detector/__init__.py"
click node_processor "https://github.com/khine282/emotionvision/blob/main/detector/camera_processor.py"
click node_models "https://github.com/khine282/emotionvision/blob/main/detector/models.py"
click node_frame_cache "https://github.com/khine282/emotionvision/blob/main/detector/frame_cache.py"
click node_mjpeg "https://github.com/khine282/emotionvision/blob/main/services/detector_service.py"
click node_detections "https://github.com/khine282/emotionvision/blob/main/detector/database.py"
click node_screenshots "https://github.com/khine282/emotionvision/blob/main/detector/database.py"
click node_config "https://github.com/khine282/emotionvision/blob/main/detector/config.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_app,node_routes,node_mjpeg,node_browser toneBlue
class node_orchestrator,node_processor,node_models,node_frame_cache,node_config,node_storage toneAmber
class node_camera_registry,node_detections,node_screenshots toneMint
class node_camera,node_face_emotion toneIndigo
```

## Components

### API and dashboard

- [Web dashboard](https://github.com/khine282/emotionvision/blob/main/static/index.html): `static/index.html`
- [FastAPI application](https://github.com/khine282/emotionvision/blob/main/main.py): `main.py`
- [Detector routes](https://github.com/khine282/emotionvision/blob/main/services/detector_service.py): `services/detector_service.py`
- [MJPEG stream](https://github.com/khine282/emotionvision/blob/main/services/detector_service.py): `services/detector_service.py`

### Camera runtime

- [Detector orchestrator](https://github.com/khine282/emotionvision/blob/main/detector/__init__.py): `detector/__init__.py`
- [Camera processor](https://github.com/khine282/emotionvision/blob/main/detector/camera_processor.py): `detector/camera_processor.py`
- [Model loader](https://github.com/khine282/emotionvision/blob/main/detector/models.py): `detector/models.py`
- [Frame cache](https://github.com/khine282/emotionvision/blob/main/detector/frame_cache.py): `detector/frame_cache.py`
- [Runtime configuration](https://github.com/khine282/emotionvision/blob/main/detector/config.py): `detector/config.py`

### Cloud persistence

- [Camera registry](https://github.com/khine282/emotionvision/blob/main/detector/database.py): `detector/database.py`
- [Detection records](https://github.com/khine282/emotionvision/blob/main/detector/database.py): `detector/database.py`
- [Screenshot records](https://github.com/khine282/emotionvision/blob/main/detector/database.py): `detector/database.py`

### Other components

- **Dashboard user**
- **Webcam / RTSP**
- **Face and emotion models**
- **Screenshot storage**

## Connections

- Dashboard user → Web dashboard: opens
- Web dashboard → FastAPI application: requests
- FastAPI application → Detector routes: routes to
- Detector routes → Detector orchestrator: starts or stops
- Detector routes → Camera registry: manages cameras
- Detector orchestrator → Camera registry: loads cameras
- Detector orchestrator → Model loader: loads models
- Detector orchestrator → Camera processor: starts processor
- Camera processor → Webcam / RTSP: captures frames
- Model loader → Face and emotion models: loads
- Camera processor → Face and emotion models: analyzes frames
- Camera processor → Frame cache: writes annotated frames
- Detector routes → Frame cache: reads latest frame
- Detector routes → MJPEG stream: returns stream
- MJPEG stream → Dashboard user: streams frames
- Camera processor → Detection records: writes detections
- Detector routes → Screenshot records: queries or deletes
- Camera processor → Screenshot storage: uploads screenshot
- Detector routes → Screenshot storage: deletes screenshot file
- Detector routes → Screenshot records: writes manual screenshot metadata
- Camera processor → Screenshot records: writes automatic screenshot metadata
- Runtime configuration → Camera registry: configures client
- Runtime configuration → Camera processor: provides capture settings
