How ishaan-jain2207/metascale-health works
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: app.js Express App · db.js DB Config · predictionController.js Screening API · adminController.js Role Domains
Components 21
Frontend
React/Vite presentation layer and role-based UI flows
- React App · Main frontend entry and app composition
healthapp/frontend/src/main.jsx - Auth State · Central session and identity state
healthapp/frontend/src/context/AuthProvider.jsx - Route Guard · Blocks pages unless authenticated and authorized
healthapp/frontend/src/components/ProtectedRoute.jsx - API Client · Network boundary for backend calls
healthapp/frontend/src/services/api.js - Health Service · Higher-level client for clinical and app workflows
healthapp/frontend/src/services/HealthService.js - Patient UI · Screening, history, appointments, profile, and results
healthapp/frontend/src/pages/patient/PatientDashboard.jsx - Doctor UI · Patient review and appointment workflows
healthapp/frontend/src/pages/doctor/DoctorDashboard.jsx - Admin UI · Doctor management and system oversight
healthapp/frontend/src/pages/admin/AdminDashboard.jsx
Backend
Express API, domain logic, and request pipeline
- Express App · Server composition and middleware wiring
healthapp/backend/src/app.js - API Server · Runtime entrypoint for the backend
healthapp/backend/src/server.js - Auth Domain · Registration, login, token issuance, and auth checks
healthapp/backend/src/controllers/authController.js - Role Domains · Admin and doctor management surfaces
healthapp/backend/src/controllers/adminController.js - Appointments · Appointment creation and management
healthapp/backend/src/controllers/appointmentController.js - Screening API · Disease screening endpoints and result orchestration
healthapp/backend/src/controllers/predictionController.js - Middleware · Authentication, authorization, and error handling
healthapp/backend/src/middleware/authMiddleware.js - DB Config · Database connection boundary
healthapp/backend/src/config/db.js - Schema Setup · Bootstrap and schema management
healthapp/backend/src/utils/migrate.js
Prediction
Python inference and stored model artifacts
- ML Engine · Executes model inference for backend requests
healthapp/backend/src/utils/mlEngine.js - Inference Script · Python execution entrypoint for prediction workflows
healthapp/backend/scripts/inference.py - Model Artifacts · Persisted diabetes and liver risk models
healthapp/backend/scripts/models/diabetes_model.pkl
Data
Schema and persistence boundary
- MySQL Schema · Operational schema for users, profiles, screenings, and appointments
healthapp/backend/schema.sql
Connections 26
- 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