# astreonix/cardioai architecture

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

- Interactive diagram: https://gitdiagram.com/astreonix/cardioai
- Repository: https://github.com/astreonix/cardioai

## Overview

CardioAI is a Flask heart-disease risk assessment platform. A user submits 13 clinical fields; the app validates them, prepares features, runs the trained model, presents a risk result with SHAP explanations, and records the assessment. Users can review assessment history, ask Gemini contextual questions, and download PDF reports. The runtime is concentrated in app.py, so several distinct responsibilities share that source path. README capabilities fill gaps where route implementation excerpts were omitted; unsampled implementation details are not inferred.

Main entry points: [`app.py`](https://github.com/astreonix/cardioai/blob/main/app.py) (Flask routes), [`templates/predict.html`](https://github.com/astreonix/cardioai/blob/main/templates/predict.html) (Assessment form), [`templates/history.html`](https://github.com/astreonix/cardioai/blob/main/templates/history.html) (History dashboard), [`templates/chat.html`](https://github.com/astreonix/cardioai/blob/main/templates/chat.html) (Chat page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_web["Flask routes<br/>[app.py]"]
  node_assessment_form["Assessment form<br/>[predict.html]"]
  node_history_view["History dashboard<br/>[history.html]"]
  node_chat_view["Chat page<br/>[chat.html]"]
end

subgraph group_assessment["Risk assessment"]
  node_input_validation["Input validation<br/>[app.py]"]
  node_feature_prep["Feature preparation<br/>[app.py]"]
  node_scaler["Feature scaler<br/>[scaler.pkl]"]
  node_classifier["Risk classifier<br/>[cardioai_model.pkl]"]
  node_shap["SHAP explanations<br/>[app.py]"]
end

subgraph group_records["Assessment records"]
  node_database[("SQLite records<br/>[app.py]")]
  node_history["History queries<br/>[app.py]"]
  node_report["PDF reports<br/>[app.py]"]
end

subgraph group_assistance["Follow-up assistance"]
  node_gemini["Gemini service"]
  node_chat["Chat handling<br/>[app.py]"]
end

node_user(("User"))

node_user -->|"enters data"| node_assessment_form
node_assessment_form -->|"submits assessment"| node_web
node_web -->|"validates input"| node_input_validation
node_web -->|"builds features"| node_feature_prep
node_web -->|"transforms features"| node_scaler
node_web -->|"predicts risk"| node_classifier
node_web -->|"generates explanations"| node_shap
node_web -->|"saves assessment"| node_database
node_web -->|"renders form"| node_assessment_form
node_user -->|"reviews history"| node_history_view
node_history_view -->|"requests history"| node_web
node_web -->|"queries records"| node_history
node_history -->|"reads assessments"| node_database
node_web -->|"renders history"| node_history_view
node_user -->|"opens chat"| node_chat_view
node_chat_view -->|"sends message"| node_web
node_web -->|"handles message"| node_chat
node_chat -->|"loads context"| node_database
node_chat -->|"requests reply"| node_gemini
node_chat -->|"stores messages"| node_database
node_user -->|"requests report"| node_web
node_web -->|"loads assessment"| node_database
node_web -->|"generates PDF"| node_report
node_report -->|"logs report"| node_database

click node_web "https://github.com/astreonix/cardioai/blob/main/app.py"
click node_assessment_form "https://github.com/astreonix/cardioai/blob/main/templates/predict.html"
click node_history_view "https://github.com/astreonix/cardioai/blob/main/templates/history.html"
click node_chat_view "https://github.com/astreonix/cardioai/blob/main/templates/chat.html"
click node_input_validation "https://github.com/astreonix/cardioai/blob/main/app.py"
click node_feature_prep "https://github.com/astreonix/cardioai/blob/main/app.py"
click node_scaler "https://github.com/astreonix/cardioai/blob/main/models/scaler.pkl"
click node_classifier "https://github.com/astreonix/cardioai/blob/main/models/cardioai_model.pkl"
click node_shap "https://github.com/astreonix/cardioai/blob/main/app.py"
click node_database "https://github.com/astreonix/cardioai/blob/main/app.py"
click node_history "https://github.com/astreonix/cardioai/blob/main/app.py"
click node_report "https://github.com/astreonix/cardioai/blob/main/app.py"
click node_chat "https://github.com/astreonix/cardioai/blob/main/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_web,node_assessment_form,node_history_view,node_chat_view,node_user toneBlue
class node_input_validation,node_feature_prep,node_scaler,node_classifier,node_shap toneAmber
class node_database,node_history,node_report toneMint
class node_gemini,node_chat toneRose
```

## Components

### User experience

- [Flask routes](https://github.com/astreonix/cardioai/blob/main/app.py): `app.py`
- [Assessment form](https://github.com/astreonix/cardioai/blob/main/templates/predict.html): `templates/predict.html`
- [History dashboard](https://github.com/astreonix/cardioai/blob/main/templates/history.html): `templates/history.html`
- [Chat page](https://github.com/astreonix/cardioai/blob/main/templates/chat.html): `templates/chat.html`

### Risk assessment

- [Input validation](https://github.com/astreonix/cardioai/blob/main/app.py): `app.py`
- [Feature preparation](https://github.com/astreonix/cardioai/blob/main/app.py): `app.py`
- [Feature scaler](https://github.com/astreonix/cardioai/blob/main/models/scaler.pkl): `models/scaler.pkl`
- [Risk classifier](https://github.com/astreonix/cardioai/blob/main/models/cardioai_model.pkl): `models/cardioai_model.pkl`
- [SHAP explanations](https://github.com/astreonix/cardioai/blob/main/app.py): `app.py`

### Assessment records

- [SQLite records](https://github.com/astreonix/cardioai/blob/main/app.py): `app.py`
- [History queries](https://github.com/astreonix/cardioai/blob/main/app.py): `app.py`
- [PDF reports](https://github.com/astreonix/cardioai/blob/main/app.py): `app.py`

### Follow-up assistance

- **Gemini service**
- [Chat handling](https://github.com/astreonix/cardioai/blob/main/app.py): `app.py`

### Other components

- **User**

## Connections

- User → Assessment form: enters data (evidence: `README.md`)
- Assessment form → Flask routes: submits assessment (evidence: `README.md`)
- Flask routes → Input validation: validates input (evidence: `app.py`)
- Flask routes → Feature preparation: builds features (evidence: `app.py`)
- Flask routes → Feature scaler: transforms features (evidence: `app.py`)
- Flask routes → Risk classifier: predicts risk (evidence: `app.py`)
- Flask routes → SHAP explanations: generates explanations (evidence: `README.md`)
- Flask routes → SQLite records: saves assessment (evidence: `app.py`)
- Flask routes → Assessment form: renders form (evidence: `README.md`)
- User → History dashboard: reviews history (evidence: `README.md`)
- History dashboard → Flask routes: requests history (evidence: `README.md`)
- Flask routes → History queries: queries records (evidence: `README.md`)
- History queries → SQLite records: reads assessments (evidence: `README.md`)
- Flask routes → History dashboard: renders history (evidence: `README.md`)
- User → Chat page: opens chat (evidence: `README.md`)
- Chat page → Flask routes: sends message (evidence: `README.md`)
- Flask routes → Chat handling: handles message (evidence: `app.py`)
- Chat handling → SQLite records: loads context (evidence: `app.py`)
- Chat handling → Gemini service: requests reply (evidence: `README.md`)
- Chat handling → SQLite records: stores messages (evidence: `app.py`)
- User → Flask routes: requests report (evidence: `README.md`)
- Flask routes → SQLite records: loads assessment (evidence: `README.md`)
- Flask routes → PDF reports: generates PDF (evidence: `README.md`)
- PDF reports → SQLite records: logs report (evidence: `app.py`)
