# sam-tituz/hospital-management-system architecture

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

- Interactive diagram: https://gitdiagram.com/sam-tituz/hospital-management-system
- Repository: https://github.com/sam-tituz/hospital-management-system

## Overview

Swasthya is a clinic-management application spanning a Next.js site and an Express API. Its visible clinical workflow covers staff sign-in, patient lookup or registration, consultation with medicine selection, and saving visits and prescriptions; the API also exposes doctor-scoped visit history. The sampled controllers confirm authentication, patient search/creation, medicine search, and visit persistence against shared database schemas. The README is a generic Turborepo starter and does not document product capabilities. Site actions, route aggregation, and most UI-to-API wiring were not sampled, so those relationships are left out.

Main entry points: [`apps/api/src/db.ts`](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/db.ts) (Database Client), [`apps/api/src/routes/patient.routes.ts`](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/routes/patient.routes.ts) (Patient Routes), [`apps/api/src/server.ts`](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/server.ts) (API Server), [`apps/api/src/controllers/patient.controller.ts`](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/controllers/patient.controller.ts) (Patient Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_site["Clinic Site"]
  node_signin["Sign In<br/>[page.tsx]"]
  node_dashboard["Dashboard<br/>[page.tsx]"]
  node_consult["Consultation<br/>[page.tsx]"]
  node_medui["Medicine Search UI<br/>[SearchMedicine.tsx]"]
end

subgraph group_api["API Services"]
  node_server["API Server<br/>[server.ts]"]
  node_routes["Route Aggregator<br/>[index.ts]"]
  node_patientroute["Patient Routes<br/>[patient.routes.ts]"]
  node_patientctl["Patient Service"]
  node_authctl["Authentication<br/>[auth.controller.ts]"]
  node_visitctl["Visit Service"]
  node_medicinectl["Medicine Search"]
end

subgraph group_data["Persistence"]
  node_db["Database Client<br/>[db.ts]"]
  node_schema["Clinical Schemas<br/>[index.ts]"]
end

subgraph group_shared["Shared Utilities"]
  node_middleware["Session Middleware"]
  node_retriever["Server Fetch<br/>[retriever.ts]"]
end

node_staff(("Clinic Staff"))

node_staff -->|"opens"| node_signin
node_staff -->|"uses"| node_dashboard
node_staff -->|"records visit"| node_consult
node_server -->|"mounts"| node_routes
node_patientroute -->|"dispatches"| node_patientctl
node_patientroute -->|"applies"| node_middleware
node_patientctl -->|"queries"| node_db
node_authctl -->|"queries"| node_db
node_visitctl -->|"reads and writes"| node_db
node_medicinectl -->|"searches"| node_db
node_db -->|"uses"| node_schema
node_retriever -.->|"fetches API"| node_server

click node_signin "https://github.com/sam-tituz/hospital-management-system/blob/main/apps/site/src/app/(onboarding)/auth/sign-in/page.tsx"
click node_dashboard "https://github.com/sam-tituz/hospital-management-system/blob/main/apps/site/src/app/(Frontend)/dashboard/page.tsx"
click node_consult "https://github.com/sam-tituz/hospital-management-system/blob/main/apps/site/src/app/(Frontend)/patients/%5BpatientId%5D/consult/page.tsx"
click node_medui "https://github.com/sam-tituz/hospital-management-system/blob/main/apps/site/src/app/(Frontend)/patients/%5BpatientId%5D/consult/components/SearchMedicine.tsx"
click node_server "https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/server.ts"
click node_routes "https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/routes/index.ts"
click node_patientroute "https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/routes/patient.routes.ts"
click node_patientctl "https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/controllers/patient.controller.ts"
click node_authctl "https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/controllers/auth.controller.ts"
click node_visitctl "https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/controllers/visit.controller.ts"
click node_medicinectl "https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/controllers/medicine.controller.ts"
click node_db "https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/db.ts"
click node_schema "https://github.com/sam-tituz/hospital-management-system/blob/main/lib/database/src/schema/index.ts"
click node_middleware "https://github.com/sam-tituz/hospital-management-system/blob/main/lib/utils/src/middlewares/authentication.middleware.ts"
click node_retriever "https://github.com/sam-tituz/hospital-management-system/blob/main/packages/utils/src/server/retriever.ts"

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_signin,node_dashboard,node_consult,node_medui toneBlue
class node_server,node_routes,node_patientroute,node_patientctl,node_authctl,node_visitctl,node_medicinectl toneAmber
class node_db,node_schema toneMint
class node_middleware,node_retriever toneRose
class node_staff toneIndigo
```

## Components

### Clinic Site

- [Sign In](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/site/src/app/(onboarding)/auth/sign-in/page.tsx): `apps/site/src/app/(onboarding)/auth/sign-in/page.tsx`
- [Dashboard](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/site/src/app/(Frontend)/dashboard/page.tsx): `apps/site/src/app/(Frontend)/dashboard/page.tsx`
- [Consultation](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/site/src/app/(Frontend)/patients/%5BpatientId%5D/consult/page.tsx): `apps/site/src/app/(Frontend)/patients/[patientId]/consult/page.tsx`
- [Medicine Search UI](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/site/src/app/(Frontend)/patients/%5BpatientId%5D/consult/components/SearchMedicine.tsx): `apps/site/src/app/(Frontend)/patients/[patientId]/consult/components/SearchMedicine.tsx`

### API Services

- [API Server](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/server.ts): `apps/api/src/server.ts`
- [Route Aggregator](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/routes/index.ts): `apps/api/src/routes/index.ts`
- [Patient Routes](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/routes/patient.routes.ts): `apps/api/src/routes/patient.routes.ts`
- [Patient Service](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/controllers/patient.controller.ts): `apps/api/src/controllers/patient.controller.ts`
- [Authentication](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/controllers/auth.controller.ts): `apps/api/src/controllers/auth.controller.ts`
- [Visit Service](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/controllers/visit.controller.ts): `apps/api/src/controllers/visit.controller.ts`
- [Medicine Search](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/controllers/medicine.controller.ts): `apps/api/src/controllers/medicine.controller.ts`

### Persistence

- [Database Client](https://github.com/sam-tituz/hospital-management-system/blob/main/apps/api/src/db.ts): `apps/api/src/db.ts`
- [Clinical Schemas](https://github.com/sam-tituz/hospital-management-system/blob/main/lib/database/src/schema/index.ts): `lib/database/src/schema/index.ts`

### Shared Utilities

- [Session Middleware](https://github.com/sam-tituz/hospital-management-system/blob/main/lib/utils/src/middlewares/authentication.middleware.ts): `lib/utils/src/middlewares/authentication.middleware.ts`
- [Server Fetch](https://github.com/sam-tituz/hospital-management-system/blob/main/packages/utils/src/server/retriever.ts): `packages/utils/src/server/retriever.ts`

### Other components

- **Clinic Staff**

## Connections

- Clinic Staff → Sign In: opens
- Clinic Staff → Dashboard: uses
- Clinic Staff → Consultation: records visit
- API Server → Route Aggregator: mounts
- Patient Routes → Patient Service: dispatches
- Patient Routes → Session Middleware: applies
- Patient Service → Database Client: queries
- Authentication → Database Client: queries
- Visit Service → Database Client: reads and writes
- Medicine Search → Database Client: searches
- Database Client → Clinical Schemas: uses
- Server Fetch → API Server: fetches API
