# kavin-adarsh/heart_disease_prediction architecture

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

- Interactive diagram: https://gitdiagram.com/kavin-adarsh/heart_disease_prediction
- Repository: https://github.com/kavin-adarsh/heart_disease_prediction

## Overview

##### Project type and purpose
- Full-stack, single-page/web application that serves a machine-learning model.
- Purpose: Accept patient inputs via a browser UI, run them through a Keras/TensorFlow model, and display prediction results.

##### File structure
- app.py – Flask entry point (backend web server & API).
- models/model_X.h5 – Pre-trained ML model artifact.
- static/ – CSS, JS, images for UI.
- templates/index.html – Jinja2 template for the HTML form and result display.
- hdPred.ipynb & heart.csv – Training pipeline (not part of production runtime, but relevant for Dev/ML component).

##### README
- Simple instructions to launch Flask and open the browser.
- No additional architectural sections—so we infer key components from code and folders.

##### Main components and their interactions
a. Client (Web Browser)
– Hosts the UI, sends HTTP requests.
b. Web Server (Flask app.py)
– Receives form data (POST), loads model, invokes prediction, renders template.
c. Model Artifact Store (models/model_X.h5)
– Persistent storage for the trained Keras model.
d. Template Engine & Static Server
– Jinja2 templates in templates/, static assets in static/.
e. (Optional) Training Pipeline
– Jupyter Notebook (hdPred.ipynb) and heart.csv data file create/validate model_X.h5.

##### Relationships & data flows
- Browser → HTTP GET / → Flask → templates/index.html → Browser
- Browser submits form → HTTP POST → Flask
- Flask loads model_X.h5 → TensorFlow/Keras predict() → result
- Flask renders result via template → Browser
- (In Dev) hdPred.ipynb reads heart.csv → trains model → writes model_X.h5

##### Architectural patterns & design principles
- MVC-style separation:
– View: HTML/CSS (templates + static)
– Controller: Flask request handlers in app.py
– Model: Keras model file
- One-process single-service architecture (could be containerized as one Docker service).
- Stateless API calls; model file loaded once on startup or per request.

##### Technologies & frameworks
- Python 3
- Flask (web framework)
- Jinja2 (templating)
- Keras / TensorFlow (ML inference)
- Jupyter Notebook (training)
- heart.csv – CSV dataset

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Runtime Prediction Service"
        direction TB
        Browser["Client (Web Browser UI)"]:::frontend
        Flask["Flask Server\n(app.py)\nport: 5000"]:::backend
        Template["Template Engine\n(Jinja2 Views)"]:::frontend
        Static["Static Asset Server\n(CSS/JS/Images)"]:::frontend
        ModelStore["Model Artifact Store\n(models/model_X.h5)"]:::datastore
    end

    subgraph "Dev/Training Pipeline"
        direction TB
        Notebook["Training Pipeline Notebook\n(hdPred.ipynb)"]:::dev
        CSV["Training Dataset\n(heart.csv)"]:::datastore
    end

    subgraph "Documentation"
        README["Project README\n(README.md)"]:::doc
    end

    %% Runtime flows
    Browser -->|"HTTP GET /"| Flask
    Browser -->|"HTTP POST /predict"| Flask
    Flask -->|"load model_X.h5\npredict()"| ModelStore
    Flask -->|"render prediction"| Template
    Flask -->|"serve static assets"| Static
    Template -->|"HTML" | Browser
    Static -->|"CSS/JS/Images"| Browser

    %% Dev flows
    Notebook -->|"reads CSV data"| CSV
    Notebook -->|"trains model"| ModelStore

    %% Click Events
    click Browser "https://github.com/kavin-adarsh/heart_disease_prediction/blob/main/templates/index.html"
    click Flask "https://github.com/kavin-adarsh/heart_disease_prediction/blob/main/app.py"
    click Template "https://github.com/kavin-adarsh/heart_disease_prediction/blob/main/templates/index.html"
    click Static "https://github.com/kavin-adarsh/heart_disease_prediction/tree/main/static/"
    click ModelStore "https://github.com/kavin-adarsh/heart_disease_prediction/blob/main/models/model_X.h5"
    click Notebook "https://github.com/kavin-adarsh/heart_disease_prediction/blob/main/hdPred.ipynb"
    click CSV "https://github.com/kavin-adarsh/heart_disease_prediction/blob/main/heart.csv"
    click README "https://github.com/kavin-adarsh/heart_disease_prediction/blob/main/README.md"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef datastore fill:#FFFACD,stroke:#333,stroke-width:1px
    classDef dev fill:#D3D3D3,stroke:#666,stroke-width:1px,stroke-dasharray: 5 5
    classDef doc fill:#E0E0E0,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2
```
