# ishaan-jain2207/metascale-health architecture

> Architecture diagram of the GitHub repository ishaan-jain2207/metascale-health, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ishaan-jain2207/metascale-health
- Repository: https://github.com/ishaan-jain2207/metascale-health

## Overview

1. **Repository shape**
   - This is a two-tier application in a single monorepo: a **React frontend** in `healthapp/frontend` and a **Node.js/Express backend** in `healthapp/backend`.
   - The backend is the system-of-record API for users, screenings, appointments, and role-based access. The frontend is the presentation layer for patients, doctors, and admins.

2. **Primary runtime boundaries**
   - **Frontend runtime:** React 19 with Vite and Tailwind CSS.
   - **Backend runtime:** Node.js + Express.
   - **Data store:** MySQL, with schema definitions in `healthapp/backend/schema.sql`.
   - **ML inference layer:** Python-based model execution under `healthapp/backend/scripts`, backed by serialized models (`diabetes_model.pkl`, `liver_model.pkl`).

3. **Frontend architecture**
   - The UI is organized by user journey: `pages/patient`, `pages/doctor`, `pages/admin`, and shared/auth pages.
   - `AuthProvider`/`AuthContext` and hooks like `useAuth` centralize session state and user identity.
   - `ProtectedRoute` and role-oriented pages indicate that routing is gated by authentication and role.
   - `services/api.js` and `services/HealthService.js` are the main network boundary from UI to backend.

4. **Backend request pipeline**
   - Express entrypoints are in `src/server.js` and `src/app.js`.
   - API endpoints are split by domain in `src/routes`: `auth`, `admin`, `doctor`, `appointment`, and `prediction`.
   - Requests flow through middleware layers for **authentication**, **role authorization**, and **error handling** before reaching controllers.

5. **Core domain subsystems**
   - **Auth subsystem:** registration/login/token issuance in `authController`, token helpers in `utils/generateToken.js`, and auth checks in `middleware/authMiddleware.js`.
   - **Patient/doctor/admin management:** separate controllers and routes for each role, keeping the authorization boundary explicit.
   - **Appointments:** handled as a distinct domain with its own controller and routes.
   - **Screening/predictions:** dedicated prediction controllers and services for diabetes and liver risk workflows.

6. **Prediction data flow**
   - Screening requests enter through `predictionRoutes` → `predictionController`.
   - Domain services such as `diabetesPredictionService.js` and `liverPredictionService.js` encapsulate disease-specific logic.
   - `utils/mlEngine.js` is the abstraction layer that ties backend request handling to the Python inference code and stored model artifacts.
   - Results likely feed back into persistence/history views and clinical summaries.

7. **ML/model boundary**
   - The repository contains two persisted model artifacts for diabetes and liver risk prediction, suggesting offline training and online inference are separated.
   - `scripts/inference.py` is the runtime execution point for the predictive models.
   - The `notebooks/` directory holds model research, feature logic, and cleaning work; it is offline/analytical, not part of request serving.

8. **Persistence and migration**
   - `src/config/db.js` is the DB connection boundary.
   - `utils/migrate.js` and `schema.sql` indicate a schema-first setup with explicit migration/bootstrap support.
   - The backend stores operational data such as users, medical profiles, screenings, appointment records, and role-specific metadata.

9. **Role-based product surfaces**
   - **Patients:** screening portal, history, appointments, profile, and results pages.
   - **Doctors:** patient list/detail, appointments, and review workflows.
   - **Admins:** doctor management and system oversight.
   - These surfaces map closely to backend route groups, which is useful for diagramming clear role-to-service paths.

10. **Cross-cutting utilities**
   - `apiResponse.js` standardizes backend responses.
   - `errorMiddleware.js` provides centralized failure handling.
   - `clinicalInsightService.js` suggests post-prediction interpretation or recommendation generation layered on top of raw model output.

11. **Operational artifacts**
   - Root-level debug scripts (`debug_ml.js`, `debug_ml_services.js`) and `test_register.js` imply lightweight local validation for auth and ML integration.
   - Frontend deployment hints exist via `vercel.json`, indicating the UI may be independently deployed from the backend.

12. **Important diagram boundaries**
   - Draw a hard line between **UI/auth state** in React, **business/API logic** in Express, **persistence** in MySQL, and **prediction execution** in Python/model artifacts.
   - The most important end-to-end flows are:
     - user authentication,
     - screening submission and risk scoring,
     - appointment management,
     - role-based doctor/admin management,
     - history/profile retrieval from the database.

Main entry points: [`healthapp/backend/src/app.js`](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/app.js) (Express App), [`healthapp/backend/src/config/db.js`](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/config/db.js) (DB Config), [`healthapp/backend/src/controllers/predictionController.js`](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/controllers/predictionController.js) (Screening API), [`healthapp/backend/src/controllers/adminController.js`](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/controllers/adminController.js) (Role Domains)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["React App<br/>react-vite shell<br/>[main.jsx]"]
  node_frontend_auth["Auth State<br/>context/hooks<br/>[AuthProvider.jsx]"]
  node_frontend_route_guard["Route Guard<br/>protected routing<br/>[ProtectedRoute.jsx]"]
  node_frontend_api["API Client<br/>service layer<br/>[api.js]"]
  node_frontend_healthservice["Health Service<br/>domain client<br/>[HealthService.js]"]
  node_frontend_patient["Patient UI<br/>patient pages"]
  node_frontend_doctor["Doctor UI<br/>doctor pages"]
  node_frontend_admin["Admin UI<br/>admin pages<br/>[AdminDashboard.jsx]"]
end

subgraph group_backend["Backend"]
  node_backend_app["Express App<br/>[app.js]"]
  node_backend_server["API Server<br/>node entrypoint<br/>[server.js]"]
  node_backend_auth["Auth Domain<br/>controllers/routes<br/>[authController.js]"]
  node_backend_roles["Role Domains<br/>role controllers<br/>[adminController.js]"]
  node_backend_appointments["Appointments<br/>appointment domain"]
  node_backend_predictions["Screening API<br/>prediction domain"]
  node_backend_middleware["Middleware<br/>auth/role/error<br/>[authMiddleware.js]"]
  node_backend_db["DB Config<br/>mysql connection<br/>[db.js]"]
  node_backend_migration["Schema Setup<br/>schema/migration<br/>[migrate.js]"]
end

subgraph group_ml["Prediction"]
  node_ml_engine["ML Engine<br/>python inference<br/>[mlEngine.js]"]
  node_ml_runtime["Inference Script<br/>python runtime<br/>[inference.py]"]
  node_ml_models[("Model Artifacts<br/>serialized models<br/>[diabetes_model.pkl]")]
end

subgraph group_data["Data"]
  node_data_schema["MySQL Schema<br/>[schema.sql]"]
end

node_frontend_app -->|"provides session"| node_frontend_auth
node_frontend_app -->|"gates routes"| node_frontend_route_guard
node_frontend_patient -->|"fetches data"| node_frontend_api
node_frontend_doctor -->|"fetches data"| node_frontend_api
node_frontend_admin -->|"fetches data"| node_frontend_api
node_frontend_healthservice -->|"uses client"| node_frontend_api
node_frontend_route_guard -->|"reads identity"| node_frontend_auth
node_backend_server -->|"starts app"| node_backend_app
node_backend_app -->|"applies pipeline"| node_backend_middleware
node_backend_app -->|"mounts auth"| node_backend_auth
node_backend_app -->|"mounts roles"| node_backend_roles
node_backend_app -->|"mounts appointments"| node_backend_appointments
node_backend_app -->|"mounts screening"| node_backend_predictions
node_backend_auth -->|"reads/writes"| node_backend_db
node_backend_roles -->|"reads/writes"| node_backend_db
node_backend_appointments -->|"reads/writes"| node_backend_db
node_backend_predictions -->|"invokes inference"| node_ml_engine
node_ml_engine -->|"executes"| node_ml_runtime
node_ml_runtime -->|"loads models"| node_ml_models
node_backend_db -->|"initialized by"| node_data_schema
node_backend_migration -->|"applies schema"| node_data_schema
node_backend_predictions -->|"stores results"| node_backend_db
node_frontend_patient -->|"submits screening"| node_backend_predictions
node_frontend_patient -->|"manages visits"| node_backend_appointments
node_frontend_doctor -->|"reviews patients"| node_backend_roles
node_frontend_admin -->|"administers users"| node_backend_roles

click node_frontend_app "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/main.jsx"
click node_frontend_auth "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/context/AuthProvider.jsx"
click node_frontend_route_guard "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/components/ProtectedRoute.jsx"
click node_frontend_api "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/services/api.js"
click node_frontend_healthservice "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/services/HealthService.js"
click node_frontend_patient "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/pages/patient/PatientDashboard.jsx"
click node_frontend_doctor "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/pages/doctor/DoctorDashboard.jsx"
click node_frontend_admin "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/pages/admin/AdminDashboard.jsx"
click node_backend_app "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/app.js"
click node_backend_server "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/server.js"
click node_backend_auth "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/controllers/authController.js"
click node_backend_roles "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/controllers/adminController.js"
click node_backend_appointments "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/controllers/appointmentController.js"
click node_backend_predictions "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/controllers/predictionController.js"
click node_backend_middleware "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/middleware/authMiddleware.js"
click node_backend_db "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/config/db.js"
click node_backend_migration "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/utils/migrate.js"
click node_data_schema "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/schema.sql"
click node_ml_engine "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/utils/mlEngine.js"
click node_ml_runtime "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/scripts/inference.py"
click node_ml_models "https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/scripts/models/diabetes_model.pkl"

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_frontend_app,node_frontend_auth,node_frontend_route_guard,node_frontend_api,node_frontend_healthservice,node_frontend_patient,node_frontend_doctor,node_frontend_admin toneBlue
class node_backend_app,node_backend_server,node_backend_auth,node_backend_roles,node_backend_appointments,node_backend_predictions,node_backend_middleware,node_backend_db,node_backend_migration toneAmber
class node_ml_engine,node_ml_runtime,node_ml_models toneMint
class node_data_schema toneRose
```

## Components

### Frontend

React/Vite presentation layer and role-based UI flows

- [React App](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/main.jsx): react-vite shell · Main frontend entry and app composition · `healthapp/frontend/src/main.jsx`
- [Auth State](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/context/AuthProvider.jsx): context/hooks · Central session and identity state · `healthapp/frontend/src/context/AuthProvider.jsx`
- [Route Guard](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/components/ProtectedRoute.jsx): protected routing · Blocks pages unless authenticated and authorized · `healthapp/frontend/src/components/ProtectedRoute.jsx`
- [API Client](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/services/api.js): service layer · Network boundary for backend calls · `healthapp/frontend/src/services/api.js`
- [Health Service](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/services/HealthService.js): domain client · Higher-level client for clinical and app workflows · `healthapp/frontend/src/services/HealthService.js`
- [Patient UI](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/pages/patient/PatientDashboard.jsx): patient pages · Screening, history, appointments, profile, and results · `healthapp/frontend/src/pages/patient/PatientDashboard.jsx`
- [Doctor UI](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/pages/doctor/DoctorDashboard.jsx): doctor pages · Patient review and appointment workflows · `healthapp/frontend/src/pages/doctor/DoctorDashboard.jsx`
- [Admin UI](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/frontend/src/pages/admin/AdminDashboard.jsx): admin pages · Doctor management and system oversight · `healthapp/frontend/src/pages/admin/AdminDashboard.jsx`

### Backend

Express API, domain logic, and request pipeline

- [Express App](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/app.js): node-express app · Server composition and middleware wiring · `healthapp/backend/src/app.js`
- [API Server](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/server.js): node entrypoint · Runtime entrypoint for the backend · `healthapp/backend/src/server.js`
- [Auth Domain](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/controllers/authController.js): controllers/routes · Registration, login, token issuance, and auth checks · `healthapp/backend/src/controllers/authController.js`
- [Role Domains](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/controllers/adminController.js): role controllers · Admin and doctor management surfaces · `healthapp/backend/src/controllers/adminController.js`
- [Appointments](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/controllers/appointmentController.js): appointment domain · Appointment creation and management · `healthapp/backend/src/controllers/appointmentController.js`
- [Screening API](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/controllers/predictionController.js): prediction domain · Disease screening endpoints and result orchestration · `healthapp/backend/src/controllers/predictionController.js`
- [Middleware](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/middleware/authMiddleware.js): auth/role/error · Authentication, authorization, and error handling · `healthapp/backend/src/middleware/authMiddleware.js`
- [DB Config](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/config/db.js): mysql connection · Database connection boundary · `healthapp/backend/src/config/db.js`
- [Schema Setup](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/utils/migrate.js): schema/migration · Bootstrap and schema management · `healthapp/backend/src/utils/migrate.js`

### Prediction

Python inference and stored model artifacts

- [ML Engine](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/src/utils/mlEngine.js): python inference · Executes model inference for backend requests · `healthapp/backend/src/utils/mlEngine.js`
- [Inference Script](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/scripts/inference.py): python runtime · Python execution entrypoint for prediction workflows · `healthapp/backend/scripts/inference.py`
- [Model Artifacts](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/scripts/models/diabetes_model.pkl): serialized models · Persisted diabetes and liver risk models · `healthapp/backend/scripts/models/diabetes_model.pkl`

### Data

Schema and persistence boundary

- [MySQL Schema](https://github.com/ishaan-jain2207/metascale-health/blob/main/healthapp/backend/schema.sql): sql schema · Operational schema for users, profiles, screenings, and appointments · `healthapp/backend/schema.sql`

## Connections

- React App → Auth State: provides session · App wraps the UI in auth context
- React App → Route Guard: gates routes · Protected routes enforce auth and role checks
- Patient UI → API Client: fetches data · Patient screens call backend APIs
- Doctor UI → API Client: fetches data · Doctor screens call backend APIs
- Admin UI → API Client: fetches data · Admin screens call backend APIs
- Health Service → API Client: uses client · Domain service builds on the base API client
- Route Guard → Auth State: reads identity · Route gating depends on auth state
- API Server → Express App: starts app · Server boots the Express application
- Express App → Middleware: applies pipeline · Requests pass through auth, role, and error middleware
- Express App → Auth Domain: mounts auth · Auth routes and controllers are attached to the app
- Express App → Role Domains: mounts roles · Admin and doctor domains are exposed as routes
- Express App → Appointments: mounts appointments · Appointment domain is exposed as routes
- Express App → Screening API: mounts screening · Prediction routes are exposed through the app
- Auth Domain → DB Config: reads/writes · Auth flows persist and query users
- Role Domains → DB Config: reads/writes · Role management uses the database
- Appointments → DB Config: reads/writes · Appointments are persisted in MySQL
- Screening API → ML Engine: invokes inference · Prediction requests delegate to the ML engine
- ML Engine → Inference Script: executes · Engine bridges API logic to Python inference
- Inference Script → Model Artifacts: loads models · Inference uses serialized disease models
- DB Config → MySQL Schema: initialized by · Connection targets the schema-defined database
- Schema Setup → MySQL Schema: applies schema · Migration/bootstrap aligns the database schema
- Screening API → DB Config: stores results · Screening outputs can be recorded for history and review
- Patient UI → Screening API: submits screening · Patient screening flows send data to prediction endpoints
- Patient UI → Appointments: manages visits · Patients manage appointments through backend APIs
- Doctor UI → Role Domains: reviews patients · Doctor workflows depend on role-scoped backend data
- Admin UI → Role Domains: administers users · Admin workflows depend on role-scoped backend data
