# youngturing/stroke-prediction architecture

> Architecture diagram of the GitHub repository youngturing/stroke-prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/youngturing/stroke-prediction
- Repository: https://github.com/youngturing/stroke-prediction

## Overview

This repository is a stroke-probability application: users submit patient features to a FastAPI endpoint, which validates and preprocesses them, loads a serialized classifier, and returns a probability. A separate modeling workflow loads transformed stroke data, splits and optionally oversamples it, trains classifiers, evaluates them, and saves model and metric artifacts. The repository also includes a dataset-download utility. The inference model artifact is referenced by the API but is not present in the file tree; edges reflect only relationships shown in the excerpts or README.

Main entry points: [`app/main.py`](https://github.com/youngturing/stroke-prediction/blob/main/app/main.py) (FastAPI routes), [`model/model.py`](https://github.com/youngturing/stroke-prediction/blob/main/model/model.py) (Training workflow), [`data/download_stroke_dataset.py`](https://github.com/youngturing/stroke-prediction/blob/main/data/download_stroke_dataset.py) (Dataset downloader), [`data/stroke_data_transformed.csv`](https://github.com/youngturing/stroke-prediction/blob/main/data/stroke_data_transformed.csv) (Transformed stroke data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Prediction API"]
  node_api["FastAPI routes<br/>[main.py]"]
  node_validation["Patient input model<br/>[main.py]"]
  node_preprocess["Feature preparation<br/>[main.py]"]
  node_classifier["Serialized classifier"]
  node_probability["Prediction response<br/>[main.py]"]
end

subgraph group_modeling["Model development"]
  node_model_workflow["Training workflow<br/>[model.py]"]
  node_loader["Data loading<br/>[model.py]"]
  node_transform["Split and SMOTE<br/>[model.py]"]
  node_trainer["Classifier training<br/>[model.py]"]
  node_evaluation["Model evaluation<br/>[model.py]"]
  node_model_artifacts["Trained model files"]
  node_metrics["Evaluation metrics<br/>[model.py]"]
end

subgraph group_data["Dataset"]
  node_dataset_download["Dataset downloader"]
  node_dataset[("Transformed stroke data")]
end

node_user(("Application user"))
node_kaggle["Kaggle dataset service"]

node_user -->|"submits features"| node_api
node_api -->|"validates input"| node_validation
node_api -->|"prepares features"| node_preprocess
node_api -->|"loads model"| node_classifier
node_api -->|"requests probability"| node_classifier
node_api -->|"returns prediction"| node_probability
node_model_workflow -->|"loads data"| node_loader
node_loader -->|"reads CSV"| node_dataset
node_model_workflow -->|"splits and resamples"| node_transform
node_model_workflow -->|"trains classifiers"| node_trainer
node_trainer -->|"saves models"| node_model_artifacts
node_model_workflow -->|"evaluates models"| node_evaluation
node_evaluation -->|"loads models"| node_model_artifacts
node_evaluation -->|"writes metrics"| node_metrics
node_dataset_download -->|"downloads archive"| node_kaggle

click node_api "https://github.com/youngturing/stroke-prediction/blob/main/app/main.py"
click node_validation "https://github.com/youngturing/stroke-prediction/blob/main/app/main.py"
click node_preprocess "https://github.com/youngturing/stroke-prediction/blob/main/app/main.py"
click node_probability "https://github.com/youngturing/stroke-prediction/blob/main/app/main.py"
click node_model_workflow "https://github.com/youngturing/stroke-prediction/blob/main/model/model.py"
click node_loader "https://github.com/youngturing/stroke-prediction/blob/main/model/model.py"
click node_transform "https://github.com/youngturing/stroke-prediction/blob/main/model/model.py"
click node_trainer "https://github.com/youngturing/stroke-prediction/blob/main/model/model.py"
click node_evaluation "https://github.com/youngturing/stroke-prediction/blob/main/model/model.py"
click node_metrics "https://github.com/youngturing/stroke-prediction/blob/main/model/model.py"
click node_dataset_download "https://github.com/youngturing/stroke-prediction/blob/main/data/download_stroke_dataset.py"
click node_dataset "https://github.com/youngturing/stroke-prediction/blob/main/data/stroke_data_transformed.csv"

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_api,node_validation,node_preprocess,node_classifier,node_probability,node_user toneBlue
class node_model_workflow,node_loader,node_transform,node_trainer,node_evaluation,node_model_artifacts,node_metrics toneAmber
class node_dataset_download,node_dataset toneMint
class node_kaggle toneIndigo
```

## Components

### Prediction API

- [FastAPI routes](https://github.com/youngturing/stroke-prediction/blob/main/app/main.py): `app/main.py`
- [Patient input model](https://github.com/youngturing/stroke-prediction/blob/main/app/main.py): `app/main.py`
- [Feature preparation](https://github.com/youngturing/stroke-prediction/blob/main/app/main.py): `app/main.py`
- **Serialized classifier**
- [Prediction response](https://github.com/youngturing/stroke-prediction/blob/main/app/main.py): `app/main.py`

### Model development

- [Training workflow](https://github.com/youngturing/stroke-prediction/blob/main/model/model.py): `model/model.py`
- [Data loading](https://github.com/youngturing/stroke-prediction/blob/main/model/model.py): `model/model.py`
- [Split and SMOTE](https://github.com/youngturing/stroke-prediction/blob/main/model/model.py): `model/model.py`
- [Classifier training](https://github.com/youngturing/stroke-prediction/blob/main/model/model.py): `model/model.py`
- [Model evaluation](https://github.com/youngturing/stroke-prediction/blob/main/model/model.py): `model/model.py`
- **Trained model files**
- [Evaluation metrics](https://github.com/youngturing/stroke-prediction/blob/main/model/model.py): `model/model.py`

### Dataset

- [Dataset downloader](https://github.com/youngturing/stroke-prediction/blob/main/data/download_stroke_dataset.py): `data/download_stroke_dataset.py`
- [Transformed stroke data](https://github.com/youngturing/stroke-prediction/blob/main/data/stroke_data_transformed.csv): `data/stroke_data_transformed.csv`

### Other components

- **Application user**
- **Kaggle dataset service**

## Connections

- Application user → FastAPI routes: submits features (evidence: `README.md`)
- FastAPI routes → Patient input model: validates input (evidence: `app/main.py`)
- FastAPI routes → Feature preparation: prepares features (evidence: `app/main.py`)
- FastAPI routes → Serialized classifier: loads model (evidence: `app/main.py`)
- FastAPI routes → Serialized classifier: requests probability (evidence: `app/main.py`)
- FastAPI routes → Prediction response: returns prediction (evidence: `app/main.py`)
- Training workflow → Data loading: loads data (evidence: `model/model.py`)
- Data loading → Transformed stroke data: reads CSV (evidence: `model/model.py`)
- Training workflow → Split and SMOTE: splits and resamples (evidence: `model/model.py`)
- Training workflow → Classifier training: trains classifiers (evidence: `model/model.py`)
- Classifier training → Trained model files: saves models (evidence: `model/model.py`)
- Training workflow → Model evaluation: evaluates models (evidence: `model/model.py`)
- Model evaluation → Trained model files: loads models (evidence: `model/model.py`)
- Model evaluation → Evaluation metrics: writes metrics (evidence: `model/model.py`)
- Dataset downloader → Kaggle dataset service: downloads archive (evidence: `data/download_stroke_dataset.py`)
