# memonriyaz/wardwatch architecture

> Architecture diagram of the GitHub repository memonriyaz/wardwatch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/memonriyaz/wardwatch
- Repository: https://github.com/memonriyaz/wardwatch

## Overview

WardWatch is a live hospital ward-capacity and patient-flow system. Staff create and prioritize admissions, assign patients to beds, manage discharge and cleaning transitions, while clinicians update patient records and administrators review hospital capacity. The server persists these workflows and publishes live events to role-specific dashboards. It also monitors operational anomalies and captures shareable shift handovers. The README documents analytics and capacity features whose controller implementations were not sampled, so their wiring is shown only where supported by the repository structure and documentation.

Main entry points: [`server/index.js`](https://github.com/memonriyaz/wardwatch/blob/main/server/index.js) (Express API), [`server/src/models`](https://github.com/memonriyaz/wardwatch/tree/main/server/src/models) (Domain records), [`client/src/App.jsx`](https://github.com/memonriyaz/wardwatch/blob/main/client/src/App.jsx) (Role dashboards), [`server/src/sse/eventStream.js`](https://github.com/memonriyaz/wardwatch/blob/main/server/src/sse/eventStream.js) (Event stream)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Dashboards"]
  node_app["Role dashboards<br/>[App.jsx]"]
  node_staffdash["Staff dashboard<br/>[StaffDashboard.jsx]"]
  node_doctordash["Doctor dashboard"]
  node_admindash["Admin dashboard<br/>[AdminDashboard.jsx]"]
  node_sharedreport["Shared handover"]
  node_login["Login<br/>[Login.jsx]"]
end

subgraph group_api["API and access"]
  node_server["Express API<br/>[index.js]"]
  node_auth["Authentication<br/>[authController.js]"]
  node_models[("Domain records")]
end

subgraph group_flow["Ward operations"]
  node_admissions["Admission queue"]
  node_admissionservice["Queue and bed assignment"]
  node_beds["Bed management<br/>[bedController.js]"]
end

subgraph group_clinical["Clinical and oversight"]
  node_patients["Patient care"]
  node_capacity["Capacity analytics"]
  node_analytics["Ward analytics"]
  node_escalations["Escalation monitoring"]
end

subgraph group_realtime["Live updates and handover"]
  node_handover["Handover snapshots"]
  node_cron["Scheduled handovers<br/>[handoverCron.js]"]
  node_events["Event stream<br/>[eventStream.js]"]
  node_sse["SSE endpoint<br/>[sseRoutes.js]"]
end

node_staff(("Nursing staff"))
node_doctor(("Doctor"))
node_admin(("Administrator"))
node_mongo[("MongoDB")]

node_staff -->|"opens dashboard"| node_app
node_doctor -->|"opens dashboard"| node_app
node_admin -->|"opens dashboard"| node_app
node_app -->|"routes login"| node_login
node_app -->|"routes staff"| node_staffdash
node_app -->|"routes doctor"| node_doctordash
node_app -->|"routes admin"| node_admindash
node_app -->|"routes shared report"| node_sharedreport
node_login -->|"authenticates via API"| node_server
node_staffdash -->|"uses ward APIs"| node_server
node_doctordash -->|"uses patient APIs"| node_server
node_admindash -->|"uses analytics APIs"| node_server
node_sharedreport -->|"fetches snapshot"| node_server
node_server -->|"dispatches auth routes"| node_auth
node_server -->|"dispatches admission routes"| node_admissions
node_server -->|"dispatches bed routes"| node_beds
node_server -->|"dispatches patient routes"| node_patients
node_server -->|"dispatches capacity routes"| node_capacity
node_server -->|"dispatches analytics routes"| node_analytics
node_server -->|"dispatches handover routes"| node_handover
node_admissions -->|"queues and assigns"| node_admissionservice
node_admissions -->|"reads and writes"| node_models
node_admissionservice -->|"reads and assigns"| node_models
node_beds -->|"updates bed state"| node_models
node_beds -->|"processes freed beds"| node_admissionservice
node_patients -->|"updates patient records"| node_models
node_patients -->|"publishes changes"| node_events
node_admissions -->|"publishes admissions"| node_events
node_beds -->|"publishes bed changes"| node_events
node_server -->|"runs checks periodically"| node_escalations
node_escalations -->|"checks and records alerts"| node_models
node_escalations -->|"publishes alerts"| node_events
node_server -->|"starts scheduled worker"| node_cron
node_cron -->|"generates snapshots"| node_handover
node_handover -->|"reads ward state and stores snapshots"| node_models
node_server -->|"mounts event endpoint"| node_sse
node_sse -->|"streams events"| node_events
node_events -->|"pushes live updates"| node_staffdash
node_events -->|"pushes live updates"| node_doctordash
node_events -->|"pushes live updates"| node_admindash
node_models -->|"persists records"| node_mongo
node_capacity -->|"reads capacity data"| node_models
node_analytics -->|"reads analytics data"| node_models
node_handover -->|"serves shared snapshot"| node_sharedreport

click node_app "https://github.com/memonriyaz/wardwatch/blob/main/client/src/App.jsx"
click node_staffdash "https://github.com/memonriyaz/wardwatch/blob/main/client/src/pages/staff/StaffDashboard.jsx"
click node_doctordash "https://github.com/memonriyaz/wardwatch/blob/main/client/src/pages/doctor/DoctorDashboard.jsx"
click node_admindash "https://github.com/memonriyaz/wardwatch/blob/main/client/src/pages/admin/AdminDashboard.jsx"
click node_sharedreport "https://github.com/memonriyaz/wardwatch/blob/main/client/src/pages/shared/SharedHandoverReport.jsx"
click node_login "https://github.com/memonriyaz/wardwatch/blob/main/client/src/pages/auth/Login.jsx"
click node_server "https://github.com/memonriyaz/wardwatch/blob/main/server/index.js"
click node_auth "https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/authController.js"
click node_admissions "https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/admissionController.js"
click node_admissionservice "https://github.com/memonriyaz/wardwatch/blob/main/server/src/services/admissionService.js"
click node_beds "https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/bedController.js"
click node_patients "https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/patientController.js"
click node_capacity "https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/capacityController.js"
click node_analytics "https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/analyticsController.js"
click node_escalations "https://github.com/memonriyaz/wardwatch/blob/main/server/src/services/escalationService.js"
click node_handover "https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/handoverController.js"
click node_cron "https://github.com/memonriyaz/wardwatch/blob/main/server/src/cron/handoverCron.js"
click node_events "https://github.com/memonriyaz/wardwatch/blob/main/server/src/sse/eventStream.js"
click node_sse "https://github.com/memonriyaz/wardwatch/blob/main/server/src/routes/sseRoutes.js"
click node_models "https://github.com/memonriyaz/wardwatch/tree/main/server/src/models"

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_staffdash,node_doctordash,node_admindash,node_sharedreport,node_login toneBlue
class node_server,node_auth,node_models,node_mongo toneAmber
class node_admissions,node_admissionservice,node_beds toneMint
class node_patients,node_capacity,node_analytics,node_escalations toneRose
class node_handover,node_cron,node_events,node_sse,node_staff,node_doctor,node_admin toneIndigo
```

## Components

### Dashboards

- [Role dashboards](https://github.com/memonriyaz/wardwatch/blob/main/client/src/App.jsx): `client/src/App.jsx`
- [Staff dashboard](https://github.com/memonriyaz/wardwatch/blob/main/client/src/pages/staff/StaffDashboard.jsx): `client/src/pages/staff/StaffDashboard.jsx`
- [Doctor dashboard](https://github.com/memonriyaz/wardwatch/blob/main/client/src/pages/doctor/DoctorDashboard.jsx): `client/src/pages/doctor/DoctorDashboard.jsx`
- [Admin dashboard](https://github.com/memonriyaz/wardwatch/blob/main/client/src/pages/admin/AdminDashboard.jsx): `client/src/pages/admin/AdminDashboard.jsx`
- [Shared handover](https://github.com/memonriyaz/wardwatch/blob/main/client/src/pages/shared/SharedHandoverReport.jsx): `client/src/pages/shared/SharedHandoverReport.jsx`
- [Login](https://github.com/memonriyaz/wardwatch/blob/main/client/src/pages/auth/Login.jsx): `client/src/pages/auth/Login.jsx`

### API and access

- [Express API](https://github.com/memonriyaz/wardwatch/blob/main/server/index.js): `server/index.js`
- [Authentication](https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/authController.js): `server/src/controllers/authController.js`
- [Domain records](https://github.com/memonriyaz/wardwatch/tree/main/server/src/models): `server/src/models`

### Ward operations

- [Admission queue](https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/admissionController.js): `server/src/controllers/admissionController.js`
- [Queue and bed assignment](https://github.com/memonriyaz/wardwatch/blob/main/server/src/services/admissionService.js): `server/src/services/admissionService.js`
- [Bed management](https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/bedController.js): `server/src/controllers/bedController.js`

### Clinical and oversight

- [Patient care](https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/patientController.js): `server/src/controllers/patientController.js`
- [Capacity analytics](https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/capacityController.js): `server/src/controllers/capacityController.js`
- [Ward analytics](https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/analyticsController.js): `server/src/controllers/analyticsController.js`
- [Escalation monitoring](https://github.com/memonriyaz/wardwatch/blob/main/server/src/services/escalationService.js): `server/src/services/escalationService.js`

### Live updates and handover

- [Handover snapshots](https://github.com/memonriyaz/wardwatch/blob/main/server/src/controllers/handoverController.js): `server/src/controllers/handoverController.js`
- [Scheduled handovers](https://github.com/memonriyaz/wardwatch/blob/main/server/src/cron/handoverCron.js): `server/src/cron/handoverCron.js`
- [Event stream](https://github.com/memonriyaz/wardwatch/blob/main/server/src/sse/eventStream.js): `server/src/sse/eventStream.js`
- [SSE endpoint](https://github.com/memonriyaz/wardwatch/blob/main/server/src/routes/sseRoutes.js): `server/src/routes/sseRoutes.js`

### Other components

- **Nursing staff**
- **Doctor**
- **Administrator**
- **MongoDB**

## Connections

- Nursing staff → Role dashboards: opens dashboard
- Doctor → Role dashboards: opens dashboard
- Administrator → Role dashboards: opens dashboard
- Role dashboards → Login: routes login
- Role dashboards → Staff dashboard: routes staff
- Role dashboards → Doctor dashboard: routes doctor
- Role dashboards → Admin dashboard: routes admin
- Role dashboards → Shared handover: routes shared report
- Login → Express API: authenticates via API
- Staff dashboard → Express API: uses ward APIs
- Doctor dashboard → Express API: uses patient APIs
- Admin dashboard → Express API: uses analytics APIs
- Shared handover → Express API: fetches snapshot
- Express API → Authentication: dispatches auth routes
- Express API → Admission queue: dispatches admission routes
- Express API → Bed management: dispatches bed routes
- Express API → Patient care: dispatches patient routes
- Express API → Capacity analytics: dispatches capacity routes
- Express API → Ward analytics: dispatches analytics routes
- Express API → Handover snapshots: dispatches handover routes
- Admission queue → Queue and bed assignment: queues and assigns
- Admission queue → Domain records: reads and writes
- Queue and bed assignment → Domain records: reads and assigns
- Bed management → Domain records: updates bed state
- Bed management → Queue and bed assignment: processes freed beds
- Patient care → Domain records: updates patient records
- Patient care → Event stream: publishes changes
- Admission queue → Event stream: publishes admissions
- Bed management → Event stream: publishes bed changes
- Express API → Escalation monitoring: runs checks periodically
- Escalation monitoring → Domain records: checks and records alerts
- Escalation monitoring → Event stream: publishes alerts
- Express API → Scheduled handovers: starts scheduled worker
- Scheduled handovers → Handover snapshots: generates snapshots
- Handover snapshots → Domain records: reads ward state and stores snapshots
- Express API → SSE endpoint: mounts event endpoint
- SSE endpoint → Event stream: streams events
- Event stream → Staff dashboard: pushes live updates
- Event stream → Doctor dashboard: pushes live updates
- Event stream → Admin dashboard: pushes live updates
- Domain records → MongoDB: persists records
- Capacity analytics → Domain records: reads capacity data
- Ward analytics → Domain records: reads analytics data
- Handover snapshots → Shared handover: serves shared snapshot
