How virabhadrakhobare/smart-hospital-management works
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.js API process · App.jsx App routes & shell · api.js Axios API layer · PatientsPage.jsx Hospital operations views
Components 23
React SPA
- Vercel deployment · Independently deploys the SPA.
client/vercel.json - SPA bootstrap
client/src/main.jsx - App routes & shell · Composes routes and shared authenticated layout.
client/src/App.jsx - Auth session state
client/src/context/AuthContext.jsx - Protected navigation
client/src/components/ProtectedRoute.jsx - Hospital operations views · Patients, appointments, billing, lab, pharmacy, users, and doctors.
client/src/pages/Patients/PatientsPage.jsx - Patient detail view · Combines appointment, billing, and lab history.
client/src/pages/Patients/PatientDetailPage.jsx - Dashboard view
client/src/pages/Dashboard/DashboardPage.jsx - Axios API layer · Uses VITE_API_URL and role-oriented requests.
client/src/services/api.js
Express API
- API process · Connects MongoDB and mounts API routes.
server/server.js - Auth endpoints
server/routes/authRoutes.js - Authentication service · Bcrypt credentials and eight-hour JWT issuance.
server/controllers/authController.js - JWT & role boundary · Verifies tokens and authorizes roles.
server/middleware/authMiddleware.js - Validation, audit & errors · Validates requests, records audit activity, and normalizes errors.
server/middleware/validateRequest.js
Domain APIs
- Patient API · Patient CRUD and clinical record access.
server/routes/patientRoutes.js - Dashboard aggregation
server/routes/dashboardRoutes.js - Hospital records · Patient, appointment, billing, laboratory, and pharmacy records.
server/models/Patient.js - Administration & catalog · Users, roles, permissions, services, and departments.
server/models/User.js
Data & Operations
- Audit & activity records · Traceability for API activity.
server/models/AuditLog.js - MongoDB / Atlas
- Database connection
server/config/db.js - Seed data · Creates initial data and demo admin access.
server/seed.js - Environment configuration · Supplies MongoDB, JWT secret, and allowed client origins.
server/.env.example
Connections 29
- 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