# adarshdev200/trinetra-8bitbite architecture

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

- Interactive diagram: https://gitdiagram.com/adarshdev200/trinetra-8bitbite
- Repository: https://github.com/adarshdev200/trinetra-8bitbite

## Overview

TRIMUKH is a temple crowd-safety platform. Camera video is processed into zone counts and entrance/exit events; the backend updates occupancy and gate state, then serves live status to the protected command-center pages. Wearable SOS positions and barricade guidance are additional hardware branches. The main implementation links are supported by excerpts and README documentation; frontend feature-page internals and some hardware wiring were not sampled, so those connections are shown only where documented.

Main entry points: [`mandir-crowd-monitor/backend/server.js`](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/server.js) (API & Socket Server), [`mandir-crowd-monitor/cv-engine/src/zone_pipeline.py`](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/src/zone_pipeline.py) (Zone Pipeline), [`mandir-crowd-monitor/cv-engine/main.py`](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/main.py) (CV Runner), [`trinetra-frontend/src/App.jsx`](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/trinetra-frontend/src/App.jsx) (App & Protected Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vision["Vision &amp; Zone Counting"]
  node_cvmain["CV Runner<br/>[main.py]"]
  node_pipeline["Zone Pipeline<br/>[zone_pipeline.py]"]
  node_detector["Person Detector<br/>[detector.py]"]
  node_linecounter["Line Counter<br/>[line_counter.py]"]
  node_occupancycounter["Occupancy Counter<br/>[counter.py]"]
  node_stream["Annotated Feeds<br/>[web_stream.py]"]
  node_signal["Backend Signal Client<br/>[signal_client.py]"]
end

subgraph group_backend["Backend &amp; Live State"]
  node_backendserver["API &amp; Socket Server<br/>[server.js]"]
  node_state["Occupancy &amp; Gate State<br/>[state.js]"]
  node_gate["Gate Threshold Logic<br/>[gate.js]"]
  node_models[("State &amp; Event Models<br/>[models.js]")]
  node_positions["Band Positions<br/>[positions.js]"]
  node_zones["Zone Counts<br/>[zones.js]"]
  node_auth["Login &amp; Tokens<br/>[auth.js]"]
end

subgraph group_frontend["Command Center"]
  node_frontend["Command Center Pages"]
  node_app["App &amp; Protected Routes<br/>[App.jsx]"]
  node_authcontext["Frontend Authentication<br/>[AuthContext.jsx]"]
  node_socketcontext["Realtime Socket Context<br/>[SocketContext.jsx]"]
end

subgraph group_hardware["Field Hardware"]
  node_band["BLE SOS Band<br/>[network.cpp]"]
  node_barricade["LED Barricade<br/>[main.py]"]
  node_barricadeagent["Barricade Agent<br/>[agent.py]"]
end

node_camera(("Camera Feeds"))
node_operator(("Control-Room Operator"))
node_mongo[("MongoDB")]

node_camera -->|"provides video"| node_cvmain
node_cvmain -->|"starts zones"| node_pipeline
node_cvmain -->|"serves feeds"| node_stream
node_cvmain -->|"configures client"| node_signal
node_pipeline -->|"runs tracking"| node_detector
node_pipeline -->|"counts crossings"| node_linecounter
node_pipeline -->|"smooths counts"| node_occupancycounter
node_pipeline -->|"posts events"| node_signal
node_pipeline -->|"publishes frames"| node_stream
node_signal -->|"posts events/counts"| node_backendserver
node_backendserver -->|"applies events"| node_state
node_backendserver -->|"updates positions"| node_positions
node_backendserver -->|"updates zone counts"| node_zones
node_backendserver -->|"checks login"| node_auth
node_state -->|"computes gate state"| node_gate
node_state -->|"reads/writes records"| node_models
node_models -->|"persists state"| node_mongo
node_operator -->|"opens console"| node_app
node_app -->|"provides session"| node_authcontext
node_app -->|"provides realtime"| node_socketcontext
node_app -->|"routes pages"| node_frontend
node_frontend -->|"uses REST and sockets"| node_backendserver
node_frontend -->|"views MJPEG feeds"| node_stream
node_authcontext -->|"authenticates"| node_backendserver
node_socketcontext -->|"opens socket"| node_backendserver
node_band -->|"posts SOS position"| node_backendserver
node_backendserver -.->|"supplies zone status"| node_barricadeagent
node_barricadeagent -.->|"drives LEDs"| node_barricade

click node_cvmain "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/main.py"
click node_pipeline "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/src/zone_pipeline.py"
click node_detector "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/src/detector.py"
click node_linecounter "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/src/line_counter.py"
click node_occupancycounter "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/src/counter.py"
click node_stream "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/src/web_stream.py"
click node_signal "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/src/signal_client.py"
click node_backendserver "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/server.js"
click node_state "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/src/state.js"
click node_gate "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/src/gate.js"
click node_models "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/src/models.js"
click node_positions "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/src/positions.js"
click node_zones "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/src/zones.js"
click node_auth "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/src/auth.js"
click node_frontend "https://github.com/adarshdev200/trinetra-8bitbite/tree/main/trinetra-frontend/src/pages"
click node_app "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/trinetra-frontend/src/App.jsx"
click node_authcontext "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/trinetra-frontend/src/context/AuthContext.jsx"
click node_socketcontext "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/trinetra-frontend/src/context/SocketContext.jsx"
click node_band "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/band/ble_trilateration_network/network.cpp"
click node_barricade "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/barricade/pico/main.py"
click node_barricadeagent "https://github.com/adarshdev200/trinetra-8bitbite/blob/main/barricade/agent.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_cvmain,node_pipeline,node_detector,node_linecounter,node_occupancycounter,node_stream,node_signal toneBlue
class node_backendserver,node_state,node_gate,node_models,node_positions,node_zones,node_auth,node_mongo toneAmber
class node_frontend,node_app,node_authcontext,node_socketcontext toneMint
class node_band,node_barricade,node_barricadeagent toneRose
class node_camera,node_operator toneIndigo
```

## Components

### Vision & Zone Counting

- [CV Runner](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/main.py): `mandir-crowd-monitor/cv-engine/main.py`
- [Zone Pipeline](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/src/zone_pipeline.py): `mandir-crowd-monitor/cv-engine/src/zone_pipeline.py`
- [Person Detector](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/src/detector.py): `mandir-crowd-monitor/cv-engine/src/detector.py`
- [Line Counter](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/src/line_counter.py): `mandir-crowd-monitor/cv-engine/src/line_counter.py`
- [Occupancy Counter](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/src/counter.py): `mandir-crowd-monitor/cv-engine/src/counter.py`
- [Annotated Feeds](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/src/web_stream.py): `mandir-crowd-monitor/cv-engine/src/web_stream.py`
- [Backend Signal Client](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/cv-engine/src/signal_client.py): `mandir-crowd-monitor/cv-engine/src/signal_client.py`

### Backend & Live State

- [API & Socket Server](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/server.js): `mandir-crowd-monitor/backend/server.js`
- [Occupancy & Gate State](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/src/state.js): `mandir-crowd-monitor/backend/src/state.js`
- [Gate Threshold Logic](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/src/gate.js): `mandir-crowd-monitor/backend/src/gate.js`
- [State & Event Models](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/src/models.js): `mandir-crowd-monitor/backend/src/models.js`
- [Band Positions](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/src/positions.js): `mandir-crowd-monitor/backend/src/positions.js`
- [Zone Counts](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/src/zones.js): `mandir-crowd-monitor/backend/src/zones.js`
- [Login & Tokens](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/mandir-crowd-monitor/backend/src/auth.js): `mandir-crowd-monitor/backend/src/auth.js`

### Command Center

- [Command Center Pages](https://github.com/adarshdev200/trinetra-8bitbite/tree/main/trinetra-frontend/src/pages): `trinetra-frontend/src/pages`
- [App & Protected Routes](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/trinetra-frontend/src/App.jsx): `trinetra-frontend/src/App.jsx`
- [Frontend Authentication](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/trinetra-frontend/src/context/AuthContext.jsx): `trinetra-frontend/src/context/AuthContext.jsx`
- [Realtime Socket Context](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/trinetra-frontend/src/context/SocketContext.jsx): `trinetra-frontend/src/context/SocketContext.jsx`

### Field Hardware

- [BLE SOS Band](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/band/ble_trilateration_network/network.cpp): `band/ble_trilateration_network/network.cpp`
- [LED Barricade](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/barricade/pico/main.py): `barricade/pico/main.py`
- [Barricade Agent](https://github.com/adarshdev200/trinetra-8bitbite/blob/main/barricade/agent.py): `barricade/agent.py`

### Other components

- **Camera Feeds**
- **Control-Room Operator**
- **MongoDB**

## Connections

- Camera Feeds → CV Runner: provides video
- CV Runner → Zone Pipeline: starts zones (evidence: `mandir-crowd-monitor/cv-engine/main.py`)
- CV Runner → Annotated Feeds: serves feeds (evidence: `mandir-crowd-monitor/cv-engine/main.py`)
- CV Runner → Backend Signal Client: configures client (evidence: `mandir-crowd-monitor/cv-engine/main.py`)
- Zone Pipeline → Person Detector: runs tracking (evidence: `mandir-crowd-monitor/cv-engine/src/zone_pipeline.py`)
- Zone Pipeline → Line Counter: counts crossings (evidence: `mandir-crowd-monitor/cv-engine/src/zone_pipeline.py`)
- Zone Pipeline → Occupancy Counter: smooths counts (evidence: `mandir-crowd-monitor/cv-engine/src/zone_pipeline.py`)
- Zone Pipeline → Backend Signal Client: posts events (evidence: `mandir-crowd-monitor/cv-engine/src/zone_pipeline.py`)
- Zone Pipeline → Annotated Feeds: publishes frames (evidence: `mandir-crowd-monitor/cv-engine/src/zone_pipeline.py`)
- Backend Signal Client → API & Socket Server: posts events/counts (evidence: `mandir-crowd-monitor/cv-engine/src/signal_client.py`)
- API & Socket Server → Occupancy & Gate State: applies events (evidence: `mandir-crowd-monitor/backend/server.js`)
- API & Socket Server → Band Positions: updates positions (evidence: `mandir-crowd-monitor/backend/server.js`)
- API & Socket Server → Zone Counts: updates zone counts (evidence: `mandir-crowd-monitor/backend/server.js`)
- API & Socket Server → Login & Tokens: checks login (evidence: `mandir-crowd-monitor/backend/server.js`)
- Occupancy & Gate State → Gate Threshold Logic: computes gate state (evidence: `mandir-crowd-monitor/backend/src/state.js`)
- Occupancy & Gate State → State & Event Models: reads/writes records (evidence: `mandir-crowd-monitor/backend/src/state.js`)
- State & Event Models → MongoDB: persists state
- Control-Room Operator → App & Protected Routes: opens console
- App & Protected Routes → Frontend Authentication: provides session (evidence: `trinetra-frontend/src/App.jsx`)
- App & Protected Routes → Realtime Socket Context: provides realtime (evidence: `trinetra-frontend/src/App.jsx`)
- App & Protected Routes → Command Center Pages: routes pages (evidence: `trinetra-frontend/src/App.jsx`)
- Command Center Pages → API & Socket Server: uses REST and sockets
- Command Center Pages → Annotated Feeds: views MJPEG feeds
- Frontend Authentication → API & Socket Server: authenticates (evidence: `trinetra-frontend/src/context/AuthContext.jsx`)
- Realtime Socket Context → API & Socket Server: opens socket
- BLE SOS Band → API & Socket Server: posts SOS position
- API & Socket Server → Barricade Agent: supplies zone status
- Barricade Agent → LED Barricade: drives LEDs
