# dianacmayorgar/stroke-prediction architecture

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

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

## Overview

##### Project type and purpose
- This is a machine-learning–driven, data-visualization web application built with Streamlit.
- Purpose: provide interactive stroke-risk predictions using five pre-trained models (Logistic Regression, Naive Bayes, SVM, Decision Tree, Random Forest) plus model-explainability via LIME, and embed a Power BI dashboard for data insights.

##### File structure
- Top-level scripts:
- app.py (main Streamlit UI and orchestration)
- app(1).py, Stroke_prediction_project.py, Project_labelEncoding.py (data prep / alternative entry points)
- Directories:
- /models (five .pkl model files)
- /data (raw & cleaned CSV)
- Artifacts:
- Dashboard project – Stroke Prediction.pbix (Power BI file)
- Config: requirements.txt for Python dependencies.

##### Examining README insights
- Confirms stack: Python, Streamlit, pandas/numpy, matplotlib, tensorflow (possibly for LIME integration), lime, Power BI embed
- No microservices – single-process Streamlit app
- Supports: model inference, interpretability, embedded BI visualization.

##### Main components & relationships
a. Components
- User Interface (Streamlit)
- Input Form (Streamlit widgets)
- Data Preparation Module (Project_labelEncoding.py)
- Model Inference Module (loads .pkl from /models)
- Interpretability Module (LIME explainer)
- Power BI Embed (pbix dashboard via Streamlit iframe)
- Data Layer (CSV under /data)
- (Optional) Model Training Scripts (Stroke_prediction_project.py)

b. Relationships & data flows
1. User interacts with Input Form →
2. Input passed to Data Preparation →
3. Cleaned features forwarded to Model Inference →
- Models (.pkl) loaded from disk → produce predictions
4. Predictions & input → passed to LIME Explainer →
5. Prediction + explanation returned to UI →
6. UI renders charts, tables, text →
7. Separately, Power BI dashboard loaded in embedded frame

c. Architectural patterns & design principles
- Layered architecture: Presentation (UI), Application Logic (inference + LIME), Data Persistence (models + CSV).
- Single-process monolith (no microservices) but clear separation of concerns via modules.
- Extensibility: new models can be added to /models and discovered by the inference loader.

d. Key technologies & libraries
- Streamlit for UI & routing
- pandas/numpy for data handling
- pickle for model serialization
- lime for local interpretability
- matplotlib/plotly (if used) for on-the-fly plots
- Power BI embed via Streamlit components

##### Additional notes
- Optional branches: if a user chooses one of five models, show an internal switch/routing in the Inference module.
- Training script module (Stroke_prediction_project.py) as an optional “offline” component, separate from the real-time inference flow.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Actors
    User["User"]:::external

    %% UI Layer
    subgraph "UI Layer"
        InputForm["Input Form"]:::frontend
        ResultsPanel["Results Panel"]:::frontend
        PowerBIEmbed["Power BI Dashboard"]:::external
    end

    %% Application Logic
    subgraph "Application Logic"
        DataPrep["Data Preparation Module"]:::ml
        Inference["Model Inference Module"]:::ml
        LIMEExplainer["Interpretability Module (LIME)"]:::ml
    end

    %% Data Stores
    subgraph "Data Stores"
        RawData["Raw Dataset (CSV)"]:::data
        CleanData["Cleaned Dataset (CSV)"]:::data
        ModelsStore["Pre-trained Models"]:::data
    end

    %% Offline Training
    subgraph "Offline Training"
        TrainingScripts["Model Training Scripts"]:::ml
    end

    %% Relationships
    User -->|"fills form"| InputForm
    InputForm -->|"raw input"| DataPrep
    RawData -->|"read data"| DataPrep
    DataPrep -->|"clean features"| CleanData
    CleanData --> DataPrep
    DataPrep -->|"feature vector"| Inference
    Inference -->|"loads model"| ModelsStore
    Inference -->|"prediction"| LIMEExplainer
    LIMEExplainer -->|"explanation"| ResultsPanel
    Inference -->|"prediction"| ResultsPanel
    ResultsPanel -->|"renders visuals"| User
    ResultsPanel -->|"embed frame"| PowerBIEmbed
    TrainingScripts -.->|"offline training"| ModelsStore

    %% Click Events
    click InputForm "https://github.com/dianacmayorgar/stroke-prediction/blob/main/app.py"
    click UserInterface "https://github.com/dianacmayorgar/stroke-prediction/blob/main/app.py"
    click AltUI "https://github.com/dianacmayorgar/stroke-prediction/blob/main/app(1).py"
    click DataPrep "https://github.com/dianacmayorgar/stroke-prediction/blob/main/Project_labelEncoding.py"
    click TrainingScripts "https://github.com/dianacmayorgar/stroke-prediction/blob/main/Stroke_prediction_project.py"
    click Inference "https://github.com/dianacmayorgar/stroke-prediction/blob/main/app.py"
    click LIMEExplainer "https://github.com/dianacmayorgar/stroke-prediction/blob/main/app.py"
    click ModelsStore "https://github.com/dianacmayorgar/stroke-prediction/blob/main/models/Decision_Tree.pkl"
    click ModelsStore "https://github.com/dianacmayorgar/stroke-prediction/blob/main/models/Logistic_Regression.pkl"
    click ModelsStore "https://github.com/dianacmayorgar/stroke-prediction/blob/main/models/Naive_Bayes.pkl"
    click ModelsStore "https://github.com/dianacmayorgar/stroke-prediction/blob/main/models/Random_Forest.pkl"
    click ModelsStore "https://github.com/dianacmayorgar/stroke-prediction/blob/main/models/SVC.pkl"
    click RawData "https://github.com/dianacmayorgar/stroke-prediction/blob/main/data/train_2v.csv"
    click CleanData "https://github.com/dianacmayorgar/stroke-prediction/blob/main/data/train_2v-clean.csv"
    click PowerBIEmbed "https://github.com/dianacmayorgar/stroke-prediction/blob/main/Dashboard project - Stroke Prediction.pbix"
    click Config "https://github.com/dianacmayorgar/stroke-prediction/blob/main/requirements.txt"
    click Metadata "https://github.com/dianacmayorgar/stroke-prediction/blob/main/README.md"
    click GitIgnore "https://github.com/dianacmayorgar/stroke-prediction/blob/main/.gitignore"

    %% Styling
    classDef frontend fill:#bfdfff,stroke:#0366d6,color:#0366d6
    classDef ml fill:#d4f4dd,stroke:#2c662d,color:#2c662d
    classDef data fill:#ffe4b5,stroke:#cc8400,color:#cc8400
    classDef external fill:#e0e0e0,stroke:#888888,color:#444444
```
