# charan0120/ai-based-smart-surveillance-system architecture

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

- Interactive diagram: https://gitdiagram.com/charan0120/ai-based-smart-surveillance-system
- Repository: https://github.com/charan0120/ai-based-smart-surveillance-system

## Overview

This is a real-time smart-surveillance application: an ESP32-CAM streams frames to a Python server, which detects faces and weapons, classifies threats, and exposes monitoring dashboards. Admins can manage users and authorized faces; Firebase backs user authentication, while threat-status publishing is present as an optional, commented-out integration. The graph follows documented and excerpted calls; it does not assume connections for unsampled template behavior or hardware internals.

Main entry points: [`app.py`](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/app.py) (Flask Server), [`detector.py`](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/detector.py) (Threat Detector), [`websocket_server.py`](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/websocket_server.py) (WebSocket Receiver), [`globals.py`](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/globals.py) (Live State)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Camera Ingest"]
  node_ws["WebSocket Receiver"]
  node_shared["Live State<br/>[globals.py]"]
end

subgraph group_analysis["AI Analysis"]
  node_detector["Threat Detector<br/>[detector.py]"]
  node_model["YOLO Weights<br/>[best1.pt]"]
  node_faces[("Authorized Faces<br/>[detector.py]")]
  node_config["Detection Settings<br/>[config.py]"]
end

subgraph group_web["Web Application"]
  node_app["Flask Server<br/>[app.py]"]
  node_admin_ui["Admin Dashboard"]
  node_operator_ui["Operator Dashboard"]
  node_login_ui["Login Page<br/>[login.html]"]
end

subgraph group_identity["Identity and Cloud"]
  node_firebase_auth["Firebase User Auth<br/>[auth_firebase.py]"]
  node_firebase_events["Threat Status Publisher"]
end

node_esp32["ESP32 Camera<br/>[weblive.ino]"]
node_browser(("Browser User"))
node_firebase_db[("Firebase Realtime DB")]

node_esp32 -->|"streams frames"| node_ws
node_ws -->|"stores frames"| node_shared
node_ws -->|"processes frames"| node_detector
node_detector -->|"updates threat state"| node_shared
node_detector -->|"reads settings"| node_config
node_detector -->|"loads weights"| node_model
node_detector -->|"loads face encodings"| node_faces
node_browser -->|"requests pages"| node_app
node_app -->|"renders login"| node_login_ui
node_app -->|"renders admin view"| node_admin_ui
node_app -->|"renders operator view"| node_operator_ui
node_app -->|"verifies and manages users"| node_firebase_auth
node_firebase_auth -->|"reads and writes users"| node_firebase_db
node_app -->|"reads live status"| node_shared
node_app -->|"reloads face encodings"| node_detector
node_ws -.->|"optionally publishes status"| node_firebase_events
node_firebase_events -->|"writes status and alerts"| node_firebase_db

click node_esp32 "https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/live/weblive/weblive.ino"
click node_ws "https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/websocket_server.py"
click node_shared "https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/globals.py"
click node_detector "https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/detector.py"
click node_model "https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/best1.pt"
click node_faces "https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/detector.py"
click node_config "https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/config.py"
click node_app "https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/app.py"
click node_admin_ui "https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/templates/surveillance_dashboard.html"
click node_operator_ui "https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/templates/user_dashboard.html"
click node_login_ui "https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/templates/login.html"
click node_firebase_auth "https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/auth_firebase.py"
click node_firebase_events "https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/firebase_service.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_ws,node_shared,node_browser toneBlue
class node_detector,node_model,node_faces,node_config,node_firebase_db toneAmber
class node_app,node_admin_ui,node_operator_ui,node_login_ui toneMint
class node_firebase_auth,node_firebase_events toneRose
class node_esp32 toneTeal
```

## Components

### Camera Ingest

- [WebSocket Receiver](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/websocket_server.py): `websocket_server.py`
- [Live State](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/globals.py): `globals.py`

### AI Analysis

- [Threat Detector](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/detector.py): `detector.py`
- [YOLO Weights](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/best1.pt): `best1.pt`
- [Authorized Faces](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/detector.py): `detector.py`
- [Detection Settings](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/config.py): `config.py`

### Web Application

- [Flask Server](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/app.py): `app.py`
- [Admin Dashboard](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/templates/surveillance_dashboard.html): `templates/surveillance_dashboard.html`
- [Operator Dashboard](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/templates/user_dashboard.html): `templates/user_dashboard.html`
- [Login Page](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/templates/login.html): `templates/login.html`

### Identity and Cloud

- [Firebase User Auth](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/auth_firebase.py): `auth_firebase.py`
- [Threat Status Publisher](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/firebase_service.py): `firebase_service.py`

### Other components

- [ESP32 Camera](https://github.com/charan0120/ai-based-smart-surveillance-system/blob/main/live/weblive/weblive.ino): `live/weblive/weblive.ino`
- **Browser User**
- **Firebase Realtime DB**

## Connections

- ESP32 Camera → WebSocket Receiver: streams frames (evidence: `README.md`)
- WebSocket Receiver → Live State: stores frames (evidence: `websocket_server.py`)
- WebSocket Receiver → Threat Detector: processes frames (evidence: `websocket_server.py`)
- Threat Detector → Live State: updates threat state (evidence: `detector.py`)
- Threat Detector → Detection Settings: reads settings (evidence: `detector.py`)
- Threat Detector → YOLO Weights: loads weights
- Threat Detector → Authorized Faces: loads face encodings (evidence: `detector.py`)
- Browser User → Flask Server: requests pages (evidence: `README.md`)
- Flask Server → Login Page: renders login (evidence: `app.py`)
- Flask Server → Admin Dashboard: renders admin view (evidence: `app.py`)
- Flask Server → Operator Dashboard: renders operator view (evidence: `app.py`)
- Flask Server → Firebase User Auth: verifies and manages users (evidence: `app.py`)
- Firebase User Auth → Firebase Realtime DB: reads and writes users (evidence: `auth_firebase.py`)
- Flask Server → Live State: reads live status (evidence: `app.py`)
- Flask Server → Threat Detector: reloads face encodings (evidence: `app.py`)
- WebSocket Receiver → Threat Status Publisher: optionally publishes status (evidence: `websocket_server.py`)
- Threat Status Publisher → Firebase Realtime DB: writes status and alerts (evidence: `firebase_service.py`)
