# sitabja-web/hospital-management-system-v1 architecture

> Architecture diagram of the GitHub repository sitabja-web/hospital-management-system-v1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sitabja-web/hospital-management-system-v1
- Repository: https://github.com/sitabja-web/hospital-management-system-v1

## Overview

HMS is a role-based hospital operations application: users sign in or register, then manage patients, doctors and departments, appointments, clinical records and prescriptions, billing, and administrative oversight. The React client presents those workflows through role-aware pages and forms; its API library communicates with an Express API, whose routes and authorization middleware dispatch to controllers and PostgreSQL-backed models. The README documents the broader product capabilities; sampled source confirms representative frontend routing, authentication, API setup, and backend controller/model responsibilities, but not every domain route or controller call.

Main entry points: [`server/src/routes/index.js`](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/routes/index.js) (API routes), [`client/src/App.tsx`](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/App.tsx) (App shell), [`server/src/models`](https://github.com/sitabja-web/hospital-management-system-v1/tree/main/server/src/models) (PostgreSQL domain models), [`client/src/lib/api.ts`](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/lib/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React client"]
  node_app["App shell<br/>[App.tsx]"]
  node_login["Login and signup<br/>[Login.tsx]"]
  node_authctx["Session context<br/>[AuthContext.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
  node_dashboard["Dashboard<br/>[Dashboard.tsx]"]
  node_patient_ui["Patient management<br/>[Patients.tsx]"]
  node_doctor_ui["Doctors and availability<br/>[Doctors.tsx]"]
  node_appointment_ui["Appointment scheduling<br/>[Appointments.tsx]"]
  node_record_ui["Records and prescriptions<br/>[MedicalRecords.tsx]"]
  node_billing_ui["Billing<br/>[Billing.tsx]"]
  node_settings_ui["Settings and oversight<br/>[Settings.tsx]"]
end

subgraph group_api["API and access"]
  node_routes["API routes<br/>[index.js]"]
  node_auth_mw["JWT and role checks<br/>[auth.js]"]
  node_auth_controller["Authentication workflow<br/>[authController.js]"]
  node_express["Express application<br/>[app.js]"]
end

subgraph group_clinical["Clinical operations"]
  node_patient_controller["Patient workflows"]
  node_appointment_controller["Appointment workflows"]
  node_record_controller["Clinical record workflows"]
  node_doctor_department["Doctors and departments"]
  node_billing_controller["Invoice workflows"]
end

subgraph group_admin["Administration and data"]
  node_admin_controller["Staff and administration<br/>[adminController.js]"]
  node_system_controller["Dashboard and system"]
  node_models["PostgreSQL domain models"]
  node_audit["Audit log model<br/>[auditModel.js]"]
  node_database[("PostgreSQL<br/>[client.js]")]
end

node_users(("Hospital users"))

node_users -->|"sign in or register"| node_login
node_app -->|"provides session"| node_authctx
node_app -->|"shows when signed out"| node_login
node_app -->|"routes by role"| node_dashboard
node_app -->|"routes by role"| node_patient_ui
node_app -->|"routes by role"| node_doctor_ui
node_app -->|"routes by role"| node_appointment_ui
node_app -->|"routes by role"| node_record_ui
node_app -->|"routes by role"| node_billing_ui
node_app -->|"routes by role"| node_settings_ui
node_login -->|"submits credentials"| node_authctx
node_authctx -->|"calls authentication API"| node_api_client
node_patient_ui -.->|"requests patient data"| node_api_client
node_doctor_ui -.->|"requests doctor data"| node_api_client
node_appointment_ui -.->|"requests appointments"| node_api_client
node_record_ui -.->|"requests records"| node_api_client
node_billing_ui -.->|"requests invoices"| node_api_client
node_settings_ui -.->|"requests admin data"| node_api_client
node_api_client -.->|"sends API requests"| node_express
node_express -->|"mounts API routes"| node_routes
node_routes -->|"applies authorization"| node_auth_mw
node_routes -->|"dispatches auth requests"| node_auth_controller
node_routes -->|"dispatches patient requests"| node_patient_controller
node_routes -.->|"dispatches appointments"| node_appointment_controller
node_routes -.->|"dispatches record requests"| node_record_controller
node_routes -.->|"dispatches directory requests"| node_doctor_department
node_routes -->|"dispatches billing requests"| node_billing_controller
node_routes -->|"dispatches admin requests"| node_admin_controller
node_routes -->|"dispatches system requests"| node_system_controller
node_auth_controller -->|"reads and updates accounts"| node_models
node_auth_controller -->|"records auth events"| node_audit
node_patient_controller -->|"coordinates patient data"| node_models
node_appointment_controller -->|"coordinates appointments"| node_models
node_record_controller -.->|"coordinates clinical records"| node_models
node_doctor_department -.->|"coordinates directory data"| node_models
node_billing_controller -->|"coordinates invoices"| node_models
node_admin_controller -->|"manages staff and departments"| node_models
node_admin_controller -->|"records admin actions"| node_audit
node_system_controller -.->|"reads system summaries"| node_models
node_models -.->|"queries PostgreSQL"| node_database
node_audit -->|"writes and reads logs"| node_database

click node_app "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/App.tsx"
click node_login "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Login.tsx"
click node_authctx "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/contexts/AuthContext.tsx"
click node_api_client "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/lib/api.ts"
click node_dashboard "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Dashboard.tsx"
click node_patient_ui "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Patients.tsx"
click node_doctor_ui "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Doctors.tsx"
click node_appointment_ui "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Appointments.tsx"
click node_record_ui "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/MedicalRecords.tsx"
click node_billing_ui "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Billing.tsx"
click node_settings_ui "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Settings.tsx"
click node_routes "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/routes/index.js"
click node_auth_mw "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/middleware/auth.js"
click node_auth_controller "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/authController.js"
click node_patient_controller "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/patientController.js"
click node_appointment_controller "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/appointmentController.js"
click node_record_controller "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/medicalRecordController.js"
click node_doctor_department "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/doctorController.js"
click node_billing_controller "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/billingController.js"
click node_admin_controller "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/adminController.js"
click node_system_controller "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/systemController.js"
click node_models "https://github.com/sitabja-web/hospital-management-system-v1/tree/main/server/src/models"
click node_audit "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/models/auditModel.js"
click node_database "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/db/client.js"
click node_express "https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/app.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_authctx,node_api_client,node_dashboard,node_patient_ui,node_doctor_ui,node_appointment_ui,node_record_ui,node_billing_ui,node_settings_ui,node_users toneBlue
class node_routes,node_auth_mw,node_auth_controller,node_express toneAmber
class node_patient_controller,node_appointment_controller,node_record_controller,node_doctor_department,node_billing_controller toneMint
class node_admin_controller,node_system_controller,node_models,node_audit,node_database toneRose
```

## Components

### React client

- [App shell](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/App.tsx): `client/src/App.tsx`
- [Login and signup](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Login.tsx): `client/src/pages/Login.tsx`
- [Session context](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/contexts/AuthContext.tsx): `client/src/contexts/AuthContext.tsx`
- [API client](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/lib/api.ts): `client/src/lib/api.ts`
- [Dashboard](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Dashboard.tsx): `client/src/pages/Dashboard.tsx`
- [Patient management](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Patients.tsx): `client/src/pages/Patients.tsx`
- [Doctors and availability](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Doctors.tsx): `client/src/pages/Doctors.tsx`
- [Appointment scheduling](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Appointments.tsx): `client/src/pages/Appointments.tsx`
- [Records and prescriptions](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/MedicalRecords.tsx): `client/src/pages/MedicalRecords.tsx`
- [Billing](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Billing.tsx): `client/src/pages/Billing.tsx`
- [Settings and oversight](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/client/src/pages/Settings.tsx): `client/src/pages/Settings.tsx`

### API and access

- [API routes](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/routes/index.js): `server/src/routes/index.js`
- [JWT and role checks](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/middleware/auth.js): `server/src/middleware/auth.js`
- [Authentication workflow](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/authController.js): `server/src/controllers/authController.js`
- [Express application](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/app.js): `server/src/app.js`

### Clinical operations

- [Patient workflows](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/patientController.js): `server/src/controllers/patientController.js`
- [Appointment workflows](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/appointmentController.js): `server/src/controllers/appointmentController.js`
- [Clinical record workflows](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/medicalRecordController.js): `server/src/controllers/medicalRecordController.js`
- [Doctors and departments](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/doctorController.js): `server/src/controllers/doctorController.js`
- [Invoice workflows](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/billingController.js): `server/src/controllers/billingController.js`

### Administration and data

- [Staff and administration](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/adminController.js): `server/src/controllers/adminController.js`
- [Dashboard and system](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/controllers/systemController.js): `server/src/controllers/systemController.js`
- [PostgreSQL domain models](https://github.com/sitabja-web/hospital-management-system-v1/tree/main/server/src/models): `server/src/models`
- [Audit log model](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/models/auditModel.js): `server/src/models/auditModel.js`
- [PostgreSQL](https://github.com/sitabja-web/hospital-management-system-v1/blob/main/server/src/db/client.js): `server/src/db/client.js`

### Other components

- **Hospital users**

## Connections

- Hospital users → Login and signup: sign in or register (evidence: `README.md`)
- App shell → Session context: provides session (evidence: `client/src/App.tsx`)
- App shell → Login and signup: shows when signed out (evidence: `client/src/App.tsx`)
- App shell → Dashboard: routes by role (evidence: `client/src/App.tsx`)
- App shell → Patient management: routes by role (evidence: `client/src/App.tsx`)
- App shell → Doctors and availability: routes by role (evidence: `client/src/App.tsx`)
- App shell → Appointment scheduling: routes by role (evidence: `client/src/App.tsx`)
- App shell → Records and prescriptions: routes by role (evidence: `client/src/App.tsx`)
- App shell → Billing: routes by role (evidence: `client/src/App.tsx`)
- App shell → Settings and oversight: routes by role (evidence: `client/src/App.tsx`)
- Login and signup → Session context: submits credentials (evidence: `client/src/pages/Login.tsx`)
- Session context → API client: calls authentication API (evidence: `client/src/contexts/AuthContext.tsx`)
- Patient management → API client: requests patient data
- Doctors and availability → API client: requests doctor data
- Appointment scheduling → API client: requests appointments
- Records and prescriptions → API client: requests records
- Billing → API client: requests invoices
- Settings and oversight → API client: requests admin data (evidence: `client/src/pages/Settings.tsx`)
- API client → Express application: sends API requests (evidence: `README.md`)
- Express application → API routes: mounts API routes (evidence: `server/src/app.js`)
- API routes → JWT and role checks: applies authorization
- API routes → Authentication workflow: dispatches auth requests
- API routes → Patient workflows: dispatches patient requests
- API routes → Appointment workflows: dispatches appointments
- API routes → Clinical record workflows: dispatches record requests
- API routes → Doctors and departments: dispatches directory requests
- API routes → Invoice workflows: dispatches billing requests
- API routes → Staff and administration: dispatches admin requests
- API routes → Dashboard and system: dispatches system requests
- Authentication workflow → PostgreSQL domain models: reads and updates accounts (evidence: `server/src/controllers/authController.js`)
- Authentication workflow → Audit log model: records auth events (evidence: `server/src/controllers/authController.js`)
- Patient workflows → PostgreSQL domain models: coordinates patient data (evidence: `server/src/controllers/patientController.js`)
- Appointment workflows → PostgreSQL domain models: coordinates appointments (evidence: `server/src/controllers/appointmentController.js`)
- Clinical record workflows → PostgreSQL domain models: coordinates clinical records
- Doctors and departments → PostgreSQL domain models: coordinates directory data
- Invoice workflows → PostgreSQL domain models: coordinates invoices (evidence: `server/src/controllers/billingController.js`)
- Staff and administration → PostgreSQL domain models: manages staff and departments (evidence: `server/src/controllers/adminController.js`)
- Staff and administration → Audit log model: records admin actions (evidence: `server/src/controllers/adminController.js`)
- Dashboard and system → PostgreSQL domain models: reads system summaries
- PostgreSQL domain models → PostgreSQL: queries PostgreSQL (evidence: `README.md`)
- Audit log model → PostgreSQL: writes and reads logs (evidence: `server/src/models/auditModel.js`)
