# pushpak1203/heart-disease-mini-web-app architecture

> Architecture diagram of the GitHub repository pushpak1203/heart-disease-mini-web-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pushpak1203/heart-disease-mini-web-app
- Repository: https://github.com/pushpak1203/heart-disease-mini-web-app

## Overview

#### Purpose and Entry Points
This is a local Streamlit dashboard for educational heart-disease risk prediction. It trains and serves a Logistic Regression model over clinical inputs, then presents probability and diagnostic visualizations.

Primary entry points:
- Training CLI: `scripts/train_model.py`
- Streamlit UI: `app.py`
- Prediction-facing logic: `src/predict.py`

#### Training and Artifact Lifecycle
`scripts/train_model.py` is the offline model-building stage. It reads the bundled dataset, applies feature selection/scaling, performs stratified evaluation and cross-validation, then persists the trained estimator and scaler for the dashboard.

Relevant paths:
- `scripts/train_model.py`
- `data/heart.csv`
- `src/preprocessing.py`
- `src/config.py`

The README describes generated `models/heart_model.pkl` and `models/scaler.pkl`, but no `models/` directory is present in the supplied tree; the training command must run before inference if artifacts are absent.

#### Data Contract and Preprocessing
The application’s core feature contract is the Cleveland heart-disease subset: age, sex, chest-pain type, blood pressure, cholesterol, maximum heart rate, exercise angina, and ST depression. The target is `condition`.

`src/preprocessing.py` centralizes transformation behavior so training-time feature preparation can align with prediction-time scaling. `src/config.py` is the likely shared location for paths, feature names, and model-related constants.

Relevant paths:
- `data/heart.csv`
- `src/preprocessing.py`
- `src/config.py`

#### Inference Boundary
`src/predict.py` forms the model-serving boundary between UI values and serialized ML artifacts. It should load the model/scaler, transform a single input row in the expected feature order, and return class/probability outputs.

Relevant paths:
- `src/predict.py`
- `src/preprocessing.py`
- `src/utils.py`

The dashboard should not retrain during normal interaction; it consumes persisted artifacts produced by the training pipeline.

#### Dashboard and Visualization Layer
`app.py` is the Streamlit runtime and interaction controller. It gathers clinical parameters, invokes prediction logic, and renders probability-focused output plus model-insight views such as ROC curve, confusion matrix, and logistic-regression coefficient importance. Plotly is the interactive visualization dependency described by the README.

Relevant paths:
- `app.py`
- `.streamlit/config.toml`
- `src/predict.py`

#### Runtime, Dependencies, and Boundaries
Runtime is Python with Streamlit as the application server. Core data/ML dependencies are Pandas, NumPy, and scikit-learn; Plotly supports visual output. Dependency installation is defined by `requirements.txt`.

Relevant paths:
- `requirements.txt`
- `.streamlit/config.toml`
- `src/__init__.py`

There are no indicated remote APIs, databases, queues, or cloud services. Dataset access and model artifact loading are local filesystem concerns.

Main entry points: [`src/predict.py`](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/src/predict.py) (Prediction Service), [`scripts/train_model.py`](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/scripts/train_model.py) (Training CLI), [`app.py`](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/app.py) (Streamlit App), [`src/preprocessing.py`](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/src/preprocessing.py) (Feature Preparation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Offline Training"]
  node_dataset[("Heart Dataset<br/>CSV dataset<br/>[heart.csv]")]
  node_train["Training CLI<br/>Python script<br/>[train_model.py]"]
  node_model[("Trained Model<br/>serialized estimator")]
  node_scaler[("Feature Scaler<br/>serialized scaler")]
end

subgraph group_serving["Dashboard Runtime"]
  node_streamlit["Streamlit App<br/>UI controller<br/>[app.py]"]
  node_prediction["Prediction Service<br/>inference module<br/>[predict.py]"]
  node_utils["Runtime Utilities<br/>utility module<br/>[utils.py]"]
  node_visuals["Diagnostic Visuals<br/>Streamlit and Plotly views<br/>[app.py]"]
  node_streamlit_config["Streamlit Settings<br/>runtime configuration<br/>[config.toml]"]
end

node_preprocessing["Feature Preparation<br/>preprocessing module<br/>[preprocessing.py]"]
node_config["Shared Model Config<br/>configuration module<br/>[config.py]"]
node_dependencies["Python Dependencies<br/>dependency manifest<br/>[requirements.txt]"]
node_package["Source Package<br/>Python package<br/>[__init__.py]"]

node_dataset -->|"training data"| node_train
node_config -->|"feature contract"| node_train
node_preprocessing -->|"prepare and scale"| node_train
node_train -->|"persists"| node_model
node_train -->|"persists"| node_scaler
node_streamlit_config -->|"configures"| node_streamlit
node_streamlit -->|"clinical inputs"| node_prediction
node_prediction -->|"input transformation"| node_preprocessing
node_config -->|"feature order and paths"| node_prediction
node_model -->|"loads"| node_prediction
node_scaler -->|"loads"| node_prediction
node_utils -->|"supports"| node_prediction
node_prediction -->|"class and probability"| node_streamlit
node_streamlit -->|"renders"| node_visuals
node_dependencies -.->|"ML runtime"| node_train
node_dependencies -.->|"application runtime"| node_streamlit
node_package -.->|"contains"| node_preprocessing
node_package -.->|"contains"| node_prediction

click node_dataset "https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/data/heart.csv"
click node_train "https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/scripts/train_model.py"
click node_preprocessing "https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/src/preprocessing.py"
click node_config "https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/src/config.py"
click node_streamlit "https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/app.py"
click node_prediction "https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/src/predict.py"
click node_utils "https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/src/utils.py"
click node_visuals "https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/app.py"
click node_streamlit_config "https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/.streamlit/config.toml"
click node_dependencies "https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/requirements.txt"
click node_package "https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/src/__init__.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_dataset,node_train,node_model,node_scaler toneBlue
class node_streamlit,node_prediction,node_utils,node_visuals,node_streamlit_config toneAmber
class node_preprocessing,node_config,node_dependencies,node_package toneNeutral
```

## Components

### Offline Training

Builds local inference artifacts.

- [Heart Dataset](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/data/heart.csv): CSV dataset · Cleveland subset with condition target. · `data/heart.csv`
- [Training CLI](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/scripts/train_model.py): Python script · Trains and evaluates logistic regression. · `scripts/train_model.py`
- **Trained Model**: serialized estimator · Generated by training before dashboard inference.
- **Feature Scaler**: serialized scaler · Generated scaling artifact for inference.

### Dashboard Runtime

Serves local interactive predictions.

- [Streamlit App](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/app.py): UI controller · Collects clinical inputs and renders prediction insights. · `app.py`
- [Prediction Service](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/src/predict.py): inference module · Converts one input row into class and probability outputs. · `src/predict.py`
- [Runtime Utilities](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/src/utils.py): utility module · `src/utils.py`
- [Diagnostic Visuals](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/app.py): Streamlit and Plotly views · Shows probability, ROC, confusion matrix, and coefficients. · `app.py`
- [Streamlit Settings](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/.streamlit/config.toml): runtime configuration · `.streamlit/config.toml`

### Other components

- [Feature Preparation](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/src/preprocessing.py): preprocessing module · Keeps training and inference transformations aligned. · `src/preprocessing.py`
- [Shared Model Config](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/src/config.py): configuration module · Defines paths, feature names, and model constants. · `src/config.py`
- [Python Dependencies](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/requirements.txt): dependency manifest · Defines Streamlit, Pandas, NumPy, scikit-learn, and Plotly. · `requirements.txt`
- [Source Package](https://github.com/pushpak1203/heart-disease-mini-web-app/blob/main/src/__init__.py): Python package · `src/__init__.py`

## Connections

- Heart Dataset → Training CLI: training data
- Shared Model Config → Training CLI: feature contract
- Feature Preparation → Training CLI: prepare and scale
- Training CLI → Trained Model: persists
- Training CLI → Feature Scaler: persists
- Streamlit Settings → Streamlit App: configures
- Streamlit App → Prediction Service: clinical inputs
- Prediction Service → Feature Preparation: input transformation
- Shared Model Config → Prediction Service: feature order and paths
- Trained Model → Prediction Service: loads
- Feature Scaler → Prediction Service: loads
- Runtime Utilities → Prediction Service: supports
- Prediction Service → Streamlit App: class and probability
- Streamlit App → Diagnostic Visuals: renders
- Python Dependencies → Training CLI: ML runtime
- Python Dependencies → Streamlit App: application runtime
- Source Package → Feature Preparation: contains
- Source Package → Prediction Service: contains
