# phnxlabs/broad-ecg2af architecture

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

- Interactive diagram: https://gitdiagram.com/phnxlabs/broad-ecg2af
- Repository: https://github.com/phnxlabs/broad-ecg2af

## Overview

This Gradio app accepts an HD5 ECG upload and returns four predictions: incident atrial-fibrillation survival, sex, age, and atrial-fibrillation classification. Its runtime flow validates the upload, converts ECG leads into a normalized tensor, runs a pretrained TensorFlow model, interprets the outputs, and displays sliders and probability charts. The runner reads configuration and wires the model, processor, visualizer, and interface. The README documents these capabilities; no separate storage or asynchronous processing subsystem is implemented.

Main entry points: [`app/interface.py`](https://github.com/phnxlabs/broad-ecg2af/blob/main/app/interface.py) (Gradio interface), [`scripts/run_app.py`](https://github.com/phnxlabs/broad-ecg2af/blob/main/scripts/run_app.py) (App runner), [`app/model_handler.py`](https://github.com/phnxlabs/broad-ecg2af/blob/main/app/model_handler.py) (ECG model), [`app/ecg_processor.py`](https://github.com/phnxlabs/broad-ecg2af/blob/main/app/ecg_processor.py) (HD5 preprocessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_gradio["Gradio interface<br/>[interface.py]"]
  node_output_format["Prediction formatting<br/>[interface.py]"]
end

subgraph group_inference["ECG inference"]
  node_processor["HD5 preprocessing<br/>[ecg_processor.py]"]
  node_model["ECG model<br/>[model_handler.py]"]
  node_visualizer["Probability charts<br/>[visualizer.py]"]
end

subgraph group_startup["Runtime setup"]
  node_runner["App runner<br/>[run_app.py]"]
  node_config["App configuration<br/>[config.yaml]"]
end

node_user(("ECG user"))
node_tensorflow["TensorFlow runtime"]

node_user -->|"uploads HD5"| node_gradio
node_gradio -->|"preprocesses file"| node_processor
node_gradio -->|"requests predictions"| node_model
node_gradio -->|"formats predictions"| node_output_format
node_output_format -->|"renders charts"| node_visualizer
node_gradio -->|"displays results"| node_user
node_model -->|"loads and predicts"| node_tensorflow
node_runner -->|"reads settings"| node_config
node_runner -->|"initializes"| node_model
node_runner -->|"initializes"| node_processor
node_runner -->|"initializes"| node_visualizer
node_runner -->|"launches"| node_gradio

click node_gradio "https://github.com/phnxlabs/broad-ecg2af/blob/main/app/interface.py"
click node_output_format "https://github.com/phnxlabs/broad-ecg2af/blob/main/app/interface.py"
click node_processor "https://github.com/phnxlabs/broad-ecg2af/blob/main/app/ecg_processor.py"
click node_model "https://github.com/phnxlabs/broad-ecg2af/blob/main/app/model_handler.py"
click node_visualizer "https://github.com/phnxlabs/broad-ecg2af/blob/main/app/visualizer.py"
click node_runner "https://github.com/phnxlabs/broad-ecg2af/blob/main/scripts/run_app.py"
click node_config "https://github.com/phnxlabs/broad-ecg2af/blob/main/config/config.yaml"

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_gradio,node_output_format,node_user toneBlue
class node_processor,node_model,node_visualizer toneAmber
class node_runner,node_config toneMint
class node_tensorflow toneIndigo
```

## Components

### User interface

- [Gradio interface](https://github.com/phnxlabs/broad-ecg2af/blob/main/app/interface.py): `app/interface.py`
- [Prediction formatting](https://github.com/phnxlabs/broad-ecg2af/blob/main/app/interface.py): `app/interface.py`

### ECG inference

- [HD5 preprocessing](https://github.com/phnxlabs/broad-ecg2af/blob/main/app/ecg_processor.py): `app/ecg_processor.py`
- [ECG model](https://github.com/phnxlabs/broad-ecg2af/blob/main/app/model_handler.py): `app/model_handler.py`
- [Probability charts](https://github.com/phnxlabs/broad-ecg2af/blob/main/app/visualizer.py): `app/visualizer.py`

### Runtime setup

- [App runner](https://github.com/phnxlabs/broad-ecg2af/blob/main/scripts/run_app.py): `scripts/run_app.py`
- [App configuration](https://github.com/phnxlabs/broad-ecg2af/blob/main/config/config.yaml): `config/config.yaml`

### Other components

- **ECG user**
- **TensorFlow runtime**

## Connections

- ECG user → Gradio interface: uploads HD5 (evidence: `README.md`)
- Gradio interface → HD5 preprocessing: preprocesses file (evidence: `app/interface.py`)
- Gradio interface → ECG model: requests predictions (evidence: `app/interface.py`)
- Gradio interface → Prediction formatting: formats predictions (evidence: `app/interface.py`)
- Prediction formatting → Probability charts: renders charts (evidence: `app/interface.py`)
- Gradio interface → ECG user: displays results (evidence: `README.md`)
- ECG model → TensorFlow runtime: loads and predicts (evidence: `app/model_handler.py`)
- App runner → App configuration: reads settings (evidence: `scripts/run_app.py`)
- App runner → ECG model: initializes (evidence: `scripts/run_app.py`)
- App runner → HD5 preprocessing: initializes (evidence: `scripts/run_app.py`)
- App runner → Probability charts: initializes (evidence: `scripts/run_app.py`)
- App runner → Gradio interface: launches (evidence: `scripts/run_app.py`)
