# praveenofficial12/ai-heart-disease-risk-predictor architecture

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

- Interactive diagram: https://gitdiagram.com/praveenofficial12/ai-heart-disease-risk-predictor
- Repository: https://github.com/praveenofficial12/ai-heart-disease-risk-predictor

## Overview

CardioAI is a Flask web application for assessing cardiovascular risk and tracking results. Users sign in, then submit health information manually or upload a medical report; the application calculates a risk category, explanation, and recommendations, and presents results and history. Authentication and prediction persistence use MongoDB. The README describes OCR-based report extraction, while the sampled upload route uses preset values, so its connection to OCR is documented but not verified in the sampled route. The graph preserves documented capabilities without asserting unseen calls.

Main entry points: [`backend/app.py`](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/app.py) (Flask routes), [`backend/ocr_pipeline.py`](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/ocr_pipeline.py) (Report text extraction), [`frontend/templates`](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/tree/main/frontend/templates) (Web pages), [`frontend/static/js/main.js`](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/frontend/static/js/main.js) (Browser interactions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_web_ui["Web pages"]
  node_ui_js["Browser interactions<br/>[main.js]"]
end

subgraph group_workflow["Assessment workflow"]
  node_flask["Flask routes<br/>[app.py]"]
  node_manual["Manual assessment<br/>[predictor.html]"]
  node_upload["Report upload<br/>[upload_report.html]"]
  node_ocr["Report text extraction<br/>[ocr_pipeline.py]"]
  node_ocr_engine["OCR engine<br/>[ocr_engine.py]"]
  node_report_parser["Report parser<br/>[report_parser.py]"]
  node_predictor["Risk scoring<br/>[predictor.py]"]
  node_explanation["Clinical explanation<br/>[explainer.py]"]
  node_pdf["PDF generation<br/>[pdf_generator.py]"]
  node_voice["Voice output<br/>[voice.py]"]
end

subgraph group_account["Accounts and history"]
  node_auth["Authentication<br/>[auth.py]"]
  node_profile_history["Profile and history"]
  node_database[("MongoDB collections<br/>[database.py]")]
end

subgraph group_services["External services"]
  node_openai{{"OpenAI API"}}
end

node_user(("User"))

node_user -->|"uses"| node_web_ui
node_web_ui -->|"submits forms"| node_flask
node_ui_js -->|"enhances"| node_web_ui
node_flask -->|"authenticates"| node_auth
node_auth -->|"reads and writes"| node_database
node_flask -->|"reads and writes"| node_database
node_manual -->|"submits metrics"| node_flask
node_upload -->|"submits report"| node_flask
node_flask -.->|"extracts report data"| node_ocr
node_ocr -.->|"extracts text"| node_ocr_engine
node_ocr -.->|"parses text"| node_report_parser
node_flask -->|"calculates risk"| node_predictor
node_flask -.->|"requests explanation"| node_explanation
node_explanation -->|"generates text"| node_openai
node_flask -->|"renders pages"| node_profile_history
node_flask -.->|"generates report"| node_pdf
node_ui_js -.->|"speaks results"| node_voice

click node_web_ui "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/tree/main/frontend/templates"
click node_ui_js "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/frontend/static/js/main.js"
click node_flask "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/app.py"
click node_manual "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/frontend/templates/predictor.html"
click node_upload "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/frontend/templates/upload_report.html"
click node_ocr "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/ocr_pipeline.py"
click node_ocr_engine "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/ocr/ocr_engine.py"
click node_report_parser "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/ocr/report_parser.py"
click node_predictor "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/predictor.py"
click node_explanation "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/explainer.py"
click node_pdf "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/pdf_generator.py"
click node_voice "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/voice.py"
click node_auth "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/auth.py"
click node_profile_history "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/tree/main/frontend/templates"
click node_database "https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/database.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_ui,node_ui_js,node_user toneBlue
class node_flask,node_manual,node_upload,node_ocr,node_ocr_engine,node_report_parser,node_predictor,node_explanation,node_pdf,node_voice toneAmber
class node_auth,node_profile_history,node_database toneMint
class node_openai toneRose
```

## Components

### User interface

- [Web pages](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/tree/main/frontend/templates): `frontend/templates`
- [Browser interactions](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/frontend/static/js/main.js): `frontend/static/js/main.js`

### Assessment workflow

- [Flask routes](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/app.py): `backend/app.py`
- [Manual assessment](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/frontend/templates/predictor.html): `frontend/templates/predictor.html`
- [Report upload](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/frontend/templates/upload_report.html): `frontend/templates/upload_report.html`
- [Report text extraction](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/ocr_pipeline.py): `backend/ocr_pipeline.py`
- [OCR engine](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/ocr/ocr_engine.py): `backend/ocr/ocr_engine.py`
- [Report parser](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/ocr/report_parser.py): `backend/ocr/report_parser.py`
- [Risk scoring](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/predictor.py): `backend/predictor.py`
- [Clinical explanation](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/explainer.py): `backend/explainer.py`
- [PDF generation](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/pdf_generator.py): `backend/pdf_generator.py`
- [Voice output](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/voice.py): `backend/voice.py`

### Accounts and history

- [Authentication](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/auth.py): `backend/auth.py`
- [Profile and history](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/tree/main/frontend/templates): `frontend/templates`
- [MongoDB collections](https://github.com/praveenofficial12/ai-heart-disease-risk-predictor/blob/main/backend/database.py): `backend/database.py`

### External services

- **OpenAI API**

### Other components

- **User**

## Connections

- User → Web pages: uses (evidence: `README.md`)
- Web pages → Flask routes: submits forms (evidence: `README.md`)
- Browser interactions → Web pages: enhances (evidence: `frontend/static/js/main.js`)
- Flask routes → Authentication: authenticates (evidence: `backend/app.py`)
- Authentication → MongoDB collections: reads and writes (evidence: `backend/auth.py`)
- Flask routes → MongoDB collections: reads and writes (evidence: `backend/app.py`)
- Manual assessment → Flask routes: submits metrics (evidence: `README.md`)
- Report upload → Flask routes: submits report (evidence: `README.md`)
- Flask routes → Report text extraction: extracts report data (evidence: `README.md`)
- Report text extraction → OCR engine: extracts text
- Report text extraction → Report parser: parses text
- Flask routes → Risk scoring: calculates risk (evidence: `backend/app.py`)
- Flask routes → Clinical explanation: requests explanation (evidence: `README.md`)
- Clinical explanation → OpenAI API: generates text (evidence: `backend/explainer.py`)
- Flask routes → Profile and history: renders pages (evidence: `README.md`)
- Flask routes → PDF generation: generates report
- Browser interactions → Voice output: speaks results
