# umayashaswi/heart-disease-prediction architecture

> Architecture diagram of the GitHub repository umayashaswi/heart-disease-prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/umayashaswi/heart-disease-prediction
- Repository: https://github.com/umayashaswi/heart-disease-prediction

## Overview

##### Project type and purpose
- This is a lightweight full-stack web application for heart disease prediction.
- The core functionality: collect patient inputs via a web form, feed them to a pre-trained Random Forest model, and render the prediction result in the browser.

##### File structure
- Top-level:
- Heart_disease_prediction.ipynb – exploratory notebook (data analysis & model training).
- app.py – Flask application entry point (serves pages, handles form submissions).
- heart1.csv – raw dataset (used offline for model training).
- random_forest_model.pkl – serialized ML model.
- templates – Jinja2 HTML templates (views).
- No external microservices or databases—everything is in-process and file-based.

##### README
- Contains only a demonstration link, so no extra architectural guidance there.

a. Main components
1. Client (Web Browser)
2. HTTP Layer / WSGI Server (Flask)
3. View Layer (templates + static files)
4. Controller Layer (app.py routes & form handlers)
5. Model Layer (Random Forest model + data I/O)
6. Data Store (flat files: heart1.csv for notebook, random_forest_model.pkl at runtime)

b. Relationships & interactions
- User → (1) loads “home.html” or “index.html” from Flask → browser renders form.
- User submits form → HTTP POST → Flask route (“/predict”) → Controller reads form data.
- Controller loads random_forest_model.pkl into memory → passes input into ML model → gets prediction.
- Controller renders a result template (e.g., h1.html) with the prediction → sent back to browser.
- Static files/images served alongside templates for UI assets.
- Notebook (Heart_disease_prediction.ipynb) interacts offline with heart1.csv to train & export random_forest_model.pkl (not in the live request path).

c. Architectural patterns & principles
- MVC-style separation:
- Model: serialized ML object & CSV used for training.
- View: Jinja2 templates in /templates + static assets in /static.
- Controller: Flask routes in app.py.
- Single monolithic service—no external DB or third‐party APIs.
- Stateless request handling (each prediction loads the model or retains it in memory across requests).

d. Key technologies/frameworks
- Python 3 + Flask (web framework)
- Jinja2 (templating)
- scikit-learn Random Forest saved via pickle
- HTML/CSS/JavaScript (client side)
- CSV flat file for training data

##### Elements
- Browser → Flask App (HTTP GET/POST)
- Flask App → Templates & Static Files (serve UI)
- Flask App → Random Forest Model (load & predict)
- Notebook → CSV → Model (train & serialize)
- Frontend (blue), Backend (green), Offline Training Workflow (orange).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend" 
        Browser["Web Browser"]:::frontend
    end

    subgraph "Backend"
        FlaskApp["Flask App (app.py)"]:::backend
        subgraph "View Layer"
            Templates["Jinja2 Templates"]:::backend
            StaticAssets["Static Assets (CSS/JS/Images)"]:::backend
            StaticImages["Static Images"]:::backend
        end
        RandomForestModel["Random Forest Model (.pkl)"]:::backend
    end

    subgraph "Offline Training Workflow"
        Notebook["Training Notebook (.ipynb)"]:::offline
        CSV["Raw Dataset (CSV)"]:::offline
    end

    Browser -->|"HTTP GET/POST"| FlaskApp
    FlaskApp -->|"serve UI"| Templates
    FlaskApp -->|"serve static files"| StaticAssets
    StaticAssets -->|"images"| StaticImages
    FlaskApp -->|"load & predict"| RandomForestModel
    Notebook -->|"train on"| CSV
    Notebook -->|"export model"| RandomForestModel

    click FlaskApp "https://github.com/umayashaswi/heart-disease-prediction/blob/main/app.py"
    click Templates "https://github.com/umayashaswi/heart-disease-prediction/tree/main/templates/"
    click StaticAssets "https://github.com/umayashaswi/heart-disease-prediction/tree/main/static/"
    click StaticImages "https://github.com/umayashaswi/heart-disease-prediction/tree/main/static/images/"
    click RandomForestModel "https://github.com/umayashaswi/heart-disease-prediction/blob/main/random_forest_model.pkl"
    click Notebook "https://github.com/umayashaswi/heart-disease-prediction/blob/main/Heart_disease_prediction.ipynb"
    click CSV "https://github.com/umayashaswi/heart-disease-prediction/blob/main/heart1.csv"

    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef offline fill:#FFA500,stroke:#333,stroke-width:1px
```
