# ri-ya-dutta/medcore-hms architecture

> Architecture diagram of the GitHub repository ri-ya-dutta/medcore-hms, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ri-ya-dutta/medcore-hms
- Repository: https://github.com/ri-ya-dutta/medcore-hms

## Overview

MedCore HMS is a hospital-management REST backend. Hospital staff and patients use authenticated API routes for accounts and administration, patient records, and appointments; clinical records, vitals, prescriptions, lab operations, and invoices are also represented in the backend. Routes apply authentication and role checks before controllers handle requests, while services implement domain operations against PostgreSQL. The README describes the clinical sequence as planned; the sampled code confirms the API modules, but not calls between those clinical stages.

Main entry points: [`server/src/config/db.js`](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/config/db.js) (Database pool), [`server/src/app.js`](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/app.js) (Express API), [`server/src/controllers/authController.js`](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/controllers/authController.js) (Account controller), [`server/src/routes/adminRoutes.js`](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/routes/adminRoutes.js) (Admin routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_app["Express API<br/>[app.js]"]
  node_authroutes["Auth routes<br/>[authRoutes.js]"]
  node_authmw["Authentication and roles<br/>[authMiddleware.js]"]
  node_authctrl["Account controller<br/>[authController.js]"]
  node_authsvc["Account service<br/>[authService.js]"]
  node_jwt["JWT utilities<br/>[jwt.js]"]
  node_adminroutes["Admin routes<br/>[adminRoutes.js]"]
  node_adminctrl["Admin controller<br/>[adminController.js]"]
  node_adminsvc["Admin service<br/>[adminService.js]"]
end

subgraph group_people["People and scheduling"]
  node_patientroutes["Patient routes<br/>[patientRoutes.js]"]
  node_patientctrl["Patient controller"]
  node_patientsvc["Patient service<br/>[patientService.js]"]
  node_approutes["Appointment routes"]
  node_appctrl["Appointment controller"]
  node_appsvc["Appointment service"]
end

subgraph group_clinical["Clinical and billing"]
  node_encctrl["Encounter controller"]
  node_encsvc["Encounter service"]
  node_vitals["Vitals operations<br/>[vitalsService.js]"]
  node_prescriptions["Prescription operations"]
  node_laborders["Lab orders<br/>[labOrderService.js]"]
  node_labresults["Lab results"]
  node_invoices["Invoices and billing<br/>[invoiceService.js]"]
end

subgraph group_data["Persistence"]
  node_dbconfig["Database pool<br/>[db.js]"]
  node_postgres[("PostgreSQL<br/>[schema.sql]")]
end

node_users(("Hospital users"))

node_users -->|"send requests"| node_app
node_app -->|"mounts"| node_authroutes
node_app -->|"mounts"| node_adminroutes
node_app -->|"mounts"| node_patientroutes
node_app -->|"mounts"| node_approutes
node_app -->|"mounts encounter routes"| node_encctrl
node_authroutes -->|"routes to"| node_authctrl
node_adminroutes -->|"guards with"| node_authmw
node_adminroutes -->|"routes to"| node_adminctrl
node_patientroutes -->|"guards with"| node_authmw
node_patientroutes -->|"routes to"| node_patientctrl
node_approutes -->|"guards with"| node_authmw
node_approutes -->|"routes to"| node_appctrl
node_authctrl -->|"calls"| node_authsvc
node_authctrl -->|"creates tokens"| node_jwt
node_adminctrl -->|"calls"| node_adminsvc
node_patientctrl -->|"calls"| node_patientsvc
node_appctrl -->|"calls"| node_appsvc
node_encctrl -->|"calls"| node_encsvc
node_authsvc -->|"queries"| node_dbconfig
node_adminsvc -->|"queries"| node_dbconfig
node_patientsvc -->|"queries"| node_dbconfig
node_appsvc -->|"queries"| node_dbconfig
node_encsvc -->|"queries"| node_dbconfig
node_vitals -->|"queries"| node_dbconfig
node_prescriptions -->|"queries"| node_dbconfig
node_laborders -->|"queries"| node_dbconfig
node_labresults -->|"queries"| node_dbconfig
node_invoices -->|"queries"| node_dbconfig
node_dbconfig -.->|"connects to"| node_postgres

click node_app "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/app.js"
click node_authroutes "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/routes/authRoutes.js"
click node_authmw "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/middleware/authMiddleware.js"
click node_authctrl "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/controllers/authController.js"
click node_authsvc "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/authService.js"
click node_jwt "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/utils/jwt.js"
click node_adminroutes "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/routes/adminRoutes.js"
click node_adminctrl "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/controllers/adminController.js"
click node_adminsvc "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/adminService.js"
click node_patientroutes "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/routes/patientRoutes.js"
click node_patientctrl "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/controllers/patientController.js"
click node_patientsvc "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/patientService.js"
click node_approutes "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/routes/appointmentRoutes.js"
click node_appctrl "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/controllers/appointmentController.js"
click node_appsvc "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/appointmentService.js"
click node_encctrl "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/controllers/encounterController.js"
click node_encsvc "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/encounterService.js"
click node_vitals "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/vitalsService.js"
click node_prescriptions "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/prescriptionService.js"
click node_laborders "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/labOrderService.js"
click node_labresults "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/labResultService.js"
click node_invoices "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/invoiceService.js"
click node_dbconfig "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/config/db.js"
click node_postgres "https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/database/schema.sql"

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_authroutes,node_authmw,node_authctrl,node_authsvc,node_jwt,node_adminroutes,node_adminctrl,node_adminsvc,node_users toneBlue
class node_patientroutes,node_patientctrl,node_patientsvc,node_approutes,node_appctrl,node_appsvc toneAmber
class node_encctrl,node_encsvc,node_vitals,node_prescriptions,node_laborders,node_labresults,node_invoices toneMint
class node_dbconfig,node_postgres toneRose
```

## Components

### API and access

- [Express API](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/app.js): `server/src/app.js`
- [Auth routes](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/routes/authRoutes.js): `server/src/routes/authRoutes.js`
- [Authentication and roles](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/middleware/authMiddleware.js): `server/src/middleware/authMiddleware.js`
- [Account controller](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/controllers/authController.js): `server/src/controllers/authController.js`
- [Account service](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/authService.js): `server/src/services/authService.js`
- [JWT utilities](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/utils/jwt.js): `server/src/utils/jwt.js`
- [Admin routes](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/routes/adminRoutes.js): `server/src/routes/adminRoutes.js`
- [Admin controller](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/controllers/adminController.js): `server/src/controllers/adminController.js`
- [Admin service](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/adminService.js): `server/src/services/adminService.js`

### People and scheduling

- [Patient routes](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/routes/patientRoutes.js): `server/src/routes/patientRoutes.js`
- [Patient controller](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/controllers/patientController.js): `server/src/controllers/patientController.js`
- [Patient service](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/patientService.js): `server/src/services/patientService.js`
- [Appointment routes](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/routes/appointmentRoutes.js): `server/src/routes/appointmentRoutes.js`
- [Appointment controller](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/controllers/appointmentController.js): `server/src/controllers/appointmentController.js`
- [Appointment service](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/appointmentService.js): `server/src/services/appointmentService.js`

### Clinical and billing

- [Encounter controller](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/controllers/encounterController.js): `server/src/controllers/encounterController.js`
- [Encounter service](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/encounterService.js): `server/src/services/encounterService.js`
- [Vitals operations](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/vitalsService.js): `server/src/services/vitalsService.js`
- [Prescription operations](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/prescriptionService.js): `server/src/services/prescriptionService.js`
- [Lab orders](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/labOrderService.js): `server/src/services/labOrderService.js`
- [Lab results](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/labResultService.js): `server/src/services/labResultService.js`
- [Invoices and billing](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/services/invoiceService.js): `server/src/services/invoiceService.js`

### Persistence

- [Database pool](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/src/config/db.js): `server/src/config/db.js`
- [PostgreSQL](https://github.com/ri-ya-dutta/medcore-hms/blob/main/server/database/schema.sql): `server/database/schema.sql`

### Other components

- **Hospital users**

## Connections

- Hospital users → Express API: send requests (evidence: `README.md`)
- Express API → Auth routes: mounts (evidence: `server/src/app.js`)
- Express API → Admin routes: mounts (evidence: `server/src/app.js`)
- Express API → Patient routes: mounts (evidence: `server/src/app.js`)
- Express API → Appointment routes: mounts (evidence: `server/src/app.js`)
- Express API → Encounter controller: mounts encounter routes (evidence: `server/src/app.js`)
- Auth routes → Account controller: routes to (evidence: `server/src/routes/authRoutes.js`)
- Admin routes → Authentication and roles: guards with (evidence: `server/src/routes/adminRoutes.js`)
- Admin routes → Admin controller: routes to (evidence: `server/src/routes/adminRoutes.js`)
- Patient routes → Authentication and roles: guards with (evidence: `server/src/routes/patientRoutes.js`)
- Patient routes → Patient controller: routes to (evidence: `server/src/routes/patientRoutes.js`)
- Appointment routes → Authentication and roles: guards with (evidence: `server/src/routes/appointmentRoutes.js`)
- Appointment routes → Appointment controller: routes to (evidence: `server/src/routes/appointmentRoutes.js`)
- Account controller → Account service: calls (evidence: `server/src/controllers/authController.js`)
- Account controller → JWT utilities: creates tokens (evidence: `server/src/controllers/authController.js`)
- Admin controller → Admin service: calls (evidence: `server/src/controllers/adminController.js`)
- Patient controller → Patient service: calls (evidence: `server/src/controllers/patientController.js`)
- Appointment controller → Appointment service: calls (evidence: `server/src/controllers/appointmentController.js`)
- Encounter controller → Encounter service: calls (evidence: `server/src/controllers/encounterController.js`)
- Account service → Database pool: queries (evidence: `server/src/services/authService.js`)
- Admin service → Database pool: queries (evidence: `server/src/services/adminService.js`)
- Patient service → Database pool: queries (evidence: `server/src/services/patientService.js`)
- Appointment service → Database pool: queries (evidence: `server/src/services/appointmentService.js`)
- Encounter service → Database pool: queries (evidence: `server/src/services/encounterService.js`)
- Vitals operations → Database pool: queries (evidence: `server/src/services/vitalsService.js`)
- Prescription operations → Database pool: queries (evidence: `server/src/services/prescriptionService.js`)
- Lab orders → Database pool: queries (evidence: `server/src/services/labOrderService.js`)
- Lab results → Database pool: queries (evidence: `server/src/services/labResultService.js`)
- Invoices and billing → Database pool: queries (evidence: `server/src/services/invoiceService.js`)
- Database pool → PostgreSQL: connects to
