# immanuellangat/daima-hms architecture

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

- Interactive diagram: https://gitdiagram.com/immanuellangat/daima-hms
- Repository: https://github.com/immanuellangat/daima-hms

## Overview

DAIMA Health is a hospital management system centered on a shared patient record. Staff workflows span reception and triage into consultation, diagnostic services and pharmacy, then billing; appointment booking and the patient portal are parallel entry points. Admin features cover analytics, audit, inventory and backups, while a scheduled worker handles reminders, alerts, queued notifications and cloud backups. The README documents these capabilities; unsampled implementation links are omitted or marked unverified.

Main entry points: [`src/app/(app)/consultation/[visitId]/page.tsx`](https://github.com/immanuellangat/daima-hms/blob/main/src/app/(app)/consultation/%5BvisitId%5D/page.tsx) (Consultation), [`src/lib/supabase/server.ts`](https://github.com/immanuellangat/daima-hms/blob/main/src/lib/supabase/server.ts) (Supabase database), [`src/app/(app)/admin`](https://github.com/immanuellangat/daima-hms/tree/main/src/app/(app)/admin) (Administration), [`src/app/api/cron/daily/route.ts`](https://github.com/immanuellangat/daima-hms/blob/main/src/app/api/cron/daily/route.ts) (Daily worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_care["Patient care"]
  node_reception["Reception"]
  node_triage["Triage"]
  node_consult["Consultation<br/>[page.tsx]"]
  node_clinical_rules["Clinical support<br/>[clinical.ts]"]
  node_lab["Laboratory<br/>[page.tsx]"]
  node_imaging["Imaging<br/>[page.tsx]"]
  node_patient_records["Patient records<br/>[emr.ts]"]
  node_consult_actions["Consultation actions<br/>[consultation.ts]"]
  node_lab_actions["Diagnostic actions<br/>[lab.ts]"]
end

subgraph group_ops["Appointments and access"]
  node_appointments["Appointments<br/>[page.tsx]"]
  node_public_booking["Public booking<br/>[page.tsx]"]
  node_booking_actions["Booking requests<br/>[booking.ts]"]
  node_patient_portal["Patient portal"]
end

subgraph group_finance["Pharmacy and billing"]
  node_pharmacy["Pharmacy<br/>[page.tsx]"]
  node_billing["Billing"]
  node_pharmacy_actions["Pharmacy actions<br/>[pharmacy.ts]"]
end

subgraph group_oversight["Administration"]
  node_admin["Administration"]
  node_analytics["Analytics<br/>[page.tsx]"]
  node_insights["Decision support<br/>[insights.ts]"]
  node_backup["Backup service<br/>[backup.ts]"]
  node_cron["Daily worker<br/>[route.ts]"]
  node_notifications["Notifications<br/>[notify.ts]"]
end

subgraph group_platform["Shared services"]
  node_auth["Authentication and roles<br/>[auth.ts]"]
  node_database[("Supabase database<br/>[server.ts]")]
  node_admin_client[("Privileged database client<br/>[admin.ts]")]
end

node_patient(("Patient"))
node_staff(("Hospital staff"))

node_staff -.->|"registers visits"| node_reception
node_reception -.->|"starts care"| node_triage
node_triage -.->|"passes assessment"| node_consult
node_consult -->|"checks clinical risks"| node_clinical_rules
node_consult -->|"loads history"| node_patient_records
node_consult -->|"submits care changes"| node_consult_actions
node_consult -.->|"requests tests"| node_lab
node_consult -.->|"requests imaging"| node_imaging
node_lab -->|"updates results"| node_lab_actions
node_imaging -->|"uses diagnostic actions"| node_lab_actions
node_consult -.->|"sends prescriptions"| node_pharmacy
node_pharmacy -->|"dispenses and adjusts"| node_pharmacy_actions
node_patient -->|"requests appointment"| node_public_booking
node_public_booking -.->|"submits request"| node_booking_actions
node_booking_actions -.->|"confirms requests"| node_appointments
node_patient -.->|"views own records"| node_patient_portal
node_appointments -->|"checks no-show risk"| node_insights
node_admin -->|"views reports"| node_analytics
node_analytics -->|"calculates trends"| node_insights
node_cron -->|"queries and updates"| node_admin_client
node_cron -->|"dispatches queue"| node_notifications
node_cron -->|"runs daily backup"| node_backup
node_consult_actions -->|"reads and writes"| node_database
node_lab_actions -->|"reads and writes"| node_database
node_pharmacy_actions -->|"reads and writes"| node_database
node_auth -->|"checks session and profile"| node_database
node_public_booking -->|"lists doctors"| node_database
node_admin -.->|"manages backups"| node_backup
node_patient_portal -.->|"reads patient data"| node_database
node_appointments -->|"loads schedules"| node_database
node_admin -.->|"manages hospital records"| node_database
node_backup -->|"uses privileged access"| node_admin_client
node_staff -.->|"signs in by role"| node_auth
node_patient -.->|"signs in"| node_auth

click node_reception "https://github.com/immanuellangat/daima-hms/tree/main/src/app/(app)/reception"
click node_triage "https://github.com/immanuellangat/daima-hms/tree/main/src/app/(app)/triage"
click node_consult "https://github.com/immanuellangat/daima-hms/blob/main/src/app/(app)/consultation/%5BvisitId%5D/page.tsx"
click node_clinical_rules "https://github.com/immanuellangat/daima-hms/blob/main/src/lib/clinical.ts"
click node_lab "https://github.com/immanuellangat/daima-hms/blob/main/src/app/(app)/laboratory/page.tsx"
click node_imaging "https://github.com/immanuellangat/daima-hms/blob/main/src/app/(app)/radiology/page.tsx"
click node_patient_records "https://github.com/immanuellangat/daima-hms/blob/main/src/lib/emr.ts"
click node_appointments "https://github.com/immanuellangat/daima-hms/blob/main/src/app/(app)/appointments/page.tsx"
click node_public_booking "https://github.com/immanuellangat/daima-hms/blob/main/src/app/book/page.tsx"
click node_booking_actions "https://github.com/immanuellangat/daima-hms/blob/main/src/app/actions/booking.ts"
click node_patient_portal "https://github.com/immanuellangat/daima-hms/tree/main/src/app/(app)/portal"
click node_pharmacy "https://github.com/immanuellangat/daima-hms/blob/main/src/app/(app)/pharmacy/page.tsx"
click node_billing "https://github.com/immanuellangat/daima-hms/tree/main/src/app/(app)/billing"
click node_admin "https://github.com/immanuellangat/daima-hms/tree/main/src/app/(app)/admin"
click node_analytics "https://github.com/immanuellangat/daima-hms/blob/main/src/app/(app)/admin/analytics/page.tsx"
click node_insights "https://github.com/immanuellangat/daima-hms/blob/main/src/lib/insights.ts"
click node_backup "https://github.com/immanuellangat/daima-hms/blob/main/src/lib/backup.ts"
click node_cron "https://github.com/immanuellangat/daima-hms/blob/main/src/app/api/cron/daily/route.ts"
click node_notifications "https://github.com/immanuellangat/daima-hms/blob/main/src/lib/notify.ts"
click node_auth "https://github.com/immanuellangat/daima-hms/blob/main/src/lib/auth.ts"
click node_database "https://github.com/immanuellangat/daima-hms/blob/main/src/lib/supabase/server.ts"
click node_admin_client "https://github.com/immanuellangat/daima-hms/blob/main/src/lib/supabase/admin.ts"
click node_consult_actions "https://github.com/immanuellangat/daima-hms/blob/main/src/app/actions/consultation.ts"
click node_lab_actions "https://github.com/immanuellangat/daima-hms/blob/main/src/app/actions/lab.ts"
click node_pharmacy_actions "https://github.com/immanuellangat/daima-hms/blob/main/src/app/actions/pharmacy.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_reception,node_triage,node_consult,node_clinical_rules,node_lab,node_imaging,node_patient_records,node_consult_actions,node_lab_actions toneBlue
class node_appointments,node_public_booking,node_booking_actions,node_patient_portal toneAmber
class node_pharmacy,node_billing,node_pharmacy_actions toneMint
class node_admin,node_analytics,node_insights,node_backup,node_cron,node_notifications toneRose
class node_auth,node_database,node_admin_client,node_patient,node_staff toneIndigo
```

## Components

### Patient care

- [Reception](https://github.com/immanuellangat/daima-hms/tree/main/src/app/(app)/reception): `src/app/(app)/reception`
- [Triage](https://github.com/immanuellangat/daima-hms/tree/main/src/app/(app)/triage): `src/app/(app)/triage`
- [Consultation](https://github.com/immanuellangat/daima-hms/blob/main/src/app/(app)/consultation/%5BvisitId%5D/page.tsx): `src/app/(app)/consultation/[visitId]/page.tsx`
- [Clinical support](https://github.com/immanuellangat/daima-hms/blob/main/src/lib/clinical.ts): `src/lib/clinical.ts`
- [Laboratory](https://github.com/immanuellangat/daima-hms/blob/main/src/app/(app)/laboratory/page.tsx): `src/app/(app)/laboratory/page.tsx`
- [Imaging](https://github.com/immanuellangat/daima-hms/blob/main/src/app/(app)/radiology/page.tsx): `src/app/(app)/radiology/page.tsx`
- [Patient records](https://github.com/immanuellangat/daima-hms/blob/main/src/lib/emr.ts): `src/lib/emr.ts`
- [Consultation actions](https://github.com/immanuellangat/daima-hms/blob/main/src/app/actions/consultation.ts): `src/app/actions/consultation.ts`
- [Diagnostic actions](https://github.com/immanuellangat/daima-hms/blob/main/src/app/actions/lab.ts): `src/app/actions/lab.ts`

### Appointments and access

- [Appointments](https://github.com/immanuellangat/daima-hms/blob/main/src/app/(app)/appointments/page.tsx): `src/app/(app)/appointments/page.tsx`
- [Public booking](https://github.com/immanuellangat/daima-hms/blob/main/src/app/book/page.tsx): `src/app/book/page.tsx`
- [Booking requests](https://github.com/immanuellangat/daima-hms/blob/main/src/app/actions/booking.ts): `src/app/actions/booking.ts`
- [Patient portal](https://github.com/immanuellangat/daima-hms/tree/main/src/app/(app)/portal): `src/app/(app)/portal`

### Pharmacy and billing

- [Pharmacy](https://github.com/immanuellangat/daima-hms/blob/main/src/app/(app)/pharmacy/page.tsx): `src/app/(app)/pharmacy/page.tsx`
- [Billing](https://github.com/immanuellangat/daima-hms/tree/main/src/app/(app)/billing): `src/app/(app)/billing`
- [Pharmacy actions](https://github.com/immanuellangat/daima-hms/blob/main/src/app/actions/pharmacy.ts): `src/app/actions/pharmacy.ts`

### Administration

- [Administration](https://github.com/immanuellangat/daima-hms/tree/main/src/app/(app)/admin): `src/app/(app)/admin`
- [Analytics](https://github.com/immanuellangat/daima-hms/blob/main/src/app/(app)/admin/analytics/page.tsx): `src/app/(app)/admin/analytics/page.tsx`
- [Decision support](https://github.com/immanuellangat/daima-hms/blob/main/src/lib/insights.ts): `src/lib/insights.ts`
- [Backup service](https://github.com/immanuellangat/daima-hms/blob/main/src/lib/backup.ts): `src/lib/backup.ts`
- [Daily worker](https://github.com/immanuellangat/daima-hms/blob/main/src/app/api/cron/daily/route.ts): `src/app/api/cron/daily/route.ts`
- [Notifications](https://github.com/immanuellangat/daima-hms/blob/main/src/lib/notify.ts): `src/lib/notify.ts`

### Shared services

- [Authentication and roles](https://github.com/immanuellangat/daima-hms/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [Supabase database](https://github.com/immanuellangat/daima-hms/blob/main/src/lib/supabase/server.ts): `src/lib/supabase/server.ts`
- [Privileged database client](https://github.com/immanuellangat/daima-hms/blob/main/src/lib/supabase/admin.ts): `src/lib/supabase/admin.ts`

### Other components

- **Patient**
- **Hospital staff**

## Connections

- Hospital staff → Reception: registers visits
- Reception → Triage: starts care
- Triage → Consultation: passes assessment
- Consultation → Clinical support: checks clinical risks (evidence: `src/app/(app)/consultation/[visitId]/page.tsx`)
- Consultation → Patient records: loads history (evidence: `src/app/(app)/consultation/[visitId]/page.tsx`)
- Consultation → Consultation actions: submits care changes (evidence: `src/app/(app)/consultation/[visitId]/page.tsx`)
- Consultation → Laboratory: requests tests
- Consultation → Imaging: requests imaging
- Laboratory → Diagnostic actions: updates results (evidence: `src/app/(app)/laboratory/page.tsx`)
- Imaging → Diagnostic actions: uses diagnostic actions (evidence: `src/app/(app)/radiology/page.tsx`)
- Consultation → Pharmacy: sends prescriptions
- Pharmacy → Pharmacy actions: dispenses and adjusts (evidence: `src/app/(app)/pharmacy/page.tsx`)
- Patient → Public booking: requests appointment (evidence: `src/app/book/page.tsx`)
- Public booking → Booking requests: submits request (evidence: `src/app/book/page.tsx`)
- Booking requests → Appointments: confirms requests
- Patient → Patient portal: views own records
- Appointments → Decision support: checks no-show risk (evidence: `src/app/(app)/appointments/page.tsx`)
- Administration → Analytics: views reports (evidence: `src/app/(app)/admin/analytics/page.tsx`)
- Analytics → Decision support: calculates trends (evidence: `src/app/(app)/admin/analytics/page.tsx`)
- Daily worker → Privileged database client: queries and updates (evidence: `src/app/api/cron/daily/route.ts`)
- Daily worker → Notifications: dispatches queue (evidence: `src/app/api/cron/daily/route.ts`)
- Daily worker → Backup service: runs daily backup (evidence: `src/app/api/cron/daily/route.ts`)
- Consultation actions → Supabase database: reads and writes (evidence: `src/app/actions/consultation.ts`)
- Diagnostic actions → Supabase database: reads and writes (evidence: `src/app/actions/lab.ts`)
- Pharmacy actions → Supabase database: reads and writes (evidence: `src/app/actions/pharmacy.ts`)
- Authentication and roles → Supabase database: checks session and profile (evidence: `src/lib/auth.ts`)
- Public booking → Supabase database: lists doctors (evidence: `src/app/book/page.tsx`)
- Administration → Backup service: manages backups
- Patient portal → Supabase database: reads patient data (evidence: `src/app/(app)/portal/page.tsx`)
- Appointments → Supabase database: loads schedules (evidence: `src/app/(app)/appointments/page.tsx`)
- Administration → Supabase database: manages hospital records (evidence: `src/app/(app)/admin/analytics/page.tsx`)
- Backup service → Privileged database client: uses privileged access (evidence: `src/lib/backup.ts`)
- Hospital staff → Authentication and roles: signs in by role
- Patient → Authentication and roles: signs in
