# prateekm180/ecg-analysis architecture

> Architecture diagram of the GitHub repository prateekm180/ecg-analysis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prateekm180/ecg-analysis
- Repository: https://github.com/prateekm180/ecg-analysis

## Overview

CORVIS is an ECG-image digitization and analysis application: a user uploads an ECG image, the backend extracts trace points and clinical metrics, and the frontend presents the returned results. The backend separates image preparation, lead-panel detection, per-panel waveform reconstruction, and clinical analysis. The frontend also contains 3D heart and waveform visualizations. One integration caveat is visible in the excerpts: the frontend passes `data.points` to its signal view, while the backend response shown contains `leads`, `lead_names`, and `medical_report`. Some frontend rendering lines are omitted, so uncertain component wiring is not inferred.

Main entry points: [`ECG-Backend/main.py`](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py) (Analyze endpoint), [`ECG-Frontend/src/App.jsx`](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Frontend/src/App.jsx) (Upload and results UI), [`ECG-Frontend/src/EcgCanvas.jsx`](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Frontend/src/EcgCanvas.jsx) (ECG visualizations), [`ECG-Frontend/public/realistic_human_heart.glb`](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Frontend/public/realistic_human_heart.glb) (Heart model asset)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_app["Upload and results UI<br/>[App.jsx]"]
  node_canvas["ECG visualizations<br/>[EcgCanvas.jsx]"]
  node_heart_asset["Heart model asset"]
  node_signal_view["Signal and reference view<br/>[EcgCanvas.jsx]"]
  node_heart_view["3D heart view<br/>[EcgCanvas.jsx]"]
end

subgraph group_api["Analysis API"]
  node_api_route["Analyze endpoint<br/>[main.py]"]
  node_api_response["Leads and report response<br/>[main.py]"]
end

subgraph group_reconstruction["Signal Reconstruction"]
  node_image_decode["Image decoding<br/>[main.py]"]
  node_ink_mask["Ink mask<br/>[main.py]"]
  node_panel_detection["Lead panel detection<br/>[main.py]"]
  node_panel_digitization["Panel digitization<br/>[main.py]"]
end

subgraph group_clinical["Clinical Analysis"]
  node_lead_selection["Metrics lead selection<br/>[main.py]"]
  node_clinical_metrics["Clinical metrics<br/>[main.py]"]
end

node_user(("ECG uploader"))

node_user -->|"selects image"| node_app
node_app -->|"uploads image"| node_api_route
node_api_route -->|"decodes bytes"| node_image_decode
node_api_route -->|"builds mask"| node_ink_mask
node_api_route -->|"finds panels"| node_panel_detection
node_api_route -->|"digitizes panels"| node_panel_digitization
node_api_route -->|"selects metrics trace"| node_lead_selection
node_lead_selection -->|"analyzes signal"| node_clinical_metrics
node_api_route -->|"returns leads and report"| node_api_response
node_api_response -->|"returns JSON"| node_app
node_app -->|"renders waveform"| node_signal_view
node_canvas -->|"loads model"| node_heart_asset

click node_app "https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Frontend/src/App.jsx"
click node_canvas "https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Frontend/src/EcgCanvas.jsx"
click node_heart_asset "https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Frontend/public/realistic_human_heart.glb"
click node_api_route "https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py"
click node_image_decode "https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py"
click node_ink_mask "https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py"
click node_panel_detection "https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py"
click node_panel_digitization "https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py"
click node_lead_selection "https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py"
click node_clinical_metrics "https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py"
click node_api_response "https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py"
click node_signal_view "https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Frontend/src/EcgCanvas.jsx"
click node_heart_view "https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Frontend/src/EcgCanvas.jsx"

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_app,node_canvas,node_heart_asset,node_signal_view,node_heart_view toneBlue
class node_api_route,node_api_response toneAmber
class node_image_decode,node_ink_mask,node_panel_detection,node_panel_digitization toneMint
class node_lead_selection,node_clinical_metrics toneRose
class node_user toneIndigo
```

## Components

### Frontend

- [Upload and results UI](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Frontend/src/App.jsx): `ECG-Frontend/src/App.jsx`
- [ECG visualizations](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Frontend/src/EcgCanvas.jsx): `ECG-Frontend/src/EcgCanvas.jsx`
- [Heart model asset](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Frontend/public/realistic_human_heart.glb): `ECG-Frontend/public/realistic_human_heart.glb`
- [Signal and reference view](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Frontend/src/EcgCanvas.jsx): `ECG-Frontend/src/EcgCanvas.jsx`
- [3D heart view](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Frontend/src/EcgCanvas.jsx): `ECG-Frontend/src/EcgCanvas.jsx`

### Analysis API

- [Analyze endpoint](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py): `ECG-Backend/main.py`
- [Leads and report response](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py): `ECG-Backend/main.py`

### Signal Reconstruction

- [Image decoding](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py): `ECG-Backend/main.py`
- [Ink mask](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py): `ECG-Backend/main.py`
- [Lead panel detection](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py): `ECG-Backend/main.py`
- [Panel digitization](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py): `ECG-Backend/main.py`

### Clinical Analysis

- [Metrics lead selection](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py): `ECG-Backend/main.py`
- [Clinical metrics](https://github.com/prateekm180/ecg-analysis/blob/main/ECG-Backend/main.py): `ECG-Backend/main.py`

### Other components

- **ECG uploader**

## Connections

- ECG uploader → Upload and results UI: selects image
- Upload and results UI → Analyze endpoint: uploads image
- Analyze endpoint → Image decoding: decodes bytes
- Analyze endpoint → Ink mask: builds mask
- Analyze endpoint → Lead panel detection: finds panels
- Analyze endpoint → Panel digitization: digitizes panels
- Analyze endpoint → Metrics lead selection: selects metrics trace
- Metrics lead selection → Clinical metrics: analyzes signal
- Analyze endpoint → Leads and report response: returns leads and report
- Leads and report response → Upload and results UI: returns JSON
- Upload and results UI → Signal and reference view: renders waveform
- ECG visualizations → Heart model asset: loads model
