# mugetsu-1/hospital-booking-system architecture

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

- Interactive diagram: https://gitdiagram.com/mugetsu-1/hospital-booking-system
- Repository: https://github.com/mugetsu-1/hospital-booking-system

## Overview

Patients discover doctors, inspect computed availability, and book or manage appointments; doctors operate their queues and update visit status or governed notes; administrators manage directory/accounts and the hospital ledger. The React role-specific screens call an Express API whose controllers enforce domain rules and persist through Prisma/PostgreSQL. JWT/RBAC, slot computation, serialization, and cache invalidation support that workflow. Redis, Socket.IO, and email are documented as optional fail-open enhancements. Some frontend-to-backend and optional integration links rely on README statements because the relevant runtime wiring is not fully excerpted.

Main entry points: [`frontend/src/App.jsx`](https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/App.jsx) (Role-based screens), [`backend/src/controllers/appointmentController.js`](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/controllers/appointmentController.js) (Booking and visit rules), [`frontend/src/api/client.js`](https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/api/client.js) (HTTP API client), [`backend/src/app.js`](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/app.js) (Express API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_app["Role-based screens<br/>[App.jsx]"]
  node_browse["Doctor search<br/>[BrowseDoctors.jsx]"]
  node_myappointments["Appointment history<br/>[MyAppointments.jsx]"]
  node_doctorboard["Doctor queue"]
  node_adminboard["Admin ledger<br/>[AdminDashboard.jsx]"]
  node_authui["Sign-in and registration<br/>[AuthContext.jsx]"]
  node_client["HTTP API client<br/>[client.js]"]
  node_frontrealtime["Realtime client<br/>[realtime.js]"]
end

subgraph group_api["API and access"]
  node_express["Express API<br/>[app.js]"]
  node_authroutes["Authentication routes<br/>[authRoutes.js]"]
  node_patientroutes["Patient routes<br/>[patientRoutes.js]"]
  node_doctorroutes["Doctor routes<br/>[doctorRoutes.js]"]
  node_appointmentroutes["Appointment routes"]
  node_auth["JWT and RBAC<br/>[auth.js]"]
end

subgraph group_care["Appointment operations"]
  node_appointments["Booking and visit rules"]
  node_slotlogic["Slot computation<br/>[slots.js]"]
  node_domain["Appointment states<br/>[appointment.js]"]
end

subgraph group_directory["Directory and identity"]
  node_authcontroller["Account operations<br/>[authController.js]"]
  node_patientcontroller["Patient profiles"]
  node_doctorcontroller["Doctor directory and slots"]
end

subgraph group_platform["Persistence and integrations"]
  node_database["Prisma data access<br/>[db.js]"]
  node_postgres[("PostgreSQL")]
  node_cache["Redis cache<br/>[cache.js]"]
  node_realtime["Socket.IO service<br/>[realtime.js]"]
  node_mailer["Email notifications<br/>[mailer.js]"]
end

node_patient(("Patient"))
node_doctor(("Doctor"))
node_admin(("Administrator"))

node_patient -.->|"uses"| node_app
node_doctor -.->|"uses"| node_app
node_admin -.->|"uses"| node_app
node_app -->|"routes to"| node_browse
node_app -->|"routes to"| node_myappointments
node_app -->|"routes to"| node_doctorboard
node_app -->|"routes to"| node_adminboard
node_app -->|"provides auth"| node_authui
node_browse -->|"requests"| node_client
node_myappointments -->|"requests"| node_client
node_doctorboard -->|"requests"| node_client
node_adminboard -->|"requests"| node_client
node_authui -->|"auth requests"| node_client
node_client -.->|"sends API calls"| node_express
node_authui -->|"connects session"| node_frontrealtime
node_frontrealtime -.->|"opens realtime link"| node_realtime
node_express -->|"mounts"| node_authroutes
node_express -->|"mounts"| node_patientroutes
node_express -->|"mounts"| node_doctorroutes
node_express -->|"mounts"| node_appointmentroutes
node_authroutes -->|"dispatches"| node_authcontroller
node_patientroutes -->|"dispatches"| node_patientcontroller
node_doctorroutes -->|"dispatches"| node_doctorcontroller
node_appointmentroutes -->|"dispatches"| node_appointments
node_authroutes -->|"guards routes"| node_auth
node_patientroutes -->|"guards routes"| node_auth
node_doctorroutes -->|"guards routes"| node_auth
node_appointmentroutes -->|"guards routes"| node_auth
node_authcontroller -->|"reads and writes"| node_database
node_patientcontroller -->|"reads and writes"| node_database
node_doctorcontroller -->|"reads and writes"| node_database
node_appointments -->|"reads and writes"| node_database
node_doctorcontroller -->|"computes availability"| node_slotlogic
node_appointments -->|"validates slots"| node_slotlogic
node_appointmentroutes -->|"uses states"| node_domain
node_database -->|"persists data"| node_postgres
node_doctorcontroller -->|"caches directory and slots"| node_cache
node_appointments -->|"invalidates slots"| node_cache
node_doctorcontroller -->|"emits slot changes"| node_realtime
node_appointments -->|"emits appointment events"| node_realtime
node_appointments -->|"sends notifications"| node_mailer

click node_app "https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/App.jsx"
click node_browse "https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/pages/patient/BrowseDoctors.jsx"
click node_myappointments "https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/pages/patient/MyAppointments.jsx"
click node_doctorboard "https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/pages/doctor/DoctorDashboard.jsx"
click node_adminboard "https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/pages/admin/AdminDashboard.jsx"
click node_authui "https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/context/AuthContext.jsx"
click node_client "https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/api/client.js"
click node_frontrealtime "https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/realtime.js"
click node_express "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/app.js"
click node_authroutes "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/routes/authRoutes.js"
click node_patientroutes "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/routes/patientRoutes.js"
click node_doctorroutes "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/routes/doctorRoutes.js"
click node_appointmentroutes "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/routes/appointmentRoutes.js"
click node_auth "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/middleware/auth.js"
click node_authcontroller "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/controllers/authController.js"
click node_patientcontroller "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/controllers/patientController.js"
click node_doctorcontroller "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/controllers/doctorController.js"
click node_appointments "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/controllers/appointmentController.js"
click node_slotlogic "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/utils/slots.js"
click node_domain "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/domain/appointment.js"
click node_database "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/db.js"
click node_cache "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/utils/cache.js"
click node_realtime "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/services/realtime.js"
click node_mailer "https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/services/mailer.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_browse,node_myappointments,node_doctorboard,node_adminboard,node_authui,node_client,node_frontrealtime toneBlue
class node_express,node_authroutes,node_patientroutes,node_doctorroutes,node_appointmentroutes,node_auth toneAmber
class node_appointments,node_slotlogic,node_domain toneMint
class node_authcontroller,node_patientcontroller,node_doctorcontroller toneRose
class node_database,node_postgres,node_cache,node_realtime,node_mailer,node_patient,node_doctor,node_admin toneIndigo
```

## Components

### Web application

- [Role-based screens](https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Doctor search](https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/pages/patient/BrowseDoctors.jsx): `frontend/src/pages/patient/BrowseDoctors.jsx`
- [Appointment history](https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/pages/patient/MyAppointments.jsx): `frontend/src/pages/patient/MyAppointments.jsx`
- [Doctor queue](https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/pages/doctor/DoctorDashboard.jsx): `frontend/src/pages/doctor/DoctorDashboard.jsx`
- [Admin ledger](https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/pages/admin/AdminDashboard.jsx): `frontend/src/pages/admin/AdminDashboard.jsx`
- [Sign-in and registration](https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [HTTP API client](https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/api/client.js): `frontend/src/api/client.js`
- [Realtime client](https://github.com/mugetsu-1/hospital-booking-system/blob/main/frontend/src/realtime.js): `frontend/src/realtime.js`

### API and access

- [Express API](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/app.js): `backend/src/app.js`
- [Authentication routes](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/routes/authRoutes.js): `backend/src/routes/authRoutes.js`
- [Patient routes](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/routes/patientRoutes.js): `backend/src/routes/patientRoutes.js`
- [Doctor routes](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/routes/doctorRoutes.js): `backend/src/routes/doctorRoutes.js`
- [Appointment routes](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/routes/appointmentRoutes.js): `backend/src/routes/appointmentRoutes.js`
- [JWT and RBAC](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/middleware/auth.js): `backend/src/middleware/auth.js`

### Appointment operations

- [Booking and visit rules](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/controllers/appointmentController.js): `backend/src/controllers/appointmentController.js`
- [Slot computation](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/utils/slots.js): `backend/src/utils/slots.js`
- [Appointment states](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/domain/appointment.js): `backend/src/domain/appointment.js`

### Directory and identity

- [Account operations](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/controllers/authController.js): `backend/src/controllers/authController.js`
- [Patient profiles](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/controllers/patientController.js): `backend/src/controllers/patientController.js`
- [Doctor directory and slots](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/controllers/doctorController.js): `backend/src/controllers/doctorController.js`

### Persistence and integrations

- [Prisma data access](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/db.js): `backend/src/db.js`
- **PostgreSQL**
- [Redis cache](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/utils/cache.js): `backend/src/utils/cache.js`
- [Socket.IO service](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/services/realtime.js): `backend/src/services/realtime.js`
- [Email notifications](https://github.com/mugetsu-1/hospital-booking-system/blob/main/backend/src/services/mailer.js): `backend/src/services/mailer.js`

### Other components

- **Patient**
- **Doctor**
- **Administrator**

## Connections

- Patient → Role-based screens: uses (evidence: `README.md`)
- Doctor → Role-based screens: uses (evidence: `README.md`)
- Administrator → Role-based screens: uses (evidence: `README.md`)
- Role-based screens → Doctor search: routes to (evidence: `frontend/src/App.jsx`)
- Role-based screens → Appointment history: routes to (evidence: `frontend/src/App.jsx`)
- Role-based screens → Doctor queue: routes to (evidence: `frontend/src/App.jsx`)
- Role-based screens → Admin ledger: routes to (evidence: `frontend/src/App.jsx`)
- Role-based screens → Sign-in and registration: provides auth (evidence: `frontend/src/App.jsx`)
- Doctor search → HTTP API client: requests (evidence: `frontend/src/pages/patient/BrowseDoctors.jsx`)
- Appointment history → HTTP API client: requests (evidence: `frontend/src/pages/patient/MyAppointments.jsx`)
- Doctor queue → HTTP API client: requests (evidence: `frontend/src/pages/doctor/DoctorDashboard.jsx`)
- Admin ledger → HTTP API client: requests (evidence: `frontend/src/pages/admin/AdminDashboard.jsx`)
- Sign-in and registration → HTTP API client: auth requests (evidence: `frontend/src/context/AuthContext.jsx`)
- HTTP API client → Express API: sends API calls (evidence: `README.md`)
- Sign-in and registration → Realtime client: connects session (evidence: `frontend/src/context/AuthContext.jsx`)
- Realtime client → Socket.IO service: opens realtime link (evidence: `README.md`)
- Express API → Authentication routes: mounts (evidence: `backend/src/app.js`)
- Express API → Patient routes: mounts (evidence: `backend/src/app.js`)
- Express API → Doctor routes: mounts (evidence: `backend/src/app.js`)
- Express API → Appointment routes: mounts (evidence: `backend/src/app.js`)
- Authentication routes → Account operations: dispatches (evidence: `backend/src/routes/authRoutes.js`)
- Patient routes → Patient profiles: dispatches (evidence: `backend/src/routes/patientRoutes.js`)
- Doctor routes → Doctor directory and slots: dispatches (evidence: `backend/src/routes/doctorRoutes.js`)
- Appointment routes → Booking and visit rules: dispatches (evidence: `backend/src/routes/appointmentRoutes.js`)
- Authentication routes → JWT and RBAC: guards routes (evidence: `backend/src/routes/authRoutes.js`)
- Patient routes → JWT and RBAC: guards routes (evidence: `backend/src/routes/patientRoutes.js`)
- Doctor routes → JWT and RBAC: guards routes (evidence: `backend/src/routes/doctorRoutes.js`)
- Appointment routes → JWT and RBAC: guards routes (evidence: `backend/src/routes/appointmentRoutes.js`)
- Account operations → Prisma data access: reads and writes (evidence: `backend/src/controllers/authController.js`)
- Patient profiles → Prisma data access: reads and writes (evidence: `backend/src/controllers/patientController.js`)
- Doctor directory and slots → Prisma data access: reads and writes (evidence: `backend/src/controllers/doctorController.js`)
- Booking and visit rules → Prisma data access: reads and writes (evidence: `backend/src/controllers/appointmentController.js`)
- Doctor directory and slots → Slot computation: computes availability (evidence: `backend/src/controllers/doctorController.js`)
- Booking and visit rules → Slot computation: validates slots (evidence: `backend/src/controllers/appointmentController.js`)
- Appointment routes → Appointment states: uses states (evidence: `backend/src/routes/appointmentRoutes.js`)
- Prisma data access → PostgreSQL: persists data (evidence: `README.md`)
- Doctor directory and slots → Redis cache: caches directory and slots (evidence: `backend/src/controllers/doctorController.js`)
- Booking and visit rules → Redis cache: invalidates slots (evidence: `backend/src/controllers/appointmentController.js`)
- Doctor directory and slots → Socket.IO service: emits slot changes (evidence: `backend/src/controllers/doctorController.js`)
- Booking and visit rules → Socket.IO service: emits appointment events (evidence: `backend/src/controllers/appointmentController.js`)
- Booking and visit rules → Email notifications: sends notifications (evidence: `backend/src/controllers/appointmentController.js`)
