# kvh03/heart-disease-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/kvh03/heart-disease-prediction
- Repository: https://github.com/kvh03/heart-disease-prediction

## Overview

##### Main Components
- Frontend Client:
- Represented by the React application contained in the top-level “src” and “public” directories.
- React components such as Home, Description, and Visualization and note that they are bundled using Create React App.
- Backend Server:
- The “backend” directory houses a Node.js server (server.js) that likely exposes API endpoints consumed by the frontend.
- That it has its own package management (node_modules, package.json) and separate configuration.
- Machine Learning / Data Processing:
- Python component – train_model.py – which is used to generate the heart disease prediction model (heart_disease_model.joblib) using the provided data (heart_disease_data.csv).
- Infrastructure & Deployment:
- Deployment configuration elements such as the .env file and GitHub workflows (in .github/workflows) which help with automated builds/CI.
- Static Assets:
- Files such as index.html, manifest.json, and robots.txt in the “public” folder.

##### Relationships and Data Flows
- The Browser/Client (React app):
- Initiates requests (user interactions) that communicate with the Node.js backend via RESTful APIs.
- Displays data and visualization results rendered by React.
- The Backend Server (Node.js):
- Handles incoming API requests from the frontend.
- Optionally, it uses the pre-trained machine learning model (heart_disease_model.joblib) to process predictions or other computations.
- ML Training Pipeline:
- Separate offline process run by train_model.py that takes in heart_disease_data.csv, trains the model, and outputs an updated heart_disease_model.joblib.
- This process might be triggered manually or as part of an automated pipeline (note the .env file for configuration settings).
- CI/CD/DevOps:
- GitHub workflows that manage continuous integration, automated testing, and deployment processes.

##### Architectural Patterns & Design Principles
- Separation of Concerns:
- Clear division between the client (presentation layer) and the backend (API and business logic layer).
- Isolate the machine learning training and prediction logic from the core API server.
- Modular Design:
- The React project structure (with separate directories for components) suggests a component-based architecture.
- The backend is segmented, likely following modular Node.js design.
- Integration Points:
- The Node.js backend serves as an integration point for the frontend and the ML components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Client
    subgraph "Frontend Client"
        direction TB
        ReactApp["React Application (src + public)"]:::frontend
        Home["Home Component"]:::frontend
        Description["Description Component"]:::frontend
        Visualization["Visualization Component"]:::frontend
        StaticAssets["Static Assets (index.html, manifest.json, robots.txt)"]:::static

        ReactApp -->|"includes"| Home
        ReactApp -->|"includes"| Description
        ReactApp -->|"includes"| Visualization
        ReactApp -->|"serves"| StaticAssets
    end

    %% Backend Server
    subgraph "Backend Server"
        direction TB
        NodeServer["Node.js Server (server.js)"]:::backend
        NodeConfig["Package Configuration (package.json, node_modules, package-lock.json)"]:::backend

        NodeServer -->|"uses"| NodeConfig
    end

    %% Machine Learning Pipeline
    subgraph "Machine Learning Pipeline"
        direction TB
        MLScript["Model Training Script (train_model.py)"]:::ml
        DataFile["Data File (heart_disease_data.csv)"]:::ml
        ModelFile["Trained Model (heart_disease_model.joblib)"]:::ml

        MLScript -->|"trainsModelOn"| DataFile
        MLScript -->|"outputs"| ModelFile
    end

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        direction TB
        EnvConfig["Environment Config (.env)"]:::deployment
        CICD["CI/CD Workflows (GitHub)"]:::deployment
    end

    %% Relationships between components
    ReactApp -->|"callsAPI"| NodeServer
    NodeServer -->|"integratesWith"| ModelFile
    CICD -->|"buildsDeploys"| ReactApp
    CICD -->|"buildsDeploys"| NodeServer
    EnvConfig -->|"configures"| NodeServer
    EnvConfig -->|"configures"| MLScript

    %% Click Events for Frontend Client
    click ReactApp "https://github.com/kvh03/heart-disease-prediction/tree/master/src"
    click Home "https://github.com/kvh03/heart-disease-prediction/blob/master/src/components/Home/home.js"
    click Home "https://github.com/kvh03/heart-disease-prediction/blob/master/src/components/Home/home.css"
    click Description "https://github.com/kvh03/heart-disease-prediction/blob/master/src/components/Description/description.js"
    click Description "https://github.com/kvh03/heart-disease-prediction/blob/master/src/components/Description/description.css"
    click Visualization "https://github.com/kvh03/heart-disease-prediction/blob/master/src/components/Visualization/visualization.js"
    click Visualization "https://github.com/kvh03/heart-disease-prediction/blob/master/src/components/Visualization/visualization.css"
    click StaticAssets "https://github.com/kvh03/heart-disease-prediction/tree/master/public"
    click StaticAssets "https://github.com/kvh03/heart-disease-prediction/blob/master/public/index.html"
    click StaticAssets "https://github.com/kvh03/heart-disease-prediction/blob/master/public/manifest.json"
    click StaticAssets "https://github.com/kvh03/heart-disease-prediction/blob/master/public/robots.txt"

    %% Click Events for Backend Server
    click NodeServer "https://github.com/kvh03/heart-disease-prediction/blob/master/backend/server.js"
    click NodeConfig "https://github.com/kvh03/heart-disease-prediction/blob/master/backend/package.json"
    click NodeConfig "https://github.com/kvh03/heart-disease-prediction/tree/master/backend/node_modules"
    click NodeConfig "https://github.com/kvh03/heart-disease-prediction/blob/master/backend/package-lock.json"

    %% Click Events for Machine Learning Pipeline
    click MLScript "https://github.com/kvh03/heart-disease-prediction/blob/master/train_model.py"
    click DataFile "https://github.com/kvh03/heart-disease-prediction/blob/master/heart_disease_data.csv"
    click ModelFile "https://github.com/kvh03/heart-disease-prediction/blob/master/heart_disease_model.joblib"

    %% Click Events for Infrastructure & Deployment
    click EnvConfig "https://github.com/kvh03/heart-disease-prediction/blob/master/.env"
    click CICD "https://github.com/kvh03/heart-disease-prediction/blob/master/.github/workflows/master_heartdisease-prediction.yml"

    %% Styles
    classDef frontend fill:#f4c2c2,stroke:#333,stroke-width:2px;
    classDef backend fill:#c2f0c2,stroke:#333,stroke-width:2px;
    classDef ml fill:#c2d6f4,stroke:#333,stroke-width:2px;
    classDef deployment fill:#f4e1c2,stroke:#333,stroke-width:2px;
    classDef static fill:#e2c2f4,stroke:#333,stroke-width:2px;
```
