# mainakadak02/cardioguard-api architecture

> Architecture diagram of the GitHub repository mainakadak02/cardioguard-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mainakadak02/cardioguard-api
- Repository: https://github.com/mainakadak02/cardioguard-api

## Overview

Heart Guard is a Flask backend that accepts heart-health features and coordinates a risk prediction, returning a risk level and probability. For high-risk results, it ranks nearby hospitals using the submitted coordinates and a CSV-loaded hospital list. The repository also includes a script that trains and saves the classifier. The README gives no further product details; this map is based on the sampled source, and does not assume an unshown client or training-data file.

Main entry points: [`app.py`](https://github.com/mainakadak02/cardioguard-api/blob/main/app.py) (Prediction route), [`heart_model.pkl`](https://github.com/mainakadak02/cardioguard-api/blob/main/heart_model.pkl) (Trained classifier), [`train_model.py`](https://github.com/mainakadak02/cardioguard-api/blob/main/train_model.py) (Model training), [`hospitals.csv`](https://github.com/mainakadak02/cardioguard-api/blob/main/hospitals.csv) (Hospital records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Prediction API"]
  node_predict_route["Prediction route<br/>[app.py]"]
  node_feature_frame["Feature framing<br/>[app.py]"]
end

subgraph group_risk["Risk Assessment"]
  node_classifier["Trained classifier<br/>[heart_model.pkl]"]
  node_risk_gate["Risk threshold<br/>[app.py]"]
end

subgraph group_hospitals["Hospital Lookup"]
  node_hospital_loader["Hospital loader<br/>[app.py]"]
  node_hospital_csv["Hospital records<br/>[hospitals.csv]"]
  node_hospital_ranker["Distance ranking<br/>[app.py]"]
end

subgraph group_training["Model Training"]
  node_trainer["Model training<br/>[train_model.py]"]
end

node_user(("API caller"))

node_user -->|"submits features"| node_predict_route
node_predict_route -->|"frames features"| node_feature_frame
node_predict_route -->|"requests probabilities"| node_classifier
node_predict_route -->|"applies threshold"| node_risk_gate
node_risk_gate -->|"returns risk result"| node_predict_route
node_hospital_loader -->|"reads records"| node_hospital_csv
node_predict_route -->|"requests nearby results"| node_hospital_ranker
node_hospital_ranker -->|"returns top five"| node_predict_route
node_trainer -->|"saves model"| node_classifier

click node_predict_route "https://github.com/mainakadak02/cardioguard-api/blob/main/app.py"
click node_feature_frame "https://github.com/mainakadak02/cardioguard-api/blob/main/app.py"
click node_classifier "https://github.com/mainakadak02/cardioguard-api/blob/main/heart_model.pkl"
click node_risk_gate "https://github.com/mainakadak02/cardioguard-api/blob/main/app.py"
click node_hospital_loader "https://github.com/mainakadak02/cardioguard-api/blob/main/app.py"
click node_hospital_csv "https://github.com/mainakadak02/cardioguard-api/blob/main/hospitals.csv"
click node_hospital_ranker "https://github.com/mainakadak02/cardioguard-api/blob/main/app.py"
click node_trainer "https://github.com/mainakadak02/cardioguard-api/blob/main/train_model.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_predict_route,node_feature_frame toneBlue
class node_classifier,node_risk_gate toneAmber
class node_hospital_loader,node_hospital_csv,node_hospital_ranker,node_user toneMint
class node_trainer toneRose
```

## Components

### Prediction API

- [Prediction route](https://github.com/mainakadak02/cardioguard-api/blob/main/app.py): `app.py`
- [Feature framing](https://github.com/mainakadak02/cardioguard-api/blob/main/app.py): `app.py`

### Risk Assessment

- [Trained classifier](https://github.com/mainakadak02/cardioguard-api/blob/main/heart_model.pkl): `heart_model.pkl`
- [Risk threshold](https://github.com/mainakadak02/cardioguard-api/blob/main/app.py): `app.py`

### Hospital Lookup

- [Hospital loader](https://github.com/mainakadak02/cardioguard-api/blob/main/app.py): `app.py`
- [Hospital records](https://github.com/mainakadak02/cardioguard-api/blob/main/hospitals.csv): `hospitals.csv`
- [Distance ranking](https://github.com/mainakadak02/cardioguard-api/blob/main/app.py): `app.py`

### Model Training

- [Model training](https://github.com/mainakadak02/cardioguard-api/blob/main/train_model.py): `train_model.py`

### Other components

- **API caller**

## Connections

- API caller → Prediction route: submits features (evidence: `app.py`)
- Prediction route → Feature framing: frames features (evidence: `app.py`)
- Prediction route → Trained classifier: requests probabilities (evidence: `app.py`)
- Prediction route → Risk threshold: applies threshold (evidence: `app.py`)
- Risk threshold → Prediction route: returns risk result (evidence: `app.py`)
- Hospital loader → Hospital records: reads records (evidence: `app.py`)
- Prediction route → Distance ranking: requests nearby results (evidence: `app.py`)
- Distance ranking → Prediction route: returns top five (evidence: `app.py`)
- Model training → Trained classifier: saves model (evidence: `train_model.py`)
