# harshithk9515-dev/cardiotwin architecture

> Architecture diagram of the GitHub repository harshithk9515-dev/cardiotwin, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harshithk9515-dev/cardiotwin
- Repository: https://github.com/harshithk9515-dev/cardiotwin

## Overview

CardioTwin is a synthetic-data cardiac decompensation prediction prototype. Its workflow generates static EHR baselines and wearable telemetry, builds normalized patient windows, trains a late-fusion model, then serves patient playback and risk scoring in a Streamlit dashboard. The dashboard also presents integrated-gradient explanations and intervention what-if scoring. Training and dashboard wiring are supported by the excerpts and README; details of unsampled dashboard calls are not inferred.

Main entry points: [`src/app.py`](https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/app.py) (Twin dashboard), [`src/train.py`](https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/train.py) (Training and evaluation), [`src/dataset.py`](https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/dataset.py) (Windowing and scaling), [`src/model.py`](https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/model.py) (Fusion risk model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Synthetic cohort"]
  node_generator["Cohort generator"]
  node_ehr[("Static EHR data<br/>[static_ehr.csv]")]
  node_wearables[("Wearable data")]
end

subgraph group_ml["Model pipeline"]
  node_windowing["Windowing and scaling<br/>[dataset.py]"]
  node_trainer["Training and evaluation<br/>[train.py]"]
  node_network["Fusion risk model<br/>[model.py]"]
  node_checkpoint[("Model checkpoint")]
end

subgraph group_clinical["Clinician dashboard"]
  node_dashboard["Twin dashboard<br/>[app.py]"]
  node_explanations["Feature explanations<br/>[explainability.py]"]
  node_whatif["What-if scoring<br/>[app.py]"]
end

node_clinician(("Clinician"))

node_generator -->|"writes"| node_ehr
node_generator -->|"writes"| node_wearables
node_ehr -->|"loads"| node_windowing
node_wearables -->|"loads"| node_windowing
node_trainer -->|"uses"| node_windowing
node_trainer -->|"trains"| node_network
node_trainer -->|"saves"| node_checkpoint
node_clinician -->|"uses"| node_dashboard
node_dashboard -->|"loads"| node_checkpoint
node_dashboard -->|"scores windows"| node_network
node_dashboard -->|"shows drivers"| node_explanations
node_dashboard -->|"offers simulation"| node_whatif
node_whatif -->|"re-scores"| node_network

click node_generator "https://github.com/harshithk9515-dev/cardiotwin/blob/master/data/generate_synthetic_data.py"
click node_ehr "https://github.com/harshithk9515-dev/cardiotwin/blob/master/data/static_ehr.csv"
click node_wearables "https://github.com/harshithk9515-dev/cardiotwin/blob/master/data/dynamic_wearables.csv"
click node_windowing "https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/dataset.py"
click node_trainer "https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/train.py"
click node_network "https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/model.py"
click node_checkpoint "https://github.com/harshithk9515-dev/cardiotwin/blob/master/models/cardiotwin_weights.pth"
click node_dashboard "https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/app.py"
click node_explanations "https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/explainability.py"
click node_whatif "https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/app.py"

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_generator,node_ehr,node_wearables toneBlue
class node_windowing,node_trainer,node_network,node_checkpoint toneAmber
class node_dashboard,node_explanations,node_whatif toneMint
class node_clinician toneIndigo
```

## Components

### Synthetic cohort

- [Cohort generator](https://github.com/harshithk9515-dev/cardiotwin/blob/master/data/generate_synthetic_data.py): `data/generate_synthetic_data.py`
- [Static EHR data](https://github.com/harshithk9515-dev/cardiotwin/blob/master/data/static_ehr.csv): `data/static_ehr.csv`
- [Wearable data](https://github.com/harshithk9515-dev/cardiotwin/blob/master/data/dynamic_wearables.csv): `data/dynamic_wearables.csv`

### Model pipeline

- [Windowing and scaling](https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/dataset.py): `src/dataset.py`
- [Training and evaluation](https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/train.py): `src/train.py`
- [Fusion risk model](https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/model.py): `src/model.py`
- [Model checkpoint](https://github.com/harshithk9515-dev/cardiotwin/blob/master/models/cardiotwin_weights.pth): `models/cardiotwin_weights.pth`

### Clinician dashboard

- [Twin dashboard](https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/app.py): `src/app.py`
- [Feature explanations](https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/explainability.py): `src/explainability.py`
- [What-if scoring](https://github.com/harshithk9515-dev/cardiotwin/blob/master/src/app.py): `src/app.py`

### Other components

- **Clinician**

## Connections

- Cohort generator → Static EHR data: writes (evidence: `data/generate_synthetic_data.py`)
- Cohort generator → Wearable data: writes (evidence: `data/generate_synthetic_data.py`)
- Static EHR data → Windowing and scaling: loads (evidence: `src/dataset.py`)
- Wearable data → Windowing and scaling: loads (evidence: `src/dataset.py`)
- Training and evaluation → Windowing and scaling: uses (evidence: `src/train.py`)
- Training and evaluation → Fusion risk model: trains (evidence: `src/train.py`)
- Training and evaluation → Model checkpoint: saves (evidence: `src/train.py`)
- Clinician → Twin dashboard: uses (evidence: `README.md`)
- Twin dashboard → Model checkpoint: loads (evidence: `src/app.py`)
- Twin dashboard → Fusion risk model: scores windows (evidence: `src/app.py`)
- Twin dashboard → Feature explanations: shows drivers (evidence: `README.md`)
- Twin dashboard → What-if scoring: offers simulation (evidence: `README.md`)
- What-if scoring → Fusion risk model: re-scores (evidence: `README.md`)
