# kumar-laxmi/heart-disease-prediction-system architecture

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

- Interactive diagram: https://gitdiagram.com/kumar-laxmi/heart-disease-prediction-system
- Repository: https://github.com/kumar-laxmi/heart-disease-prediction-system

## Overview

##### Project Type and Purpose
- This is a full-stack, monolithic Django web application enhanced with a Machine Learning component for heart disease prediction.
- The “health_desease” folder is the Django project (settings, routing, ASGI/WSGI), and “health” is the primary Django app (models, views, templates, static files, REST serializers, API views).
- It uses SQLite as its database, Bootstrap/CSS/JS for front-end styling, and Python ML libraries (scikit-learn, pandas, numpy) for training and prediction.

##### File Structure Analysis
Top-level:
- manage.py – Django CLI
- health_desease/ – Django project config
- health/ – core app (models, views, serializers, templates, static assets)
- Machine_Learning/ – Jupyter notebook and raw CSV for offline ML experimentation
- db.sqlite3, media/ – persistent storage (DB, uploaded CSV, images)
- .github/workflows – CI (CodeQL analysis)
Key patterns:
- MVC:
– Models in health/models.py
– Views/API endpoints in health/views.py & health/api_views.py
– Templates in health/templates & static assets in health/static
- REST API layer via serializers (health/serializers.py) & API views
- ML logic lives partly in the notebook and partly in a helper function (prdict_heart_disease) invoked by a Django view or API endpoint.

##### README Insights
- Describes modules for Patient, Doctor, Admin flows.
- Technology stack confirms Django, Bootstrap, scikit-learn, SQLite.
- ML training uses GradientBoostingClassifier on data loaded from a CSV stored in the database (Admin_Health_CSV model).

a. Main Components
1. Client Layer
– Web Browser (Patient/Doctor/Admin)
2. Presentation Layer
– Django Templates + Static Assets (CSS, JS, Images)
– Client-side Bootstrap & JavaScript
3. Application Layer
– Django Web Server (Gunicorn / uWSGI behind Nginx)
– URL Routing (health_desease/urls.py, urls1.py, routing.py for ASGI)
– Views & API Views (health/views.py, health/api_views.py)
– DRF Serializers (health/serializers.py)
4. Business-Logic Layer
– ML Prediction Function (prdict_heart_disease)
– Data-mining Notebook (Machine_Learning/Heart prediction.ipynb)
5. Data Layer
– SQLite Database (db.sqlite3) with tables: Users, Patients, Doctors, Feedback, Admin_Health_CSV, Prediction Logs, etc.
– Media Storage (media/heart.csv, uploaded files)
6. External Services
– None in current scope (optionally email/SMS or third-party ML API if extended)
b. Relationships & Data Flows
1. Client sends HTTP(S) requests to the Web Server.
2. Nginx (or built-in server) routes to Gunicorn → Django.
3. Django URL dispatcher invokes corresponding View or APIView.
4. If prediction request: View calls prdict_heart_disease → loads CSV from DB media location → uses scikit-learn model → returns prediction.
5. View queries/updates SQLite via Django ORM (Models).
6. Response rendered via a Template or as JSON (API).
7. Static assets served either by Django or a static server.
8. Admin interface uses Django’s built-in admin or custom templates.
c. Architectural Patterns & Principles
– Layered (Presentation, Application, Business, Data)
– MVC / MVT (Model-View-Template)
– Single-page flows for ML prediction and CRUD operations for users, doctors, feedback
– Reusable ML module invoked from web layer
d. Key Technologies & Libraries
– Python / Django Framework (health_desease, health app)
– Django REST Framework (serializers & API views)
– Bootstrap, CSS, JavaScript for front-end
– scikit-learn, pandas, numpy for ML
– SQLite for development DB
– GitHub Actions / CodeQL for CI

##### Essential Elements to Capture
- User roles and entry points (Patient, Doctor, Admin).
- Separation of concerns: UI, API, ML logic, Persistence.
- Interaction points between Django’s view layer and ML code.
- Data sources (heart.csv in media vs. historical logs in SQLite).

## Diagram (Mermaid)

```mermaid
graph TB
    %% Front-end Layer
    subgraph "Client Layer" 
        direction TB
        Browser["Web Browser (Patient/Doctor/Admin)"]:::frontend
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Templates["Django Templates"]:::frontend
        Static["Static Assets (CSS/JS/Images)"]:::frontend
    end

    %% Web Server
    subgraph "Web Server"
        direction TB
        Nginx["Nginx"]:::infra
        Gunicorn["Gunicorn/uWSGI"]:::infra
    end

    %% Django Configuration
    subgraph "Django Project Config" 
        direction TB
        Settings["settings.py"]:::backend
        URLs["urls.py & urls1.py"]:::backend
        ASGI["asgi.py"]:::backend
        WSGI["wsgi.py"]:::backend
        Routing["routing.py"]:::backend
        APIConfig["api.py & apirep.py"]:::backend
    end

    %% Application Layer
    subgraph "Core Django App" 
        direction TB
        Models["models.py"]:::backend
        Views["views.py"]:::backend
        APIViews["api_views.py"]:::backend
        Serializers["serializers.py"]:::backend
        Admin["admin.py"]:::backend
        Forms["forms.py"]:::backend
        Choices["choices.py"]:::backend
        AppsFile["apps.py"]:::backend
        Tests["tests.py"]:::backend
        Migrations["migrations/"]:::backend
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        MLFunc["prdict_heart_disease Function"]:::ml
        Notebook["Heart prediction.ipynb"]:::ml
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        SQLite["db.sqlite3"]:::data
        MediaCSV["media/heart.csv"]:::data
    end

    %% CI
    CI["GitHub Actions (codeql-analysis.yml)"]:::infra

    %% Connections
    Browser -->|"HTTP Request"| Nginx
    Nginx --> Gunicorn
    Gunicorn -->|"WSGI/ASGI"| ASGI
    Gunicorn -->|"WSGI"| WSGI
    Gunicorn -->|"Routes to"| URLs
    URLs --> Views
    URLs --> APIViews
    Views --> Templates
    Views --> Static
    APIViews --> Serializers
    Views -->|"calls"| MLFunc
    MLFunc --> MediaCSV
    MLFunc --> Notebook
    Views -->|"ORM Query"| Models
    APIViews -->|"ORM Query"| Models
    Models --> SQLite
    SQLite -->|"Query Result"| Models
    CI -.-> Settings

    %% Click Events
    click Settings "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health_desease/settings.py"
    click URLs "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health_desease/urls.py"
    click ASGI "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health_desease/asgi.py"
    click WSGI "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health_desease/wsgi.py"
    click Routing "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health_desease/routing.py"
    click APIConfig "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health_desease/api.py"
    click APIConfig "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health_desease/apirep.py"
    click Models "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health/models.py"
    click Views "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health/views.py"
    click APIViews "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health/api_views.py"
    click Serializers "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health/serializers.py"
    click Admin "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health/admin.py"
    click Forms "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health/forms.py"
    click Choices "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health/choices.py"
    click AppsFile "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health/apps.py"
    click Tests "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/health/tests.py"
    click Migrations "https://github.com/kumar-laxmi/heart-disease-prediction-system/tree/main/health/migrations/"
    click Templates "https://github.com/kumar-laxmi/heart-disease-prediction-system/tree/main/health/templates/"
    click Static "https://github.com/kumar-laxmi/heart-disease-prediction-system/tree/main/health/static/"
    click Notebook "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/Machine_Learning/Heart prediction.ipynb"
    click MediaCSV "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/Machine_Learning/heart.csv"
    click SQLite "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/db.sqlite3"
    click CI "https://github.com/kumar-laxmi/heart-disease-prediction-system/blob/main/.github/workflows/codeql-analysis.yml"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085;
    classDef backend fill:#d4edda,stroke:#155724,color:#155724;
    classDef data fill:#fff3cd,stroke:#856404,color:#856404;
    classDef ml fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef infra fill:#f8d7da,stroke:#721c24,color:#721c24;
```
