# enrituraj/healthpulse architecture

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

- Interactive diagram: https://gitdiagram.com/enrituraj/healthpulse
- Repository: https://github.com/enrituraj/healthpulse

## Overview

##### Project Type & Purpose
- Type: Full-stack web application with predictive-analytics features.
- Purpose: Enable users to register/login, upload health data (activity, sleep, nutrition), store it in MongoDB, run ML models to predict diabetes/heart‐disease risk, and view personalized dashboards and reports. An admin panel allows user/route management.

##### Main Components
a. Frontend
- Browser UI: HTML/CSS/JS served by Flask templates (`api/templates/…`)
- Static assets: CSS, JS, images (`api/static/…`)
b. Backend (Flask API)
- Entry point: `api/index.py`
- Routes: Public (register/login/my_profile/health pages), Admin (dashboard, user/route CRUD)
- Controllers: Handle form submissions, file uploads, session management (SECRET_KEY), user auth
c. Data Storage
- MongoDB: stores users, health metrics, prediction results
- Connection via MONGO_URI (env var)
d. Machine Learning Module
- Pretrained models (diabetes, heart-disease) loaded in backend
- Data preprocessing & prediction logic invoked on health data submission
e. External/Deployment
- Hosting: Vercel config (`vercel.json`) or other cloud
- Environment variables (.env)

##### Relationships & Data Flow
- User Browser → HTTP(S) → Flask Routes
- Authenticated routes ↔ Session cookie
- Form uploads → Backend
- Prediction request → ML Module → Prediction results
- CRUD calls → MongoDB
- Admin Browser → Admin Blueprint/Routes → MongoDB
- Deployment platform pulls code → ENV setup → Flask app runs → connects to MongoDB Atlas

##### Architectural Patterns & Principles
- MVC (Flask “View”=templates, “Controller”=route handlers, “Model”=MongoDB schemas/collections)
- Single-process monolithic service (no microservices)
- Separation of concerns:
- Static vs template rendering
- Public vs admin routes
- Auth middleware
- Scalability: stateless Flask instances behind load balancer, MongoDB cluster

##### Key Technologies & Libraries
- Flask (web framework, routing, templating)
- Jinja2 (HTML templates)
- Flask-Login / session (authentication)
- PyMongo or Flask-Pymongo (MongoDB client)
- scikit-learn (or similar) for predictive models
- HTML/CSS/JavaScript (static UI)
- Vercel (deployment) or alternative PaaS

- Use meaningful labels: e.g., “User Service,” “Auth Middleware,” “Diabetes Model.”

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Web Browser"]:::frontend
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        subgraph "Templates" 
            direction TB
            Register["register.html"]:::frontend
            Login["login.html"]:::frontend
            Profile["my_profile.html"]:::frontend
            EditProfile["edit_profile.html"]:::frontend
            ViewProfile["view_profile.html"]:::frontend
            UploadFile["upload_file.html"]:::frontend
            DiabetesPage["diabetes.html"]:::frontend
            HeartPage["heart_diseases.html"]:::frontend
            MyReport["my_report.html"]:::frontend
            LandingPage["landing_page.html"]:::frontend
            HomePage["index.html"]:::frontend
            subgraph "Layouts"
                Base["base.html"]:::frontend
                BaseAdmin["base_admin.html"]:::frontend
                LandingBase["landing_page_base.html"]:::frontend
            end
        end
        subgraph "Admin Templates"
            direction TB
            AdminDir["api/templates/admin/"]:::frontend
        end
        subgraph "Static Assets"
            direction TB
            CSSDir["api/static/css/"]:::static
            JSFile["script.js"]:::static
            ImgDir["api/static/img/"]:::static
        end
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        FlaskApp["Flask App (api/index.py)"]:::backend
        AuthMiddleware["Auth Middleware"]:::backend
        Controllers["Route Handlers"]:::backend
        MLModule["ML Module"]:::ml
        EnvVars["Env Variables (.env, vercel.json)"]:::external
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MongoAtlas["MongoDB Atlas"]:::db
    end

    %% External Deployment
    subgraph "External"
        direction TB
        Vercel["Vercel"]:::external
    end

    %% Connections
    Browser -->|GET/POST| FlaskApp
    FlaskApp -->|uses Templates| Register
    FlaskApp -->|uses Templates| Login
    FlaskApp -->|uses Templates| Profile
    FlaskApp -->|uses Templates| EditProfile
    FlaskApp -->|uses Templates| ViewProfile
    FlaskApp -->|uses Templates| UploadFile
    FlaskApp -->|uses Templates| DiabetesPage
    FlaskApp -->|uses Templates| HeartPage
    FlaskApp -->|uses Templates| MyReport
    FlaskApp -->|uses Templates| LandingPage
    FlaskApp -->|uses Templates| HomePage
    FlaskApp -->|uses Layouts| Base
    FlaskApp -->|uses Layouts| BaseAdmin
    FlaskApp -->|uses Layouts| LandingBase
    FlaskApp -->|serves static| CSSDir
    FlaskApp -->|serves static| JSFile
    FlaskApp -->|serves static| ImgDir
    FlaskApp -->|handles auth| AuthMiddleware
    FlaskApp -->|invokes| Controllers
    Controllers -->|POST /predict| MLModule
    MLModule -->|returns result| Controllers
    Controllers -->|CRUD| MongoAtlas
    FlaskApp -->|loads config| EnvVars
    Vercel -->|deploys| FlaskApp
    MongoAtlas -.->|external DB| FlaskApp

    %% Click Events
    click Register "https://github.com/enrituraj/healthpulse/blob/main/api/templates/register.html"
    click Login "https://github.com/enrituraj/healthpulse/blob/main/api/templates/login.html"
    click Profile "https://github.com/enrituraj/healthpulse/blob/main/api/templates/my_profile.html"
    click EditProfile "https://github.com/enrituraj/healthpulse/blob/main/api/templates/edit_profile.html"
    click ViewProfile "https://github.com/enrituraj/healthpulse/blob/main/api/templates/view_profile.html"
    click UploadFile "https://github.com/enrituraj/healthpulse/blob/main/api/templates/upload_file.html"
    click DiabetesPage "https://github.com/enrituraj/healthpulse/blob/main/api/templates/diabetes.html"
    click HeartPage "https://github.com/enrituraj/healthpulse/blob/main/api/templates/heart_diseases.html"
    click MyReport "https://github.com/enrituraj/healthpulse/blob/main/api/templates/my_report.html"
    click LandingPage "https://github.com/enrituraj/healthpulse/blob/main/api/templates/landing_page.html"
    click HomePage "https://github.com/enrituraj/healthpulse/blob/main/api/templates/index.html"
    click Base "https://github.com/enrituraj/healthpulse/blob/main/api/templates/layouts/base.html"
    click BaseAdmin "https://github.com/enrituraj/healthpulse/blob/main/api/templates/layouts/base_admin.html"
    click LandingBase "https://github.com/enrituraj/healthpulse/blob/main/api/templates/layouts/landing_page_base.html"
    click AdminDir "https://github.com/enrituraj/healthpulse/tree/main/api/templates/admin/"
    click CSSDir "https://github.com/enrituraj/healthpulse/tree/main/api/static/css/"
    click JSFile "https://github.com/enrituraj/healthpulse/blob/main/api/static/js/script.js"
    click ImgDir "https://github.com/enrituraj/healthpulse/tree/main/api/static/img/"
    click FlaskApp "https://github.com/enrituraj/healthpulse/blob/main/api/index.py"
    click MLModule "https://github.com/enrituraj/healthpulse/blob/main/api/index.py"
    click EnvVars "https://github.com/enrituraj/healthpulse/blob/main/vercel.json"
    classDef frontend fill:#AED6F1,stroke:#21618C,color:#1B2631
    classDef static fill:#D6EAF8,stroke:#2874A6,color:#1B2631
    classDef backend fill:#A9DFBF,stroke:#196F3D,color:#1B2631
    classDef ml fill:#E8DAEF,stroke:#7D3C98,color:#1B2631
    classDef db fill:#F9E79F,stroke:#B7950B,color:#1B2631
    classDef external fill:#F5CBA7,stroke:#B9770E,color:#1B2631
```
