# avinashhsinghh/heart-rate-detection architecture

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

- Interactive diagram: https://gitdiagram.com/avinashhsinghh/heart-rate-detection
- Repository: https://github.com/avinashhsinghh/heart-rate-detection

## Overview

##### Project type and purpose
- This is a full-stack, real-time, browser-based application (“Pulse”) for non-contact heart-rate detection.
- Frontend: HTML5/JavaScript (Canvas, WebRTC, headtrackr.js, D3.js, Rickshaw).
- Backend: Python (Flask + flask_sockets), NumPy, Independent Component Analysis (JADE), Fast Fourier Transform (FFT).

##### File structure
- Top-level:
- app.py – Flask entry point and WebSocket routes
- jade.py & model.py – ICA and FFT algorithms
- deploy.sh, Procfile, runtime.txt – deployment scripts/config for Heroku or similar
- requirements.txt – Python dependencies
- static/ – JS, CSS, images
- templates/ – Jinja2 HTML templates
- Patterns:
- Monolithic backend serving a single WebSocket API
- Frontend signal-processing pipeline in JS, offloading heavy math to Python server

##### README
- Documents data flow: webcam → Canvas → headtrackr ROI → channel averages → WebSocket → Python (normalize → ICA → FFT → select heartbeat → send back) → browser (compute BPM → render graphs).
- Lists major libraries and frameworks used in each tier.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Browser Client"
        direction TB
        A["Webcam & Video Capture"]:::frontend
        B["Canvas & Headtrackr ROI Extraction"]:::frontend
        C["RGB Extraction & Time-Series Buffering"]:::frontend
        D1["DSP Utilities (dsp.js)"]:::frontend
        D2["Matrix Math (matrixmath.js)"]:::frontend
        E["Optional JS ICA Demo (jadeICA.js)"]:::frontend
        F["WebSocket Client"]:::frontend
        G1["UI Logic (main.js)"]:::frontend
        G2["Animation (animate.js)"]:::frontend
        subgraph "Browser Assets"
            U["underscore.js"]:::frontend
            V["CSS & Fonts"]:::frontend
            W["HTML Templates"]:::frontend
        end
    end

    subgraph "WebSocket & Python Server"
        direction TB
        H["Flask App & WS Layer"]:::backend
        I["ICA Module (jade.py)"]:::backend
        J["FFT & Power Filtering (model.py)"]:::backend
    end

    subgraph "Deployment & Infrastructure"
        direction TB
        K["Procfile"]:::infra
        L["deploy.sh"]:::infra
        M["runtime.txt"]:::infra
        N["requirements.txt"]:::infra
    end

    A -->|"video frames"| B
    B -->|"pixel averages"| C
    C --> D1
    D1 --> D2
    C -.->|"optional demo"| E
    D2 --> F
    E -.-> F
    F -->|"JSON frames"| H
    H -->|"normalize → ICA"| I
    I -->|"signals"| J
    J -->|"heartbeat data"| H
    H -->|"processed data"| F
    F -->|"BPM data"| G1
    G1 --> G2

    click A "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/static/js/camera.js"
    click B "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/static/js/headtrackr.js"
    click C "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/static/js/mathmatical.js"
    click D1 "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/static/js/dsp.js"
    click D2 "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/static/js/matrixmath.js"
    click E "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/static/js/jadeICA.js"
    click F "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/static/js/websocket.js"
    click G1 "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/static/js/main.js"
    click G2 "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/static/js/animate.js"
    click U "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/static/js/underscore-min.js"
    click V "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/static/css/main.css"
    click W "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/templates/index.html"
    click H "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/app.py"
    click I "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/jade.py"
    click J "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/model.py"
    click K "https://github.com/avinashhsinghh/heart-rate-detection/tree/master/Procfile"
    click L "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/deploy.sh"
    click M "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/runtime.txt"
    click N "https://github.com/avinashhsinghh/heart-rate-detection/blob/master/requirements.txt"

    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#000,stroke-width:1px
```
