# yashaswinisarangi/real-time-face-detector- architecture

> Architecture diagram of the GitHub repository yashaswinisarangi/real-time-face-detector-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yashaswinisarangi/real-time-face-detector-
- Repository: https://github.com/yashaswinisarangi/real-time-face-detector-

## Overview

##### Project type and purpose
- This is a simple full-stack real-time face-detection web application.
- Purpose: capture video from a local webcam, detect faces using OpenCV and a Haar cascade classifier, and stream the processed video feed to a browser via a Flask server.

##### File structure
- Top level files:
- app.py      – defines the Flask application and HTTP routes for streaming
- main.py     – entry point; likely initializes and runs the Flask server
- camera.py   – encapsulates webcam access and OpenCV face‐detection logic
- haarcascade_frontalface_default.xml – the pre-trained face-detection model
- README.md   – high-level description (no templates or static dirs here)

##### README for additional insights
- Confirms use of:
- Flask (web framework)
- OpenCV (computer vision)
- Webcam hardware input
- MJPEG or similar streaming technique to browser

a. Main components
1. Web Browser (client)
2. Flask Server (app.py / main.py)
3. Camera Module (camera.py)
4. OpenCV Face-Detection (Haar cascade xml + cv2 library)
5. Webcam Hardware
b. Relationships & interactions
- Client ↔ Flask Server: HTTP GET to “/video_feed” → persistent multipart (MJPEG) response
- Flask Server → Camera Module: on each frame request, call camera.get_frame()
- Camera Module → Webcam: read raw frame from webcam device
- Processed frame flows back up: OpenCV → Camera Module → Flask Server → Client
c. Architectural patterns
- Single-process synchronous model: request triggers capture + processing on the fly
- Streaming API pattern (multipart MJPEG)
- Separation of concerns:
– camera.py handles hardware & CV logic
– app.py handles HTTP and routing
d. Key technologies
- Flask (Python web framework)
- OpenCV (cv2 library) + haarcascade_frontalface_default.xml
- HTML5 / MJPEG streaming in browser

##### Detailed capture of essential elements
- Continuous loop for real-time streaming.
- Clearly distinguish modules to reflect separation of capture, processing, and serving.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend
    Client["Web Browser"]:::frontend

    %% Backend Components
    subgraph "Backend (Local Host)"
        AE["Application Entry\n(main.py)"]:::backend
        FS["Flask Server\n(app.py\n/video_feed endpoint)"]:::backend
        CM["Camera Module\n(camera.py)"]:::backend
        HC["Haar Cascade Model\n(haarcascade_frontalface_default.xml)"]:::model
    end

    %% Hardware
    HW["Webcam"]:::hardware

    %% Documentation
    Doc["Project Documentation\n(README.md)"]:::doc

    %% Data Flow
    Client -->|"GET /video_feed"| FS
    AE -->|"initializes"| FS
    FS -->|"calls get_frame()"| CM
    CM -->|"read frame"| HW
    CM -->|"run face detection"| HC
    HC -->|"annotated frame"| CM
    CM -->|"returns frame"| FS
    FS -->|"MJPEG stream"| Client

    %% Click Events
    click FS "https://github.com/yashaswinisarangi/real-time-face-detector-/blob/main/app.py"
    click AE "https://github.com/yashaswinisarangi/real-time-face-detector-/blob/main/main.py"
    click CM "https://github.com/yashaswinisarangi/real-time-face-detector-/blob/main/camera.py"
    click HC "https://github.com/yashaswinisarangi/real-time-face-detector-/blob/main/haarcascade_frontalface_default.xml"
    click Doc "https://github.com/yashaswinisarangi/real-time-face-detector-/blob/main/README.md"

    %% Styles
    classDef frontend fill:#ffa500,stroke:#333,stroke-width:1px
    classDef backend fill:#add8e6,stroke:#333,stroke-width:1px
    classDef hardware fill:#90ee90,stroke:#333,stroke-width:1px
    classDef model fill:#dda0dd,stroke:#333,stroke-width:1px
    classDef doc fill:#d3d3d3,stroke:#333,stroke-width:1px
```
