# huzaifa-bubere/medisense-ai architecture

> Architecture diagram of the GitHub repository huzaifa-bubere/medisense-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/huzaifa-bubere/medisense-ai
- Repository: https://github.com/huzaifa-bubere/medisense-ai

## Overview

MediSense AI combines a role-based hospital portal, a Node/Express clinical workflow API, and a FastAPI inference service. Patients can request appointments, monitor care, and conduct a Hindi/English/Hinglish voice consultation; the assistant produces a structured assessment that clinicians can review as a report. The README also documents deterministic safety checks, urgent alerts, and clinical ML tools. Edges are limited to README-described workflows and relationships visible in the supplied excerpts or SOURCE INDEX; unsampled implementation details are not inferred.

Main entry points: [`frontend/src/App.tsx`](https://github.com/huzaifa-bubere/medisense-ai/blob/main/frontend/src/App.tsx) (Portal routing), [`backend/src/modules/ai-doctor/ai-doctor.service.ts`](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/ai-doctor/ai-doctor.service.ts) (Consultation safety), [`backend/src/config/database.ts`](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/config/database.ts) (Database client), [`ml-service/app/main.py`](https://github.com/huzaifa-bubere/medisense-ai/blob/main/ml-service/app/main.py) (Inference API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_portal["Hospital portal"]
  node_portal_app["Portal routing<br/>[App.tsx]"]
  node_patient_portal["Patient portal"]
  node_appointments_ui["Appointments UI"]
  node_patient_detail["Patient detail"]
  node_ml_ui["ML predictions UI"]
end

subgraph group_clinical["Clinical workflows"]
  node_appointments_api["Appointment requests"]
  node_patient_records["Patient records<br/>[patient.service.ts]"]
  node_consultations["Consultations"]
  node_reports["Clinical reports<br/>[report.service.ts]"]
  node_alerts["Clinical alerts<br/>[alert.service.ts]"]
end

subgraph group_assistant["AI consultation"]
  node_ai_page["AI Doctor page<br/>[AiDoctorPage.tsx]"]
  node_ai_controller["AI Doctor endpoints"]
  node_ai_service["Consultation safety"]
  node_voice_provider["Voice agent"]
end

subgraph group_inference["Clinical intelligence"]
  node_ml_api["Inference API<br/>[main.py]"]
  node_bayesian["Bayesian risk<br/>[bayesian_engine.py]"]
  node_rag["Knowledge retrieval<br/>[retriever.py]"]
  node_clinical_models["Clinical models"]
end

subgraph group_platform["Platform services"]
  node_backend_app["API application<br/>[app.ts]"]
  node_auth["Authentication<br/>[auth.service.ts]"]
  node_auth_guard["Request authorization<br/>[auth.middleware.ts]"]
  node_database_client["Database client<br/>[database.ts]"]
  node_postgres[("PostgreSQL")]
  node_socket["Live events<br/>[socket.ts]"]
end

node_patient(("Patient"))
node_clinician(("Clinician"))

node_patient -->|"uses portal"| node_portal_app
node_portal_app -->|"routes to"| node_patient_portal
node_portal_app -->|"routes to"| node_appointments_ui
node_portal_app -->|"routes to"| node_patient_detail
node_portal_app -->|"routes to"| node_ml_ui
node_patient -->|"requests visit"| node_appointments_ui
node_appointments_ui -.->|"submits request"| node_appointments_api
node_appointments_api -->|"emits request"| node_socket
node_patient -->|"starts consultation"| node_ai_page
node_portal_app -->|"routes to"| node_ai_page
node_ai_page -->|"calls endpoints"| node_ai_controller
node_ai_controller -->|"delegates to"| node_ai_service
node_ai_service -->|"starts voice call"| node_voice_provider
node_voice_provider -->|"sends transcript"| node_ai_service
node_ai_service -->|"retrieves context"| node_rag
node_ai_service -.->|"uses clinical AI"| node_clinical_models
node_ai_service -->|"raises urgent alert"| node_alerts
node_ai_service -->|"produces assessment"| node_reports
node_reports -->|"delivers report"| node_clinician
node_clinician -->|"reviews care"| node_patient_detail
node_portal_app -.->|"uses API"| node_backend_app
node_backend_app -->|"mounts auth routes"| node_auth
node_auth -->|"reads and writes"| node_database_client
node_auth_guard -->|"checks user"| node_database_client
node_backend_app -->|"connects database"| node_database_client
node_database_client -->|"connects"| node_postgres
node_ml_ui -.->|"requests predictions"| node_ml_api
node_ml_api -->|"registers route"| node_bayesian
node_ml_api -->|"registers routes"| node_clinical_models
node_ml_api -->|"warms retrieval"| node_rag
node_patient_records -.->|"persists records"| node_database_client
node_consultations -.->|"persists encounters"| node_database_client
node_alerts -.->|"pushes alerts"| node_socket

click node_portal_app "https://github.com/huzaifa-bubere/medisense-ai/blob/main/frontend/src/App.tsx"
click node_patient_portal "https://github.com/huzaifa-bubere/medisense-ai/blob/main/frontend/src/pages/PatientPortalPage.tsx"
click node_appointments_ui "https://github.com/huzaifa-bubere/medisense-ai/blob/main/frontend/src/pages/AppointmentsPage.tsx"
click node_patient_detail "https://github.com/huzaifa-bubere/medisense-ai/blob/main/frontend/src/pages/PatientDetailPage.tsx"
click node_ml_ui "https://github.com/huzaifa-bubere/medisense-ai/blob/main/frontend/src/pages/MLPredictionsPage.tsx"
click node_appointments_api "https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/appointments/appointmentRequest.service.ts"
click node_patient_records "https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/patients/patient.service.ts"
click node_consultations "https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/consultations/consultation.service.ts"
click node_reports "https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/reports/report.service.ts"
click node_alerts "https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/alerts/alert.service.ts"
click node_ai_page "https://github.com/huzaifa-bubere/medisense-ai/blob/main/frontend/src/pages/AiDoctorPage.tsx"
click node_ai_controller "https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/ai-doctor/ai-doctor.controller.ts"
click node_ai_service "https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/ai-doctor/ai-doctor.service.ts"
click node_ml_api "https://github.com/huzaifa-bubere/medisense-ai/blob/main/ml-service/app/main.py"
click node_bayesian "https://github.com/huzaifa-bubere/medisense-ai/blob/main/ml-service/app/api/routes/bayesian_engine.py"
click node_rag "https://github.com/huzaifa-bubere/medisense-ai/blob/main/ml-service/app/rag/retriever.py"
click node_clinical_models "https://github.com/huzaifa-bubere/medisense-ai/blob/main/ml-service/app/api/routes/medisense_predict.py"
click node_backend_app "https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/app.ts"
click node_auth "https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/auth/auth.service.ts"
click node_auth_guard "https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/middleware/auth.middleware.ts"
click node_database_client "https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/config/database.ts"
click node_socket "https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/config/socket.ts"

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_portal_app,node_patient_portal,node_appointments_ui,node_patient_detail,node_ml_ui toneBlue
class node_appointments_api,node_patient_records,node_consultations,node_reports,node_alerts toneAmber
class node_ai_page,node_ai_controller,node_ai_service,node_voice_provider toneMint
class node_ml_api,node_bayesian,node_rag,node_clinical_models toneRose
class node_backend_app,node_auth,node_auth_guard,node_database_client,node_postgres,node_socket,node_patient,node_clinician toneIndigo
```

## Components

### Hospital portal

- [Portal routing](https://github.com/huzaifa-bubere/medisense-ai/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Patient portal](https://github.com/huzaifa-bubere/medisense-ai/blob/main/frontend/src/pages/PatientPortalPage.tsx): `frontend/src/pages/PatientPortalPage.tsx`
- [Appointments UI](https://github.com/huzaifa-bubere/medisense-ai/blob/main/frontend/src/pages/AppointmentsPage.tsx): `frontend/src/pages/AppointmentsPage.tsx`
- [Patient detail](https://github.com/huzaifa-bubere/medisense-ai/blob/main/frontend/src/pages/PatientDetailPage.tsx): `frontend/src/pages/PatientDetailPage.tsx`
- [ML predictions UI](https://github.com/huzaifa-bubere/medisense-ai/blob/main/frontend/src/pages/MLPredictionsPage.tsx): `frontend/src/pages/MLPredictionsPage.tsx`

### Clinical workflows

- [Appointment requests](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/appointments/appointmentRequest.service.ts): `backend/src/modules/appointments/appointmentRequest.service.ts`
- [Patient records](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/patients/patient.service.ts): `backend/src/modules/patients/patient.service.ts`
- [Consultations](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/consultations/consultation.service.ts): `backend/src/modules/consultations/consultation.service.ts`
- [Clinical reports](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/reports/report.service.ts): `backend/src/modules/reports/report.service.ts`
- [Clinical alerts](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/alerts/alert.service.ts): `backend/src/modules/alerts/alert.service.ts`

### AI consultation

- [AI Doctor page](https://github.com/huzaifa-bubere/medisense-ai/blob/main/frontend/src/pages/AiDoctorPage.tsx): `frontend/src/pages/AiDoctorPage.tsx`
- [AI Doctor endpoints](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/ai-doctor/ai-doctor.controller.ts): `backend/src/modules/ai-doctor/ai-doctor.controller.ts`
- [Consultation safety](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/ai-doctor/ai-doctor.service.ts): `backend/src/modules/ai-doctor/ai-doctor.service.ts`
- **Voice agent**

### Clinical intelligence

- [Inference API](https://github.com/huzaifa-bubere/medisense-ai/blob/main/ml-service/app/main.py): `ml-service/app/main.py`
- [Bayesian risk](https://github.com/huzaifa-bubere/medisense-ai/blob/main/ml-service/app/api/routes/bayesian_engine.py): `ml-service/app/api/routes/bayesian_engine.py`
- [Knowledge retrieval](https://github.com/huzaifa-bubere/medisense-ai/blob/main/ml-service/app/rag/retriever.py): `ml-service/app/rag/retriever.py`
- [Clinical models](https://github.com/huzaifa-bubere/medisense-ai/blob/main/ml-service/app/api/routes/medisense_predict.py): `ml-service/app/api/routes/medisense_predict.py`

### Platform services

- [API application](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/app.ts): `backend/src/app.ts`
- [Authentication](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/modules/auth/auth.service.ts): `backend/src/modules/auth/auth.service.ts`
- [Request authorization](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/middleware/auth.middleware.ts): `backend/src/middleware/auth.middleware.ts`
- [Database client](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/config/database.ts): `backend/src/config/database.ts`
- **PostgreSQL**
- [Live events](https://github.com/huzaifa-bubere/medisense-ai/blob/main/backend/src/config/socket.ts): `backend/src/config/socket.ts`

### Other components

- **Patient**
- **Clinician**

## Connections

- Patient → Portal routing: uses portal (evidence: `README.md`)
- Portal routing → Patient portal: routes to (evidence: `frontend/src/App.tsx`)
- Portal routing → Appointments UI: routes to (evidence: `frontend/src/App.tsx`)
- Portal routing → Patient detail: routes to (evidence: `frontend/src/App.tsx`)
- Portal routing → ML predictions UI: routes to (evidence: `frontend/src/App.tsx`)
- Patient → Appointments UI: requests visit (evidence: `README.md`)
- Appointments UI → Appointment requests: submits request
- Appointment requests → Live events: emits request (evidence: `backend/src/modules/appointments/appointmentRequest.service.ts`)
- Patient → AI Doctor page: starts consultation (evidence: `README.md`)
- Portal routing → AI Doctor page: routes to (evidence: `frontend/src/App.tsx`)
- AI Doctor page → AI Doctor endpoints: calls endpoints (evidence: `backend/src/modules/ai-doctor/ai-doctor.controller.ts`)
- AI Doctor endpoints → Consultation safety: delegates to (evidence: `backend/src/modules/ai-doctor/ai-doctor.controller.ts`)
- Consultation safety → Voice agent: starts voice call (evidence: `README.md`)
- Voice agent → Consultation safety: sends transcript
- Consultation safety → Knowledge retrieval: retrieves context (evidence: `README.md`)
- Consultation safety → Clinical models: uses clinical AI
- Consultation safety → Clinical alerts: raises urgent alert (evidence: `README.md`)
- Consultation safety → Clinical reports: produces assessment (evidence: `README.md`)
- Clinical reports → Clinician: delivers report (evidence: `README.md`)
- Clinician → Patient detail: reviews care (evidence: `README.md`)
- Portal routing → API application: uses API
- API application → Authentication: mounts auth routes (evidence: `backend/src/app.ts`)
- Authentication → Database client: reads and writes (evidence: `backend/src/modules/auth/auth.service.ts`)
- Request authorization → Database client: checks user (evidence: `backend/src/middleware/auth.middleware.ts`)
- API application → Database client: connects database (evidence: `backend/src/app.ts`)
- Database client → PostgreSQL: connects (evidence: `backend/src/config/database.ts`)
- ML predictions UI → Inference API: requests predictions
- Inference API → Bayesian risk: registers route (evidence: `ml-service/app/main.py`)
- Inference API → Clinical models: registers routes (evidence: `ml-service/app/main.py`)
- Inference API → Knowledge retrieval: warms retrieval (evidence: `ml-service/app/main.py`)
- Patient records → Database client: persists records
- Consultations → Database client: persists encounters
- Clinical alerts → Live events: pushes alerts
