# virabhadrakhobare/smart-hospital-management architecture

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

- Interactive diagram: https://gitdiagram.com/virabhadrakhobare/smart-hospital-management
- Repository: https://github.com/virabhadrakhobare/smart-hospital-management

## Overview

#### Purpose and deployment shape
Hospital Management System monorepo: a React SPA consumes a Node/Express REST API backed by MongoDB/Mongoose. The frontend is independently deployable to Vercel (`client/vercel.json`); the API is configured through environment variables, including MongoDB, JWT secret, and permitted client origins (`server/.env.example`).

#### Entry points and application shell
Frontend bootstraps from `client/src/main.jsx` into the route/application composition in `client/src/App.jsx`. Shared authenticated UI is built around layout/navigation components such as `client/src/components/BaseLayout.jsx` and `client/src/components/Sidebar.jsx`. The backend process begins at `server/server.js`, which establishes database connectivity through `server/config/db.js` and mounts API routes.

#### Identity, access, and security boundary
Authentication state and client-side session handling are centralized in `client/src/context/AuthContext.jsx`; protected navigation is enforced by `client/src/components/ProtectedRoute.jsx` and `client/src/routes/ProtectedRoute.jsx`. Server auth endpoints live in `server/routes/authRoutes.js` and are implemented by `server/controllers/authController.js`. JWT verification and role authorization form the API boundary in `server/middleware/authMiddleware.js`; passwords use bcrypt, tokens expire after eight hours, and production can support HTTP-only token cookies.

#### API request pipeline
The SPA calls the API through the Axios layer at `client/src/services/api.js`, with role-oriented requests in `client/src/services/roleAPI.js`; `VITE_API_URL` selects the backend origin. Express routes delegate to controllers, then Mongoose models—for example `server/routes/patientRoutes.js`, `server/controllers/patientController.js`, and `server/models/Patient.js`. Validation, audit logging, and normalized error handling are cross-cutting middleware in `server/middleware/validateRequest.js`, `server/middleware/auditMiddleware.js`, and `server/middleware/errorHandler.js`.

#### Core hospital domains
Patient-centric clinical/operational records are represented by `server/models/Patient.js`, `server/models/Appointment.js`, and `server/models/Billing.js`, exposed through their corresponding route/controller layers. Primary operational views are `client/src/pages/Patients/PatientsPage.jsx`, `client/src/pages/Appointments/AppointmentsPage.jsx`, and `client/src/pages/Billing/BillingPage.jsx`; patient detail combines history across appointments, billing, and lab records at `client/src/pages/Patients/PatientDetailPage.jsx`.

#### Staffing, catalog, and inventory domains
User/role administration is modeled by `server/models/User.js`, `server/models/Role.js`, and `server/models/Permission.js`, with management UI at `client/src/pages/Users/UsersPage.jsx` and doctor operations at `client/src/pages/Doctors/DoctorsPage.jsx`. Hospital offerings and departments flow through `server/models/Service.js`, `server/models/Department.js`, and their route/controller APIs. Laboratory and pharmacy records are separate domains in `server/models/Laboratory.js` and `server/models/Pharmacy.js`, surfaced by `client/src/pages/Lab/LaboratoryPage.jsx` and `client/src/pages/Pharmacy/PharmacyPage.jsx`; pharmacy UI highlights low stock.

#### Reporting and data lifecycle
Dashboard aggregation is served by `server/routes/dashboardRoutes.js` and `server/controllers/dashboardController.js`, rendered in `client/src/pages/Dashboard/DashboardPage.jsx`. Seed scripts (`server/seed.js`, `server/seed-new.js`) establish initial data and demo admin access. MongoDB—typically Atlas in production—is the persistent system of record; API-level audit/activity models (`server/models/AuditLog.js`, `server/models/ActivityLog.js`) support traceability.

Main entry points: [`server/server.js`](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/server.js) (API process), [`client/src/App.jsx`](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/App.jsx) (App routes & shell), [`client/src/services/api.js`](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/services/api.js) (Axios API layer), [`client/src/pages/Patients/PatientsPage.jsx`](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/pages/Patients/PatientsPage.jsx) (Hospital operations views)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React SPA"]
  node_vercel{{"Vercel deployment<br/>hosting config<br/>[vercel.json]"}}
  node_spa_entry["SPA bootstrap<br/>React entry<br/>[main.jsx]"]
  node_app_shell["App routes &amp; shell<br/>React composition<br/>[App.jsx]"]
  node_auth_context["Auth session state<br/>React context<br/>[AuthContext.jsx]"]
  node_protected_routes["Protected navigation<br/>route guard<br/>[ProtectedRoute.jsx]"]
  node_hospital_views["Hospital operations views<br/>React pages<br/>[PatientsPage.jsx]"]
  node_patient_detail["Patient detail view<br/>React page"]
  node_dashboard["Dashboard view<br/>React page<br/>[DashboardPage.jsx]"]
  node_api_client["Axios API layer<br/>HTTP client<br/>[api.js]"]
end

subgraph group_api["Express API"]
  node_server_entry["API process<br/>Express entry<br/>[server.js]"]
  node_auth_routes["Auth endpoints<br/>Express routes<br/>[authRoutes.js]"]
  node_auth_controller["Authentication service<br/>controller<br/>[authController.js]"]
  node_security["JWT &amp; role boundary<br/>Express middleware<br/>[authMiddleware.js]"]
  node_api_crosscutting["Validation, audit &amp; errors<br/>Express middleware<br/>[validateRequest.js]"]
end

subgraph group_domains["Domain APIs"]
  node_patient_api["Patient API<br/>route/controller<br/>[patientRoutes.js]"]
  node_dashboard_api["Dashboard aggregation<br/>route/controller<br/>[dashboardRoutes.js]"]
  node_hospital_models["Hospital records<br/>Mongoose models<br/>[Patient.js]"]
  node_administration_models["Administration &amp; catalog<br/>Mongoose models<br/>[User.js]"]
end

subgraph group_data["Data &amp; Operations"]
  node_audit_models["Audit &amp; activity records<br/>Mongoose models<br/>[AuditLog.js]"]
  node_mongodb[("MongoDB / Atlas<br/>system of record")]
  node_db_connection["Database connection<br/>Mongoose config<br/>[db.js]"]
  node_seed_data["Seed data<br/>initialization script<br/>[seed.js]"]
  node_environment["Environment configuration<br/>runtime configuration<br/>[.env.example]"]
end

node_vercel -->|"deploys"| node_spa_entry
node_spa_entry -->|"renders"| node_app_shell
node_app_shell -->|"uses"| node_auth_context
node_app_shell -->|"guards routes with"| node_protected_routes
node_app_shell -->|"routes to"| node_hospital_views
node_hospital_views -->|"opens"| node_patient_detail
node_app_shell -->|"routes to"| node_dashboard
node_auth_context -->|"authenticates through"| node_api_client
node_hospital_views -->|"calls"| node_api_client
node_patient_detail -->|"loads history via"| node_api_client
node_dashboard -->|"loads aggregates via"| node_api_client
node_api_client -->|"REST requests"| node_server_entry
node_server_entry -->|"initializes"| node_db_connection
node_server_entry -->|"mounts"| node_auth_routes
node_server_entry -->|"mounts"| node_patient_api
node_server_entry -->|"mounts"| node_dashboard_api
node_server_entry -->|"enforces"| node_security
node_server_entry -->|"applies"| node_api_crosscutting
node_auth_routes -->|"delegates to"| node_auth_controller
node_auth_controller -->|"reads users and roles"| node_administration_models
node_patient_api -->|"reads and writes"| node_hospital_models
node_dashboard_api -->|"aggregates"| node_hospital_models
node_api_crosscutting -->|"records"| node_audit_models
node_hospital_models -->|"persists to"| node_mongodb
node_administration_models -->|"persists to"| node_mongodb
node_audit_models -->|"persists to"| node_mongodb
node_db_connection -->|"connects"| node_mongodb
node_seed_data -->|"initializes"| node_mongodb
node_environment -.->|"configures"| node_server_entry

click node_vercel "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/vercel.json"
click node_spa_entry "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/main.jsx"
click node_app_shell "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/App.jsx"
click node_auth_context "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/context/AuthContext.jsx"
click node_protected_routes "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/components/ProtectedRoute.jsx"
click node_hospital_views "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/pages/Patients/PatientsPage.jsx"
click node_patient_detail "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/pages/Patients/PatientDetailPage.jsx"
click node_dashboard "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/pages/Dashboard/DashboardPage.jsx"
click node_api_client "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/services/api.js"
click node_server_entry "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/server.js"
click node_auth_routes "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/routes/authRoutes.js"
click node_auth_controller "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/controllers/authController.js"
click node_security "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/middleware/authMiddleware.js"
click node_api_crosscutting "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/middleware/validateRequest.js"
click node_patient_api "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/routes/patientRoutes.js"
click node_dashboard_api "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/routes/dashboardRoutes.js"
click node_hospital_models "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/models/Patient.js"
click node_administration_models "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/models/User.js"
click node_audit_models "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/models/AuditLog.js"
click node_db_connection "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/config/db.js"
click node_seed_data "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/seed.js"
click node_environment "https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/.env.example"

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_vercel,node_spa_entry,node_app_shell,node_auth_context,node_protected_routes,node_hospital_views,node_patient_detail,node_dashboard,node_api_client toneBlue
class node_server_entry,node_auth_routes,node_auth_controller,node_security,node_api_crosscutting toneAmber
class node_patient_api,node_dashboard_api,node_hospital_models,node_administration_models toneMint
class node_audit_models,node_mongodb,node_db_connection,node_seed_data,node_environment toneRose
```

## Components

### React SPA

- [Vercel deployment](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/vercel.json): hosting config · Independently deploys the SPA. · `client/vercel.json`
- [SPA bootstrap](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/main.jsx): React entry · `client/src/main.jsx`
- [App routes & shell](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/App.jsx): React composition · Composes routes and shared authenticated layout. · `client/src/App.jsx`
- [Auth session state](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/context/AuthContext.jsx): React context · `client/src/context/AuthContext.jsx`
- [Protected navigation](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/components/ProtectedRoute.jsx): route guard · `client/src/components/ProtectedRoute.jsx`
- [Hospital operations views](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/pages/Patients/PatientsPage.jsx): React pages · Patients, appointments, billing, lab, pharmacy, users, and doctors. · `client/src/pages/Patients/PatientsPage.jsx`
- [Patient detail view](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/pages/Patients/PatientDetailPage.jsx): React page · Combines appointment, billing, and lab history. · `client/src/pages/Patients/PatientDetailPage.jsx`
- [Dashboard view](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/pages/Dashboard/DashboardPage.jsx): React page · `client/src/pages/Dashboard/DashboardPage.jsx`
- [Axios API layer](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/client/src/services/api.js): HTTP client · Uses VITE_API_URL and role-oriented requests. · `client/src/services/api.js`

### Express API

- [API process](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/server.js): Express entry · Connects MongoDB and mounts API routes. · `server/server.js`
- [Auth endpoints](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/routes/authRoutes.js): Express routes · `server/routes/authRoutes.js`
- [Authentication service](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/controllers/authController.js): controller · Bcrypt credentials and eight-hour JWT issuance. · `server/controllers/authController.js`
- [JWT & role boundary](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/middleware/authMiddleware.js): Express middleware · Verifies tokens and authorizes roles. · `server/middleware/authMiddleware.js`
- [Validation, audit & errors](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/middleware/validateRequest.js): Express middleware · Validates requests, records audit activity, and normalizes errors. · `server/middleware/validateRequest.js`

### Domain APIs

- [Patient API](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/routes/patientRoutes.js): route/controller · Patient CRUD and clinical record access. · `server/routes/patientRoutes.js`
- [Dashboard aggregation](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/routes/dashboardRoutes.js): route/controller · `server/routes/dashboardRoutes.js`
- [Hospital records](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/models/Patient.js): Mongoose models · Patient, appointment, billing, laboratory, and pharmacy records. · `server/models/Patient.js`
- [Administration & catalog](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/models/User.js): Mongoose models · Users, roles, permissions, services, and departments. · `server/models/User.js`

### Data & Operations

- [Audit & activity records](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/models/AuditLog.js): Mongoose models · Traceability for API activity. · `server/models/AuditLog.js`
- **MongoDB / Atlas**: system of record
- [Database connection](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/config/db.js): Mongoose config · `server/config/db.js`
- [Seed data](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/seed.js): initialization script · Creates initial data and demo admin access. · `server/seed.js`
- [Environment configuration](https://github.com/virabhadrakhobare/smart-hospital-management/blob/main/server/.env.example): runtime configuration · Supplies MongoDB, JWT secret, and allowed client origins. · `server/.env.example`

## Connections

- Vercel deployment → SPA bootstrap: deploys
- SPA bootstrap → App routes & shell: renders
- App routes & shell → Auth session state: uses
- App routes & shell → Protected navigation: guards routes with
- App routes & shell → Hospital operations views: routes to
- Hospital operations views → Patient detail view: opens
- App routes & shell → Dashboard view: routes to
- Auth session state → Axios API layer: authenticates through
- Hospital operations views → Axios API layer: calls
- Patient detail view → Axios API layer: loads history via
- Dashboard view → Axios API layer: loads aggregates via
- Axios API layer → API process: REST requests
- API process → Database connection: initializes
- API process → Auth endpoints: mounts
- API process → Patient API: mounts
- API process → Dashboard aggregation: mounts
- API process → JWT & role boundary: enforces
- API process → Validation, audit & errors: applies
- Auth endpoints → Authentication service: delegates to
- Authentication service → Administration & catalog: reads users and roles
- Patient API → Hospital records: reads and writes
- Dashboard aggregation → Hospital records: aggregates
- Validation, audit & errors → Audit & activity records: records
- Hospital records → MongoDB / Atlas: persists to
- Administration & catalog → MongoDB / Atlas: persists to
- Audit & activity records → MongoDB / Atlas: persists to
- Database connection → MongoDB / Atlas: connects
- Seed data → MongoDB / Atlas: initializes
- Environment configuration → API process: configures
