# thisisbsl/hospital-management-system architecture

> Architecture diagram of the GitHub repository thisisbsl/hospital-management-system, 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/thisisbsl/hospital-management-system
- Repository: https://github.com/thisisbsl/hospital-management-system

## Overview

MediFlow is a role-based hospital management portal for patients, doctors, and administrators. Users authenticate and enter role-specific dashboards; the backend exposes appointment booking and management, doctor lookup, medical records, and dashboard statistics. A typical care workflow is appointment scheduling, doctor consultation and record creation, then access to medical history and role-specific summaries. The backend separates HTTP routes, controllers, database operations, and MongoDB models. Dashboard API wiring is not shown in the sampled frontend excerpts, so those links are omitted.

Main entry points: [`backend/services/dbService.js`](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/services/dbService.js) (Data operations), [`backend/server.js`](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/server.js) (API server), [`frontend/src/pages/Auth.jsx`](https://github.com/thisisbsl/hospital-management-system/blob/main/frontend/src/pages/Auth.jsx) (Sign-in and registration), [`backend/middleware/authMiddleware.js`](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/middleware/authMiddleware.js) (Token and role checks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Portal UI"]
  node_app["Role-based app<br/>[App.jsx]"]
  node_auth_page["Sign-in and registration<br/>[Auth.jsx]"]
  node_auth_context["Auth state<br/>[AuthContext.jsx]"]
  node_dashboards["Role dashboards"]
end

subgraph group_api["HTTP API"]
  node_server["API server<br/>[server.js]"]
  node_auth_routes["Authentication routes<br/>[authRoutes.js]"]
  node_appointment_routes["Appointment routes"]
  node_record_routes["Medical record routes<br/>[recordRoutes.js]"]
  node_stats_routes["Statistics routes<br/>[statRoutes.js]"]
  node_auth_middleware["Token and role checks<br/>[authMiddleware.js]"]
end

subgraph group_domain["Care workflows"]
  node_auth_controller["Account handling<br/>[authController.js]"]
  node_appointment_controller["Appointment handling"]
  node_record_controller["Clinical records"]
  node_stat_controller["Dashboard metrics<br/>[statController.js]"]
end

subgraph group_data["Persistence"]
  node_db_service["Data operations<br/>[dbService.js]"]
  node_user_model["User model<br/>[User.js]"]
  node_appointment_model["Appointment model<br/>[Appointment.js]"]
  node_record_model["Medical record model<br/>[MedicalRecord.js]"]
  node_mongo[("MongoDB")]
end

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

node_patient -->|"signs in"| node_auth_page
node_doctor -->|"signs in"| node_auth_page
node_admin -->|"signs in"| node_auth_page
node_auth_page -->|"calls login"| node_auth_context
node_auth_context -->|"provides identity"| node_app
node_app -->|"renders by role"| node_dashboards
node_server -->|"mounts routes"| node_auth_routes
node_server -->|"mounts routes"| node_appointment_routes
node_server -->|"mounts routes"| node_record_routes
node_server -->|"mounts routes"| node_stats_routes
node_auth_routes -->|"dispatches"| node_auth_controller
node_auth_routes -->|"protects profile"| node_auth_middleware
node_appointment_routes -->|"protects routes"| node_auth_middleware
node_appointment_routes -->|"dispatches"| node_appointment_controller
node_record_routes -->|"protects routes"| node_auth_middleware
node_record_routes -->|"dispatches"| node_record_controller
node_stats_routes -->|"protects routes"| node_auth_middleware
node_stats_routes -->|"dispatches"| node_stat_controller
node_auth_controller -->|"queries users"| node_db_service
node_appointment_controller -->|"manages appointments"| node_db_service
node_record_controller -->|"manages records"| node_db_service
node_stat_controller -->|"loads metrics"| node_db_service
node_db_service -->|"reads and writes"| node_user_model
node_db_service -->|"reads and writes"| node_appointment_model
node_db_service -->|"reads and writes"| node_record_model
node_user_model -->|"persists"| node_mongo
node_appointment_model -->|"persists"| node_mongo
node_record_model -->|"persists"| node_mongo

click node_app "https://github.com/thisisbsl/hospital-management-system/blob/main/frontend/src/App.jsx"
click node_auth_page "https://github.com/thisisbsl/hospital-management-system/blob/main/frontend/src/pages/Auth.jsx"
click node_auth_context "https://github.com/thisisbsl/hospital-management-system/blob/main/frontend/src/context/AuthContext.jsx"
click node_dashboards "https://github.com/thisisbsl/hospital-management-system/tree/main/frontend/src/pages"
click node_server "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/server.js"
click node_auth_routes "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/routes/authRoutes.js"
click node_appointment_routes "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/routes/appointmentRoutes.js"
click node_record_routes "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/routes/recordRoutes.js"
click node_stats_routes "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/routes/statRoutes.js"
click node_auth_middleware "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/middleware/authMiddleware.js"
click node_auth_controller "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/controllers/authController.js"
click node_appointment_controller "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/controllers/appointmentController.js"
click node_record_controller "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/controllers/recordController.js"
click node_stat_controller "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/controllers/statController.js"
click node_db_service "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/services/dbService.js"
click node_user_model "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/models/User.js"
click node_appointment_model "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/models/Appointment.js"
click node_record_model "https://github.com/thisisbsl/hospital-management-system/blob/main/backend/models/MedicalRecord.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_auth_page,node_auth_context,node_dashboards toneBlue
class node_server,node_auth_routes,node_appointment_routes,node_record_routes,node_stats_routes,node_auth_middleware toneAmber
class node_auth_controller,node_appointment_controller,node_record_controller,node_stat_controller toneMint
class node_db_service,node_user_model,node_appointment_model,node_record_model,node_mongo toneRose
class node_patient,node_doctor,node_admin toneIndigo
```

## Components

### Portal UI

- [Role-based app](https://github.com/thisisbsl/hospital-management-system/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Sign-in and registration](https://github.com/thisisbsl/hospital-management-system/blob/main/frontend/src/pages/Auth.jsx): `frontend/src/pages/Auth.jsx`
- [Auth state](https://github.com/thisisbsl/hospital-management-system/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [Role dashboards](https://github.com/thisisbsl/hospital-management-system/tree/main/frontend/src/pages): `frontend/src/pages`

### HTTP API

- [API server](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/server.js): `backend/server.js`
- [Authentication routes](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/routes/authRoutes.js): `backend/routes/authRoutes.js`
- [Appointment routes](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/routes/appointmentRoutes.js): `backend/routes/appointmentRoutes.js`
- [Medical record routes](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/routes/recordRoutes.js): `backend/routes/recordRoutes.js`
- [Statistics routes](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/routes/statRoutes.js): `backend/routes/statRoutes.js`
- [Token and role checks](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/middleware/authMiddleware.js): `backend/middleware/authMiddleware.js`

### Care workflows

- [Account handling](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/controllers/authController.js): `backend/controllers/authController.js`
- [Appointment handling](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/controllers/appointmentController.js): `backend/controllers/appointmentController.js`
- [Clinical records](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/controllers/recordController.js): `backend/controllers/recordController.js`
- [Dashboard metrics](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/controllers/statController.js): `backend/controllers/statController.js`

### Persistence

- [Data operations](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/services/dbService.js): `backend/services/dbService.js`
- [User model](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/models/User.js): `backend/models/User.js`
- [Appointment model](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/models/Appointment.js): `backend/models/Appointment.js`
- [Medical record model](https://github.com/thisisbsl/hospital-management-system/blob/main/backend/models/MedicalRecord.js): `backend/models/MedicalRecord.js`
- **MongoDB**

### Other components

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

## Connections

- Patient → Sign-in and registration: signs in
- Doctor → Sign-in and registration: signs in
- Administrator → Sign-in and registration: signs in
- Sign-in and registration → Auth state: calls login
- Auth state → Role-based app: provides identity
- Role-based app → Role dashboards: renders by role
- API server → Authentication routes: mounts routes
- API server → Appointment routes: mounts routes
- API server → Medical record routes: mounts routes
- API server → Statistics routes: mounts routes
- Authentication routes → Account handling: dispatches
- Authentication routes → Token and role checks: protects profile
- Appointment routes → Token and role checks: protects routes
- Appointment routes → Appointment handling: dispatches
- Medical record routes → Token and role checks: protects routes
- Medical record routes → Clinical records: dispatches
- Statistics routes → Token and role checks: protects routes
- Statistics routes → Dashboard metrics: dispatches
- Account handling → Data operations: queries users
- Appointment handling → Data operations: manages appointments
- Clinical records → Data operations: manages records
- Dashboard metrics → Data operations: loads metrics
- Data operations → User model: reads and writes
- Data operations → Appointment model: reads and writes
- Data operations → Medical record model: reads and writes
- User model → MongoDB: persists
- Appointment model → MongoDB: persists
- Medical record model → MongoDB: persists
