# advaith-3683/mediflow-ai architecture

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

- Interactive diagram: https://gitdiagram.com/advaith-3683/mediflow-ai
- Repository: https://github.com/advaith-3683/mediflow-ai

## Overview

This repository implements a hospital-automation application: role-based React dashboards use shared state to make authenticated API requests, while an Express backend handles staff authentication, patient records, appointments, prescription OCR, and reports. Appointment booking is the clearest end-to-end workflow shown: a user works through a dashboard, shared context calls the appointment API, the server dispatches to appointment routes and controller logic, and the controller reads or writes Supabase. The root README is a Vite template rather than product documentation; backend capabilities are also evidenced by the route registrations and source index. Some frontend features and backend controllers were not excerpted, so their internal links are omitted where unverified.

Main entry points: [`src/App.jsx`](https://github.com/advaith-3683/mediflow-ai/blob/main/src/App.jsx) (Role dispatcher), [`src/context/AppContext.jsx`](https://github.com/advaith-3683/mediflow-ai/blob/main/src/context/AppContext.jsx) (Application state), [`hospital-automation-backend/src/server.js`](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/server.js) (HTTP server), [`hospital-automation-backend/src/config/db.js`](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/config/db.js) (Supabase client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["Role dispatcher<br/>[App.jsx]"]
  node_login["Staff login<br/>[LoginView.jsx]"]
  node_patientview["Patient dashboard<br/>[PatientView.jsx]"]
  node_doctorview["Doctor dashboard<br/>[DoctorView.jsx]"]
  node_adminview["Admin dashboard<br/>[AdminView.jsx]"]
  node_receptionview["Reception dashboard"]
  node_layout["App layout<br/>[Layout.jsx]"]
  node_ui["Shared UI<br/>[UI.jsx]"]
  node_context["Application state<br/>[AppContext.jsx]"]
  node_aiutil["AI utilities<br/>[ai.js]"]
end

subgraph group_backend["API runtime"]
  node_server["HTTP server<br/>[server.js]"]
  node_authroutes["Auth routes<br/>[auth.routes.js]"]
  node_patientroutes["Patient routes<br/>[patients.routes.js]"]
  node_approutes["Appointment routes"]
  node_ocrroutes["OCR routes<br/>[ocr.routes.js]"]
  node_reproutes["Report routes<br/>[reports.routes.js]"]
  node_authmw["JWT authorization<br/>[auth.js]"]
  node_validation["Request validation<br/>[validate.js]"]
  node_errors["Error handling<br/>[errorHandler.js]"]
end

subgraph group_clinical["Clinical workflows"]
  node_authctrl["Authentication<br/>[auth.controller.js]"]
  node_patientctrl["Patient records"]
  node_appctrl["Appointment workflow"]
  node_ocrctrl["Prescription OCR<br/>[ocr.controller.js]"]
  node_repctrl["Hospital reports"]
end

subgraph group_platform["Data and integrations"]
  node_dbconfig["Supabase client<br/>[db.js]"]
  node_database[("Supabase data")]
  node_gemini["Gemini service<br/>[gemini.service.js]"]
end

node_user(("Hospital user"))
node_externalai(("Google Gemini"))

node_user -->|"uses"| node_app
node_app -->|"provides state"| node_context
node_app -->|"shows unauthenticated"| node_login
node_app -->|"selects role view"| node_patientview
node_app -->|"selects role view"| node_doctorview
node_app -->|"selects role view"| node_adminview
node_app -->|"selects role view"| node_receptionview
node_app -->|"wraps dashboard"| node_layout
node_app -->|"renders notifications"| node_ui
node_patientview -->|"uses state"| node_context
node_doctorview -->|"uses state"| node_context
node_adminview -->|"uses state"| node_context
node_receptionview -->|"uses state"| node_context
node_login -->|"uses state"| node_context
node_ui -->|"reads notifications"| node_context
node_patientview -->|"uses AI helpers"| node_aiutil
node_receptionview -->|"uses AI helpers"| node_aiutil
node_context -->|"requests authentication"| node_authroutes
node_context -->|"requests patient records"| node_patientroutes
node_context -->|"requests appointments"| node_approutes
node_server -->|"mounts routes"| node_authroutes
node_server -->|"mounts routes"| node_patientroutes
node_server -->|"mounts routes"| node_approutes
node_server -->|"mounts routes"| node_ocrroutes
node_server -->|"mounts routes"| node_reproutes
node_authroutes -->|"dispatches"| node_authctrl
node_patientroutes -->|"dispatches"| node_patientctrl
node_approutes -->|"dispatches"| node_appctrl
node_ocrroutes -->|"dispatches"| node_ocrctrl
node_reproutes -->|"dispatches"| node_repctrl
node_approutes -->|"authenticates requests"| node_authmw
node_approutes -->|"validates booking"| node_validation
node_ocrroutes -->|"authenticates requests"| node_authmw
node_reproutes -->|"authenticates requests"| node_authmw
node_authctrl -->|"reads and writes"| node_dbconfig
node_patientctrl -->|"reads and writes"| node_dbconfig
node_appctrl -->|"reads and writes"| node_dbconfig
node_ocrctrl -->|"uses data store"| node_dbconfig
node_repctrl -->|"reads data"| node_dbconfig
node_dbconfig -->|"connects"| node_database
node_ocrctrl -->|"extracts prescription"| node_gemini
node_repctrl -->|"generates summary"| node_gemini
node_gemini -->|"sends AI request"| node_externalai
node_server -->|"registers handlers"| node_errors

click node_app "https://github.com/advaith-3683/mediflow-ai/blob/main/src/App.jsx"
click node_login "https://github.com/advaith-3683/mediflow-ai/blob/main/src/views/LoginView.jsx"
click node_patientview "https://github.com/advaith-3683/mediflow-ai/blob/main/src/views/PatientView.jsx"
click node_doctorview "https://github.com/advaith-3683/mediflow-ai/blob/main/src/views/DoctorView.jsx"
click node_adminview "https://github.com/advaith-3683/mediflow-ai/blob/main/src/views/AdminView.jsx"
click node_receptionview "https://github.com/advaith-3683/mediflow-ai/blob/main/src/views/ReceptionistView.jsx"
click node_layout "https://github.com/advaith-3683/mediflow-ai/blob/main/src/components/Layout.jsx"
click node_ui "https://github.com/advaith-3683/mediflow-ai/blob/main/src/components/UI.jsx"
click node_context "https://github.com/advaith-3683/mediflow-ai/blob/main/src/context/AppContext.jsx"
click node_aiutil "https://github.com/advaith-3683/mediflow-ai/blob/main/src/utils/ai.js"
click node_server "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/server.js"
click node_authroutes "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/routes/auth.routes.js"
click node_authctrl "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/controllers/auth.controller.js"
click node_patientroutes "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/routes/patients.routes.js"
click node_patientctrl "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/controllers/patients.controller.js"
click node_approutes "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/routes/appointments.routes.js"
click node_appctrl "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/controllers/appointments.controller.js"
click node_ocrroutes "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/routes/ocr.routes.js"
click node_ocrctrl "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/controllers/ocr.controller.js"
click node_reproutes "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/routes/reports.routes.js"
click node_repctrl "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/controllers/reports.controller.js"
click node_authmw "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/middleware/auth.js"
click node_validation "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/middleware/validate.js"
click node_errors "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/middleware/errorHandler.js"
click node_dbconfig "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/config/db.js"
click node_gemini "https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/services/gemini.service.js"

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_app,node_login,node_patientview,node_doctorview,node_adminview,node_receptionview,node_layout,node_ui,node_context,node_aiutil,node_user toneBlue
class node_server,node_authroutes,node_patientroutes,node_approutes,node_ocrroutes,node_reproutes,node_authmw,node_validation,node_errors toneAmber
class node_authctrl,node_patientctrl,node_appctrl,node_ocrctrl,node_repctrl toneMint
class node_dbconfig,node_database,node_gemini toneRose
class node_externalai toneIndigo
```

## Components

### Web application

- [Role dispatcher](https://github.com/advaith-3683/mediflow-ai/blob/main/src/App.jsx): `src/App.jsx`
- [Staff login](https://github.com/advaith-3683/mediflow-ai/blob/main/src/views/LoginView.jsx): `src/views/LoginView.jsx`
- [Patient dashboard](https://github.com/advaith-3683/mediflow-ai/blob/main/src/views/PatientView.jsx): `src/views/PatientView.jsx`
- [Doctor dashboard](https://github.com/advaith-3683/mediflow-ai/blob/main/src/views/DoctorView.jsx): `src/views/DoctorView.jsx`
- [Admin dashboard](https://github.com/advaith-3683/mediflow-ai/blob/main/src/views/AdminView.jsx): `src/views/AdminView.jsx`
- [Reception dashboard](https://github.com/advaith-3683/mediflow-ai/blob/main/src/views/ReceptionistView.jsx): `src/views/ReceptionistView.jsx`
- [App layout](https://github.com/advaith-3683/mediflow-ai/blob/main/src/components/Layout.jsx): `src/components/Layout.jsx`
- [Shared UI](https://github.com/advaith-3683/mediflow-ai/blob/main/src/components/UI.jsx): `src/components/UI.jsx`
- [Application state](https://github.com/advaith-3683/mediflow-ai/blob/main/src/context/AppContext.jsx): `src/context/AppContext.jsx`
- [AI utilities](https://github.com/advaith-3683/mediflow-ai/blob/main/src/utils/ai.js): `src/utils/ai.js`

### API runtime

- [HTTP server](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/server.js): `hospital-automation-backend/src/server.js`
- [Auth routes](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/routes/auth.routes.js): `hospital-automation-backend/src/routes/auth.routes.js`
- [Patient routes](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/routes/patients.routes.js): `hospital-automation-backend/src/routes/patients.routes.js`
- [Appointment routes](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/routes/appointments.routes.js): `hospital-automation-backend/src/routes/appointments.routes.js`
- [OCR routes](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/routes/ocr.routes.js): `hospital-automation-backend/src/routes/ocr.routes.js`
- [Report routes](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/routes/reports.routes.js): `hospital-automation-backend/src/routes/reports.routes.js`
- [JWT authorization](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/middleware/auth.js): `hospital-automation-backend/src/middleware/auth.js`
- [Request validation](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/middleware/validate.js): `hospital-automation-backend/src/middleware/validate.js`
- [Error handling](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/middleware/errorHandler.js): `hospital-automation-backend/src/middleware/errorHandler.js`

### Clinical workflows

- [Authentication](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/controllers/auth.controller.js): `hospital-automation-backend/src/controllers/auth.controller.js`
- [Patient records](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/controllers/patients.controller.js): `hospital-automation-backend/src/controllers/patients.controller.js`
- [Appointment workflow](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/controllers/appointments.controller.js): `hospital-automation-backend/src/controllers/appointments.controller.js`
- [Prescription OCR](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/controllers/ocr.controller.js): `hospital-automation-backend/src/controllers/ocr.controller.js`
- [Hospital reports](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/controllers/reports.controller.js): `hospital-automation-backend/src/controllers/reports.controller.js`

### Data and integrations

- [Supabase client](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/config/db.js): `hospital-automation-backend/src/config/db.js`
- **Supabase data**
- [Gemini service](https://github.com/advaith-3683/mediflow-ai/blob/main/hospital-automation-backend/src/services/gemini.service.js): `hospital-automation-backend/src/services/gemini.service.js`

### Other components

- **Hospital user**
- **Google Gemini**

## Connections

- Hospital user → Role dispatcher: uses (evidence: `src/App.jsx`)
- Role dispatcher → Application state: provides state (evidence: `src/App.jsx`)
- Role dispatcher → Staff login: shows unauthenticated (evidence: `src/App.jsx`)
- Role dispatcher → Patient dashboard: selects role view (evidence: `src/App.jsx`)
- Role dispatcher → Doctor dashboard: selects role view (evidence: `src/App.jsx`)
- Role dispatcher → Admin dashboard: selects role view (evidence: `src/App.jsx`)
- Role dispatcher → Reception dashboard: selects role view (evidence: `src/App.jsx`)
- Role dispatcher → App layout: wraps dashboard (evidence: `src/App.jsx`)
- Role dispatcher → Shared UI: renders notifications (evidence: `src/App.jsx`)
- Patient dashboard → Application state: uses state (evidence: `src/context/AppContext.jsx`)
- Doctor dashboard → Application state: uses state (evidence: `src/context/AppContext.jsx`)
- Admin dashboard → Application state: uses state (evidence: `src/context/AppContext.jsx`)
- Reception dashboard → Application state: uses state (evidence: `src/context/AppContext.jsx`)
- Staff login → Application state: uses state (evidence: `src/context/AppContext.jsx`)
- Shared UI → Application state: reads notifications (evidence: `src/components/UI.jsx`)
- Patient dashboard → AI utilities: uses AI helpers (evidence: `src/views/PatientView.jsx`)
- Reception dashboard → AI utilities: uses AI helpers (evidence: `src/views/ReceptionistView.jsx`)
- Application state → Auth routes: requests authentication (evidence: `src/context/AppContext.jsx`)
- Application state → Patient routes: requests patient records (evidence: `src/context/AppContext.jsx`)
- Application state → Appointment routes: requests appointments (evidence: `src/context/AppContext.jsx`)
- HTTP server → Auth routes: mounts routes (evidence: `hospital-automation-backend/src/server.js`)
- HTTP server → Patient routes: mounts routes (evidence: `hospital-automation-backend/src/server.js`)
- HTTP server → Appointment routes: mounts routes (evidence: `hospital-automation-backend/src/server.js`)
- HTTP server → OCR routes: mounts routes (evidence: `hospital-automation-backend/src/server.js`)
- HTTP server → Report routes: mounts routes (evidence: `hospital-automation-backend/src/server.js`)
- Auth routes → Authentication: dispatches (evidence: `hospital-automation-backend/src/routes/auth.routes.js`)
- Patient routes → Patient records: dispatches (evidence: `hospital-automation-backend/src/routes/patients.routes.js`)
- Appointment routes → Appointment workflow: dispatches (evidence: `hospital-automation-backend/src/routes/appointments.routes.js`)
- OCR routes → Prescription OCR: dispatches (evidence: `hospital-automation-backend/src/routes/ocr.routes.js`)
- Report routes → Hospital reports: dispatches (evidence: `hospital-automation-backend/src/routes/reports.routes.js`)
- Appointment routes → JWT authorization: authenticates requests (evidence: `hospital-automation-backend/src/routes/appointments.routes.js`)
- Appointment routes → Request validation: validates booking (evidence: `hospital-automation-backend/src/routes/appointments.routes.js`)
- OCR routes → JWT authorization: authenticates requests (evidence: `hospital-automation-backend/src/routes/ocr.routes.js`)
- Report routes → JWT authorization: authenticates requests (evidence: `hospital-automation-backend/src/routes/reports.routes.js`)
- Authentication → Supabase client: reads and writes (evidence: `hospital-automation-backend/src/controllers/auth.controller.js`)
- Patient records → Supabase client: reads and writes (evidence: `hospital-automation-backend/src/controllers/patients.controller.js`)
- Appointment workflow → Supabase client: reads and writes (evidence: `hospital-automation-backend/src/controllers/appointments.controller.js`)
- Prescription OCR → Supabase client: uses data store (evidence: `hospital-automation-backend/src/controllers/ocr.controller.js`)
- Hospital reports → Supabase client: reads data (evidence: `hospital-automation-backend/src/controllers/reports.controller.js`)
- Supabase client → Supabase data: connects (evidence: `hospital-automation-backend/src/config/db.js`)
- Prescription OCR → Gemini service: extracts prescription (evidence: `hospital-automation-backend/src/controllers/ocr.controller.js`)
- Hospital reports → Gemini service: generates summary (evidence: `hospital-automation-backend/src/controllers/reports.controller.js`)
- Gemini service → Google Gemini: sends AI request (evidence: `hospital-automation-backend/src/services/gemini.service.js`)
- HTTP server → Error handling: registers handlers (evidence: `hospital-automation-backend/src/server.js`)
