# pushpak1203/heart_disease architecture

> Architecture diagram of the GitHub repository pushpak1203/heart_disease, 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
- Repository: https://github.com/pushpak1203/heart_disease

## Overview

#### Purpose and Entry Points
This is a local Streamlit dashboard for educational heart-disease risk prediction. The interactive runtime starts at `app.py`; model artifacts are produced offline by `scripts/train_model.py`. The application consumes the bundled dataset at `data/heart.csv` during training.

#### Streamlit Presentation Layer
`app.py` owns the UI workflow: clinical input collection, prediction display, risk-oriented visualizations, and model-analysis views such as ROC, confusion matrix, and feature importance. Streamlit behavior and visual defaults are configured in `.streamlit/config.toml`.

#### Training Pipeline
`scripts/train_model.py` is the reproducible model-building entry point. It loads `data/heart.csv`, prepares the clinical feature set and `condition` target, performs stratified evaluation/cross-validation, and trains the logistic-regression classifier described by the README. Its output boundary is persisted model/scaler artifacts (the README identifies a `models/` location, though it is absent from the supplied tree).

#### Data Preparation Contract
`src/preprocessing.py` centralizes transformations shared by training or inference, principally feature selection/order and standard scaling. `src/config.py` likely defines the canonical feature/model path constants and therefore forms the contract preventing drift between the CSV schema, trained artifacts, and dashboard inputs.

#### Inference Boundary
`src/predict.py` encapsulates loading trained artifacts and turning one dashboard input record into probability/class predictions. The expected flow is:
`app.py` → input values in canonical feature order → `src/preprocessing.py` scaling → logistic model prediction through `src/predict.py` → UI probability and visual output.

#### Shared Application Support
`src/utils.py` contains supporting utilities used across the application, while `src/__init__.py` establishes `src` as the internal Python package. This separates application orchestration (`app.py`) from reusable ML concerns (`src/`).

#### Runtime and Dependencies
The runtime is Python with Streamlit for the local UI, pandas/NumPy for tabular/numeric handling, scikit-learn for scaling, evaluation, and logistic regression, and Plotly for interactive charts. No network service, database, API, container, or deployment infrastructure is represented in the repository tree; persistence is file-based through the dataset and generated model artifacts.

Main entry points: [`scripts/train_model.py`](https://github.com/pushpak1203/heart_disease/blob/main/scripts/train_model.py) (Model training), [`app.py`](https://github.com/pushpak1203/heart_disease/blob/main/app.py) (Dashboard workflow), [`src/predict.py`](https://github.com/pushpak1203/heart_disease/blob/main/src/predict.py) (Prediction service), [`src/preprocessing.py`](https://github.com/pushpak1203/heart_disease/blob/main/src/preprocessing.py) (Feature preprocessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Streamlit Dashboard"]
  node_app["Dashboard workflow<br/>Streamlit app<br/>[app.py]"]
  node_streamlit_config["UI configuration<br/>Streamlit config<br/>[config.toml]"]
  node_visualizations["Risk &amp; model views<br/>Plotly visualizations<br/>[app.py]"]
end

subgraph group_ml["ML Pipeline"]
  node_training["Model training<br/>Python training script<br/>[train_model.py]"]
  node_dataset[("Heart dataset<br/>CSV dataset<br/>[heart.csv]")]
  node_preprocessing["Feature preprocessing<br/>ML transformations<br/>[preprocessing.py]"]
  node_predict["Prediction service<br/>Inference module<br/>[predict.py]"]
  node_artifacts[("Model &amp; scaler artifacts<br/>Persisted ML artifacts")]
end

subgraph group_support["Shared Support"]
  node_config["ML contract constants<br/>Python configuration<br/>[config.py]"]
  node_utils["Application utilities<br/>Python utilities<br/>[utils.py]"]
  node_src_package["Internal ML package<br/>Python package<br/>[__init__.py]"]
end

node_python_runtime{{"Python ML runtime<br/>Dependencies"}}

node_streamlit_config -->|"configures"| node_app
node_app -->|"submits clinical record"| node_predict
node_app -->|"renders"| node_visualizations
node_predict -->|"uses canonical scaling"| node_preprocessing
node_predict -->|"loads"| node_artifacts
node_training -->|"loads"| node_dataset
node_training -->|"prepares features"| node_preprocessing
node_training -->|"persists model and scaler"| node_artifacts
node_config -->|"defines feature contract"| node_preprocessing
node_config -->|"defines artifact paths"| node_predict
node_config -.->|"aligns schema and outputs"| node_training
node_src_package -.->|"contains"| node_preprocessing
node_src_package -.->|"contains"| node_predict
node_utils -.->|"supports"| node_app
node_python_runtime -.->|"runs"| node_app
node_python_runtime -.->|"trains and evaluates"| node_training

click node_app "https://github.com/pushpak1203/heart_disease/blob/main/app.py"
click node_streamlit_config "https://github.com/pushpak1203/heart_disease/blob/main/.streamlit/config.toml"
click node_visualizations "https://github.com/pushpak1203/heart_disease/blob/main/app.py"
click node_training "https://github.com/pushpak1203/heart_disease/blob/main/scripts/train_model.py"
click node_dataset "https://github.com/pushpak1203/heart_disease/blob/main/data/heart.csv"
click node_preprocessing "https://github.com/pushpak1203/heart_disease/blob/main/src/preprocessing.py"
click node_predict "https://github.com/pushpak1203/heart_disease/blob/main/src/predict.py"
click node_config "https://github.com/pushpak1203/heart_disease/blob/main/src/config.py"
click node_utils "https://github.com/pushpak1203/heart_disease/blob/main/src/utils.py"
click node_src_package "https://github.com/pushpak1203/heart_disease/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_app,node_streamlit_config,node_visualizations toneBlue
class node_training,node_dataset,node_preprocessing,node_predict,node_artifacts toneAmber
class node_config,node_utils,node_src_package toneMint
class node_python_runtime toneNeutral
```

## Components

### Streamlit Dashboard

- [Dashboard workflow](https://github.com/pushpak1203/heart_disease/blob/main/app.py): Streamlit app · Collects clinical inputs and presents predictions and analysis. · `app.py`
- [UI configuration](https://github.com/pushpak1203/heart_disease/blob/main/.streamlit/config.toml): Streamlit config · `.streamlit/config.toml`
- [Risk & model views](https://github.com/pushpak1203/heart_disease/blob/main/app.py): Plotly visualizations · Prediction risk, ROC, confusion matrix, and feature importance views. · `app.py`

### ML Pipeline

- [Model training](https://github.com/pushpak1203/heart_disease/blob/main/scripts/train_model.py): Python training script · Builds and evaluates the logistic-regression classifier. · `scripts/train_model.py`
- [Heart dataset](https://github.com/pushpak1203/heart_disease/blob/main/data/heart.csv): CSV dataset · Clinical features and condition target. · `data/heart.csv`
- [Feature preprocessing](https://github.com/pushpak1203/heart_disease/blob/main/src/preprocessing.py): ML transformations · Canonical feature selection/order and standard scaling. · `src/preprocessing.py`
- [Prediction service](https://github.com/pushpak1203/heart_disease/blob/main/src/predict.py): Inference module · Loads artifacts and returns probability and class predictions. · `src/predict.py`
- **Model & scaler artifacts**: Persisted ML artifacts · Generated offline and loaded for dashboard inference.

### Shared Support

- [ML contract constants](https://github.com/pushpak1203/heart_disease/blob/main/src/config.py): Python configuration · Canonical feature and model-path constants. · `src/config.py`
- [Application utilities](https://github.com/pushpak1203/heart_disease/blob/main/src/utils.py): Python utilities · `src/utils.py`
- [Internal ML package](https://github.com/pushpak1203/heart_disease/blob/main/src/__init__.py): Python package · `src/__init__.py`

### Other components

- **Python ML runtime**: Dependencies · Streamlit, pandas/NumPy, scikit-learn, and Plotly.

## Connections

- UI configuration → Dashboard workflow: configures
- Dashboard workflow → Prediction service: submits clinical record
- Dashboard workflow → Risk & model views: renders
- Prediction service → Feature preprocessing: uses canonical scaling
- Prediction service → Model & scaler artifacts: loads
- Model training → Heart dataset: loads
- Model training → Feature preprocessing: prepares features
- Model training → Model & scaler artifacts: persists model and scaler
- ML contract constants → Feature preprocessing: defines feature contract
- ML contract constants → Prediction service: defines artifact paths
- ML contract constants → Model training: aligns schema and outputs
- Internal ML package → Feature preprocessing: contains
- Internal ML package → Prediction service: contains
- Application utilities → Dashboard workflow: supports
- Python ML runtime → Dashboard workflow: runs
- Python ML runtime → Model training: trains and evaluates
