# karan96108/livecount architecture

> Architecture diagram of the GitHub repository karan96108/livecount, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/karan96108/livecount
- Repository: https://github.com/karan96108/livecount

## Overview

##### Project type and purpose
- This is a monolithic full-stack web application written in Python/Flask for real-time emotion detection using OpenCV and DeepFace.
- It captures video from a webcam, runs an emotion-classification model, counts people, monitors FPS, and streams the annotated video to a browser UI.

##### File structure
- Top-level:
- test.py – main Flask app and video-capture loop
- wsgi.py – entrypoint for WSGI servers (e.g., Gunicorn)
- templates/index.html – single-page frontend UI
- Speech_Emotion_Recognition_Model.h5 and tmp_pretrained_models/… – pre-trained model artifacts
- requirements.txt, runtime.txt – dependency and runtime specifications
- render.yaml – deployment config for Render.com
- .devcontainer/ – development container settings
- Patterns:
- MVC-style separation: templates/ (View), test.py (Controller), model files (Model)
- Single service (no microservices)

##### Key insights from README
- Real-time face detection + emotion classification + people count + FPS
- Startup: “python test.py,” serve at localhost:5000

##### Main components
a. Client (Browser) – displays UI and video stream
b. Web Server (Flask) – handles HTTP endpoints and video streaming
c. Video Capture Module (OpenCV) – reads frames from webcam
d. Emotion Detection Module (DeepFace + .h5 model) – performs inference
e. Analytics Module – counts people, computes FPS
f. Pre-trained Model Storage – Speech_Emotion_Recognition_Model.h5 and tmp_pretrained_models
g. External Dependencies – OpenCV, DeepFace, Flask

##### Relationships & data flows
- Browser → HTTP GET “/” → Flask serves index.html
- Browser ↔ HTTP Video Stream (e.g., MJPEG) ← Flask wraps OpenCV frames
- Flask → invoke Emotion Detection Module on each frame
- Emotion Detection Module → returns emotion label
- Analytics Module → updates people count & FPS
- Flask → overlays results on frames → streams to Browser

##### Architectural patterns & design principles
- MVC:
- View = templates/index.html (UI)
- Controller = test.py routing + frame loop
- Model = pre-trained .h5 + hyperparameters
- Single-process event loop: video capture, inference, streaming all in one service
- Config as code: render.yaml for deployment, .devcontainer for consistency

##### Technology & frameworks to annotate
- Python 3.x (runtime.txt)
- Flask (wsgi.py + test.py)
- OpenCV (cv2.VideoCapture)
- DeepFace (emotion-recognition pipeline)
- Model file: Speech_Emotion_Recognition_Model.h5
- Deployment: Render.com (render.yaml), Docker devcontainer

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client UI
    BrowserUI["Client (Browser UI)"]:::ui

    %% Backend Service
    subgraph "Backend Service"
        direction TB
        WSGI["WSGI Entry Point"]:::backend
        FlaskApp["Web Server (Flask Application Controller)"]:::backend
        VideoCap["Video Capture Module (OpenCV)"]:::backend
        EmotionMod["Emotion Detection Module (DeepFace)"]:::backend
        Analytics["Analytics Module (People Count & FPS)"]:::backend
    end

    %% Config & Models
    subgraph "Config & Models"
        direction TB
        ModelArtifact["Pre-trained Model Artifact (.h5)"]:::storage
        Hyperparams["Model Storage (Hyperparams)"]:::storage
        Requirements["Dependency Specification"]:::config
        RuntimeSpec["Runtime Specification"]:::config
        DeployCfg["Deployment Configuration"]:::config
        DevContainer["Development Container Configuration"]:::config
    end

    %% Data Flows
    BrowserUI -->|"HTTP GET /"| FlaskApp
    BrowserUI -->|"HTTP GET /stream"| FlaskApp
    FlaskApp -->|"init via WSGI"| WSGI
    FlaskApp -->|"read frame"| VideoCap
    VideoCap -->|"video frame"| EmotionMod
    EmotionMod -->|"emotion label"| Analytics
    Analytics -->|"annotated frame"| FlaskApp
    FlaskApp -->|"MJPEG Stream"| BrowserUI

    %% Config & Model Usage
    FlaskApp -->|uses| Requirements
    FlaskApp -->|uses| RuntimeSpec
    FlaskApp -->|deployed via| DeployCfg
    FlaskApp -->|dev setup| DevContainer
    EmotionMod -->|loads| ModelArtifact
    EmotionMod -->|loads| Hyperparams

    %% Click Events
    click BrowserUI "https://github.com/karan96108/livecount/blob/main/templates/index.html"
    click FlaskApp "https://github.com/karan96108/livecount/blob/main/test.py"
    click VideoCap "https://github.com/karan96108/livecount/blob/main/test.py"
    click EmotionMod "https://github.com/karan96108/livecount/blob/main/test.py"
    click Analytics "https://github.com/karan96108/livecount/blob/main/test.py"
    click WSGI "https://github.com/karan96108/livecount/blob/main/wsgi.py"
    click ModelArtifact "https://github.com/karan96108/livecount/blob/main/Speech_Emotion_Recognition_Model.h5"
    click Hyperparams "https://github.com/karan96108/livecount/blob/main/tmp_pretrained_models/emotion-recognition/hyperparams.yaml"
    click Requirements "https://github.com/karan96108/livecount/blob/main/requirements.txt"
    click RuntimeSpec "https://github.com/karan96108/livecount/blob/main/runtime.txt"
    click DeployCfg "https://github.com/karan96108/livecount/blob/main/render.yaml"
    click DevContainer "https://github.com/karan96108/livecount/blob/main/.devcontainer/devcontainer.json"

    %% Styles
    classDef ui fill:#F5A623,stroke:#333,stroke-width:1px;
    classDef backend fill:#4A90E2,stroke:#333,stroke-width:1px;
    classDef storage fill:#7ED321,stroke:#333,stroke-width:1px,shape:cylinder;
    classDef config fill:#9B9B9B,stroke:#333,stroke-width:1px;
```
