# christinaprado/open-health-stack architecture

> Architecture diagram of the GitHub repository christinaprado/open-health-stack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/christinaprado/open-health-stack
- Repository: https://github.com/christinaprado/open-health-stack

## Overview

PHOHSP is an offline-first community health records app for Philippine health workers and patients. Users register households and patients, record or review clinical information, and use patient-portal features such as appointment requests, home readings, referrals, and encrypted summary sharing. Records are stored locally first; the sync worker sends patient records through OpenHIM toward OpenCR and other FHIR resources toward HAPI FHIR. The README documents the major capabilities and integrations; source excerpts confirm local persistence and sync behavior, but most feature-specific wiring was not sampled.

Main entry points: [`src/app`](https://github.com/christinaprado/open-health-stack/tree/main/src/app) (Mobile app), [`src/db/resourceRepository.ts`](https://github.com/christinaprado/open-health-stack/blob/main/src/db/resourceRepository.ts) (FHIR resource repository), [`src/fhir`](https://github.com/christinaprado/open-health-stack/tree/main/src/fhir) (FHIR clinical services), [`src/sync/syncWorker.ts`](https://github.com/christinaprado/open-health-stack/blob/main/src/sync/syncWorker.ts) (Sync worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile experience"]
  node_app["Mobile app"]
  node_household["Household registration"]
  node_patientreg["Patient registration"]
  node_patientportal["Patient portal"]
  node_appointments["Appointments<br/>[appointments.tsx]"]
  node_chatbot["Chatbot<br/>[engine.ts]"]
end

subgraph group_clinical["Clinical records"]
  node_clinicalcapture["Clinical capture"]
  node_clinicalservices["FHIR clinical services"]
  node_patientrecord["Patient records<br/>[patientRecord.ts]"]
  node_ips["Patient summary<br/>[ipsService.ts]"]
  node_provenance["Integrity provenance"]
  node_terminology["Terminology coding"]
end

subgraph group_offline["Offline data and sync"]
  node_localdb[("SQLite database<br/>[database.ts]")]
  node_resources["FHIR resource repository"]
  node_queue["Sync queue<br/>[syncQueue.ts]"]
  node_syncworker["Sync worker<br/>[syncWorker.ts]"]
end

subgraph group_interop["Interoperability"]
  node_openhim{{"OpenHIM router"}}
  node_opencr[("OpenCR MPI")]
  node_hapi[("HAPI FHIR")]
end

subgraph group_identity["Identity and sharing"]
  node_supabase[("Supabase auth and sharing<br/>[supabase.ts]")]
  node_shl["Smart Health Links<br/>[smartHealthLink.ts]"]
end

node_worker(("Health worker"))
node_patient(("Patient"))
node_doctor(("Doctor"))

node_worker -->|"uses"| node_app
node_patient -->|"uses"| node_app
node_app -->|"registers"| node_household
node_app -->|"registers"| node_patientreg
node_app -->|"records care"| node_clinicalcapture
node_app -->|"views portal"| node_patientportal
node_app -->|"manages requests"| node_appointments
node_app -->|"asks questions"| node_chatbot
node_clinicalcapture -->|"creates records"| node_clinicalservices
node_clinicalservices -->|"saves resources"| node_resources
node_patientrecord -->|"reads resources"| node_resources
node_ips -->|"reads records"| node_resources
node_ips -->|"checks integrity"| node_provenance
node_clinicalservices -->|"codes concepts"| node_terminology
node_resources -->|"reads and writes"| node_localdb
node_clinicalservices -->|"queues changes"| node_queue
node_syncworker -->|"processes items"| node_queue
node_syncworker -->|"reads and marks"| node_resources
node_syncworker -->|"sends FHIR"| node_openhim
node_openhim -->|"routes patients"| node_opencr
node_openhim -->|"routes clinical data"| node_hapi
node_app -->|"authenticates"| node_supabase
node_patientportal -->|"shares summary"| node_shl
node_shl -->|"stores encrypted file"| node_supabase
node_doctor -->|"receives summary"| node_shl

click node_app "https://github.com/christinaprado/open-health-stack/tree/main/src/app"
click node_household "https://github.com/christinaprado/open-health-stack/blob/main/src/app/register-household.tsx"
click node_patientreg "https://github.com/christinaprado/open-health-stack/blob/main/src/app/register-patient.tsx"
click node_patientportal "https://github.com/christinaprado/open-health-stack/blob/main/src/components/patient/PatientPortalHome.tsx"
click node_appointments "https://github.com/christinaprado/open-health-stack/blob/main/src/app/appointments.tsx"
click node_chatbot "https://github.com/christinaprado/open-health-stack/blob/main/src/chatbot/engine.ts"
click node_clinicalcapture "https://github.com/christinaprado/open-health-stack/tree/main/src/app"
click node_clinicalservices "https://github.com/christinaprado/open-health-stack/tree/main/src/fhir"
click node_patientrecord "https://github.com/christinaprado/open-health-stack/blob/main/src/fhir/patientRecord.ts"
click node_ips "https://github.com/christinaprado/open-health-stack/blob/main/src/fhir/ipsService.ts"
click node_provenance "https://github.com/christinaprado/open-health-stack/blob/main/src/fhir/provenanceService.ts"
click node_terminology "https://github.com/christinaprado/open-health-stack/tree/main/src/terminology"
click node_localdb "https://github.com/christinaprado/open-health-stack/blob/main/src/db/database.ts"
click node_resources "https://github.com/christinaprado/open-health-stack/blob/main/src/db/resourceRepository.ts"
click node_queue "https://github.com/christinaprado/open-health-stack/blob/main/src/sync/syncQueue.ts"
click node_syncworker "https://github.com/christinaprado/open-health-stack/blob/main/src/sync/syncWorker.ts"
click node_supabase "https://github.com/christinaprado/open-health-stack/blob/main/src/lib/supabase.ts"
click node_shl "https://github.com/christinaprado/open-health-stack/blob/main/src/shl/smartHealthLink.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_app,node_household,node_patientreg,node_patientportal,node_appointments,node_chatbot toneBlue
class node_clinicalcapture,node_clinicalservices,node_patientrecord,node_ips,node_provenance,node_terminology toneAmber
class node_localdb,node_resources,node_queue,node_syncworker toneMint
class node_openhim,node_opencr,node_hapi,node_worker toneRose
class node_supabase,node_shl,node_patient,node_doctor toneIndigo
```

## Components

### Mobile experience

- [Mobile app](https://github.com/christinaprado/open-health-stack/tree/main/src/app): `src/app`
- [Household registration](https://github.com/christinaprado/open-health-stack/blob/main/src/app/register-household.tsx): `src/app/register-household.tsx`
- [Patient registration](https://github.com/christinaprado/open-health-stack/blob/main/src/app/register-patient.tsx): `src/app/register-patient.tsx`
- [Patient portal](https://github.com/christinaprado/open-health-stack/blob/main/src/components/patient/PatientPortalHome.tsx): `src/components/patient/PatientPortalHome.tsx`
- [Appointments](https://github.com/christinaprado/open-health-stack/blob/main/src/app/appointments.tsx): `src/app/appointments.tsx`
- [Chatbot](https://github.com/christinaprado/open-health-stack/blob/main/src/chatbot/engine.ts): `src/chatbot/engine.ts`

### Clinical records

- [Clinical capture](https://github.com/christinaprado/open-health-stack/tree/main/src/app): `src/app`
- [FHIR clinical services](https://github.com/christinaprado/open-health-stack/tree/main/src/fhir): `src/fhir`
- [Patient records](https://github.com/christinaprado/open-health-stack/blob/main/src/fhir/patientRecord.ts): `src/fhir/patientRecord.ts`
- [Patient summary](https://github.com/christinaprado/open-health-stack/blob/main/src/fhir/ipsService.ts): `src/fhir/ipsService.ts`
- [Integrity provenance](https://github.com/christinaprado/open-health-stack/blob/main/src/fhir/provenanceService.ts): `src/fhir/provenanceService.ts`
- [Terminology coding](https://github.com/christinaprado/open-health-stack/tree/main/src/terminology): `src/terminology`

### Offline data and sync

- [SQLite database](https://github.com/christinaprado/open-health-stack/blob/main/src/db/database.ts): `src/db/database.ts`
- [FHIR resource repository](https://github.com/christinaprado/open-health-stack/blob/main/src/db/resourceRepository.ts): `src/db/resourceRepository.ts`
- [Sync queue](https://github.com/christinaprado/open-health-stack/blob/main/src/sync/syncQueue.ts): `src/sync/syncQueue.ts`
- [Sync worker](https://github.com/christinaprado/open-health-stack/blob/main/src/sync/syncWorker.ts): `src/sync/syncWorker.ts`

### Interoperability

- **OpenHIM router**
- **OpenCR MPI**
- **HAPI FHIR**

### Identity and sharing

- [Supabase auth and sharing](https://github.com/christinaprado/open-health-stack/blob/main/src/lib/supabase.ts): `src/lib/supabase.ts`
- [Smart Health Links](https://github.com/christinaprado/open-health-stack/blob/main/src/shl/smartHealthLink.ts): `src/shl/smartHealthLink.ts`

### Other components

- **Health worker**
- **Patient**
- **Doctor**

## Connections

- Health worker → Mobile app: uses
- Patient → Mobile app: uses
- Mobile app → Household registration: registers
- Mobile app → Patient registration: registers
- Mobile app → Clinical capture: records care
- Mobile app → Patient portal: views portal
- Mobile app → Appointments: manages requests
- Mobile app → Chatbot: asks questions
- Clinical capture → FHIR clinical services: creates records
- FHIR clinical services → FHIR resource repository: saves resources
- Patient records → FHIR resource repository: reads resources
- Patient summary → FHIR resource repository: reads records
- Patient summary → Integrity provenance: checks integrity
- FHIR clinical services → Terminology coding: codes concepts
- FHIR resource repository → SQLite database: reads and writes
- FHIR clinical services → Sync queue: queues changes
- Sync worker → Sync queue: processes items
- Sync worker → FHIR resource repository: reads and marks
- Sync worker → OpenHIM router: sends FHIR
- OpenHIM router → OpenCR MPI: routes patients
- OpenHIM router → HAPI FHIR: routes clinical data
- Mobile app → Supabase auth and sharing: authenticates
- Patient portal → Smart Health Links: shares summary
- Smart Health Links → Supabase auth and sharing: stores encrypted file
- Doctor → Smart Health Links: receives summary
