# kaloyandjunow-prog/lospor-hospital architecture

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

- Interactive diagram: https://gitdiagram.com/kaloyandjunow-prog/lospor-hospital
- Repository: https://github.com/kaloyandjunow-prog/lospor-hospital

## Overview

LOSPOR Hospital is a self-hosted clinical platform for one institution. Clinicians use its web and PWA clients to create and maintain clinical cases; the API stores them locally and supports clinical workflows. Separate branches provide research browsing and policy-gated OMOP delivery, hospital/EHR exchange, and an independently authenticated appliance Status monitor. The README documents the product capabilities; sampled source confirms selected case, autosave, and Status relationships. Many subsystem links are documented at product level rather than verified in sampled implementation.

Main entry points: [`apps/status/src/app.ts`](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/app.ts) (Status application), [`apps/api/src/app/v1/cases`](https://github.com/kaloyandjunow-prog/lospor-hospital/tree/main/apps/api/src/app/v1/cases) (Clinical API), [`apps/status/src/go-live.ts`](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/go-live.ts) (Go-live readiness), [`apps/pwa/src`](https://github.com/kaloyandjunow-prog/lospor-hospital/tree/main/apps/pwa/src) (PWA client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clinical["Clinical platform"]
  node_web["Web client"]
  node_pwa["PWA client"]
  node_api["Clinical API"]
  node_case_record[("Clinical cases<br/>[route.ts]")]
  node_preop["Preop mapping<br/>[preop.ts]"]
  node_intraop["Intraop mapping<br/>[intraop.ts]"]
  node_postop["Postop mapping<br/>[postop.ts]"]
  node_autosave["Offline autosave"]
  node_ai["Clinical AI<br/>[ai-advisor.ts]"]
end

subgraph group_research["Research and exports"]
  node_research_browser["Research Browser"]
  node_research_api["Research services<br/>[service.ts]"]
  node_omop["OMOP export<br/>[omop-mapper.ts]"]
end

subgraph group_hospital["Hospital integration"]
  node_ehr_import["EHR import<br/>[ehr-import.ts]"]
  node_delivery["Policy-gated delivery<br/>[export-batch.ts]"]
  node_patient_link["Patient linkage<br/>[patient-link.ts]"]
  node_ehr_delivery["EHR delivery<br/>[ehr-delivery.ts]"]
end

subgraph group_status["Appliance Status"]
  node_status_app["Status application<br/>[app.ts]"]
  node_status_auth["Status authentication<br/>[auth.ts]"]
  node_status_db[("Status data store<br/>[db.ts]")]
  node_status_ui["Status interface<br/>[ui.ts]"]
  node_status_go_live["Go-live readiness<br/>[go-live.ts]"]
  node_status_attention["Operational attention<br/>[attention.ts]"]
  node_status_host["Host observations<br/>[host-os.ts]"]
  node_status_signals["Operational signals<br/>[signals.ts]"]
  node_status_maintenance["Maintenance<br/>[maintenance.ts]"]
  node_status_updates["Update requests<br/>[update-requests.ts]"]
  node_status_control["Control plane<br/>[control-plane.ts]"]
  node_status_accounts["Account control<br/>[account-control.ts]"]
  node_status_locale["Localization<br/>[locale.ts]"]
end

node_clinician(("Clinician"))
node_status_admin(("Appliance administrator"))

node_clinician -->|"uses"| node_web
node_clinician -->|"uses"| node_pwa
node_web -.->|"requests clinical services"| node_api
node_pwa -.->|"requests clinical services"| node_api
node_pwa -->|"saves offline"| node_autosave
node_autosave -->|"sends case updates"| node_api
node_api -->|"reads and writes"| node_case_record
node_api -->|"maps preop"| node_preop
node_api -->|"maps intraop"| node_intraop
node_api -->|"maps postop"| node_postop
node_api -.->|"imports records"| node_ehr_import
node_api -.->|"provides advice"| node_ai
node_research_browser -.->|"queries research"| node_research_api
node_research_api -.->|"maps clinical data"| node_omop
node_omop -.->|"packages exports"| node_delivery
node_case_record -.->|"supports encrypted linkage"| node_patient_link
node_case_record -.->|"supports hospital exchange"| node_ehr_delivery
node_status_admin -->|"administers appliance"| node_status_app
node_status_app -->|"authenticates sessions"| node_status_auth
node_status_app -->|"renders pages"| node_status_ui
node_status_app -->|"stores events"| node_status_db
node_status_app -->|"localizes responses"| node_status_locale
node_status_auth -->|"persists credentials"| node_status_db
node_status_app -.->|"presents operations"| node_status_attention
node_status_app -.->|"presents readiness"| node_status_go_live
node_status_go_live -->|"assesses host state"| node_status_host
node_status_go_live -->|"assesses signals"| node_status_signals
node_status_go_live -->|"assesses maintenance"| node_status_maintenance
node_status_attention -->|"uses observations"| node_status_host
node_status_attention -->|"uses maintenance state"| node_status_maintenance
node_status_app -.->|"serves controls"| node_status_control
node_status_app -.->|"serves account controls"| node_status_accounts
node_status_app -.->|"serves update requests"| node_status_updates

click node_web "https://github.com/kaloyandjunow-prog/lospor-hospital/tree/main/apps/web/src"
click node_pwa "https://github.com/kaloyandjunow-prog/lospor-hospital/tree/main/apps/pwa/src"
click node_api "https://github.com/kaloyandjunow-prog/lospor-hospital/tree/main/apps/api/src/app/v1/cases"
click node_case_record "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/app/v1/cases/%5Bid%5D/route.ts"
click node_preop "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/app/v1/cases/_mappers/preop.ts"
click node_intraop "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/app/v1/cases/_mappers/intraop.ts"
click node_postop "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/app/v1/cases/_mappers/postop.ts"
click node_autosave "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/pwa/src/lib/autosave-manager.ts"
click node_ehr_import "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/hospital/ehr-import.ts"
click node_ai "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/ai-advisor.ts"
click node_research_browser "https://github.com/kaloyandjunow-prog/lospor-hospital/tree/main/apps/browser/src/app/(workspace)"
click node_research_api "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/research/service.ts"
click node_omop "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/omop-mapper.ts"
click node_delivery "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/hospital/export-batch.ts"
click node_patient_link "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/hospital/patient-link.ts"
click node_ehr_delivery "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/hospital/ehr-delivery.ts"
click node_status_app "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/app.ts"
click node_status_auth "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/auth.ts"
click node_status_db "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/db.ts"
click node_status_ui "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/ui.ts"
click node_status_go_live "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/go-live.ts"
click node_status_attention "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/attention.ts"
click node_status_host "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/host-os.ts"
click node_status_signals "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/signals.ts"
click node_status_maintenance "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/maintenance.ts"
click node_status_updates "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/update-requests.ts"
click node_status_control "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/control-plane.ts"
click node_status_accounts "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/account-control.ts"
click node_status_locale "https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/locale.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_web,node_pwa,node_api,node_case_record,node_preop,node_intraop,node_postop,node_autosave,node_ai toneBlue
class node_research_browser,node_research_api,node_omop toneAmber
class node_ehr_import,node_delivery,node_patient_link,node_ehr_delivery toneMint
class node_status_app,node_status_auth,node_status_db,node_status_ui,node_status_go_live,node_status_attention,node_status_host,node_status_signals,node_status_maintenance,node_status_updates,node_status_control,node_status_accounts,node_status_locale toneRose
class node_clinician,node_status_admin toneIndigo
```

## Components

### Clinical platform

- [Web client](https://github.com/kaloyandjunow-prog/lospor-hospital/tree/main/apps/web/src): `apps/web/src`
- [PWA client](https://github.com/kaloyandjunow-prog/lospor-hospital/tree/main/apps/pwa/src): `apps/pwa/src`
- [Clinical API](https://github.com/kaloyandjunow-prog/lospor-hospital/tree/main/apps/api/src/app/v1/cases): `apps/api/src/app/v1/cases`
- [Clinical cases](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/app/v1/cases/%5Bid%5D/route.ts): `apps/api/src/app/v1/cases/[id]/route.ts`
- [Preop mapping](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/app/v1/cases/_mappers/preop.ts): `apps/api/src/app/v1/cases/_mappers/preop.ts`
- [Intraop mapping](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/app/v1/cases/_mappers/intraop.ts): `apps/api/src/app/v1/cases/_mappers/intraop.ts`
- [Postop mapping](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/app/v1/cases/_mappers/postop.ts): `apps/api/src/app/v1/cases/_mappers/postop.ts`
- [Offline autosave](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/pwa/src/lib/autosave-manager.ts): `apps/pwa/src/lib/autosave-manager.ts`
- [Clinical AI](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/ai-advisor.ts): `apps/api/src/lib/ai-advisor.ts`

### Research and exports

- [Research Browser](https://github.com/kaloyandjunow-prog/lospor-hospital/tree/main/apps/browser/src/app/(workspace)): `apps/browser/src/app/(workspace)`
- [Research services](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/research/service.ts): `apps/api/src/lib/research/service.ts`
- [OMOP export](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/omop-mapper.ts): `apps/api/src/lib/omop-mapper.ts`

### Hospital integration

- [EHR import](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/hospital/ehr-import.ts): `apps/api/src/lib/hospital/ehr-import.ts`
- [Policy-gated delivery](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/hospital/export-batch.ts): `apps/api/src/lib/hospital/export-batch.ts`
- [Patient linkage](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/hospital/patient-link.ts): `apps/api/src/lib/hospital/patient-link.ts`
- [EHR delivery](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/api/src/lib/hospital/ehr-delivery.ts): `apps/api/src/lib/hospital/ehr-delivery.ts`

### Appliance Status

- [Status application](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/app.ts): `apps/status/src/app.ts`
- [Status authentication](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/auth.ts): `apps/status/src/auth.ts`
- [Status data store](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/db.ts): `apps/status/src/db.ts`
- [Status interface](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/ui.ts): `apps/status/src/ui.ts`
- [Go-live readiness](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/go-live.ts): `apps/status/src/go-live.ts`
- [Operational attention](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/attention.ts): `apps/status/src/attention.ts`
- [Host observations](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/host-os.ts): `apps/status/src/host-os.ts`
- [Operational signals](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/signals.ts): `apps/status/src/signals.ts`
- [Maintenance](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/maintenance.ts): `apps/status/src/maintenance.ts`
- [Update requests](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/update-requests.ts): `apps/status/src/update-requests.ts`
- [Control plane](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/control-plane.ts): `apps/status/src/control-plane.ts`
- [Account control](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/account-control.ts): `apps/status/src/account-control.ts`
- [Localization](https://github.com/kaloyandjunow-prog/lospor-hospital/blob/main/apps/status/src/locale.ts): `apps/status/src/locale.ts`

### Other components

- **Clinician**
- **Appliance administrator**

## Connections

- Clinician → Web client: uses
- Clinician → PWA client: uses
- Web client → Clinical API: requests clinical services
- PWA client → Clinical API: requests clinical services
- PWA client → Offline autosave: saves offline (evidence: `apps/pwa/src/lib/autosave-manager.ts`)
- Offline autosave → Clinical API: sends case updates (evidence: `apps/pwa/src/lib/autosave-manager.ts`)
- Clinical API → Clinical cases: reads and writes (evidence: `apps/api/src/app/v1/cases/[id]/route.ts`)
- Clinical API → Preop mapping: maps preop (evidence: `apps/api/src/app/v1/cases/_mappers.ts`)
- Clinical API → Intraop mapping: maps intraop (evidence: `apps/api/src/app/v1/cases/_mappers.ts`)
- Clinical API → Postop mapping: maps postop (evidence: `apps/api/src/app/v1/cases/_mappers.ts`)
- Clinical API → EHR import: imports records
- Clinical API → Clinical AI: provides advice
- Research Browser → Research services: queries research
- Research services → OMOP export: maps clinical data
- OMOP export → Policy-gated delivery: packages exports
- Clinical cases → Patient linkage: supports encrypted linkage
- Clinical cases → EHR delivery: supports hospital exchange
- Appliance administrator → Status application: administers appliance
- Status application → Status authentication: authenticates sessions (evidence: `apps/status/src/app.ts`)
- Status application → Status interface: renders pages (evidence: `apps/status/src/app.ts`)
- Status application → Status data store: stores events (evidence: `apps/status/src/app.ts`)
- Status application → Localization: localizes responses (evidence: `apps/status/src/app.ts`)
- Status authentication → Status data store: persists credentials (evidence: `apps/status/src/auth.ts`)
- Status application → Operational attention: presents operations (evidence: `apps/status/src/app.ts`)
- Status application → Go-live readiness: presents readiness (evidence: `apps/status/src/app.ts`)
- Go-live readiness → Host observations: assesses host state (evidence: `apps/status/src/go-live.ts`)
- Go-live readiness → Operational signals: assesses signals (evidence: `apps/status/src/go-live.ts`)
- Go-live readiness → Maintenance: assesses maintenance (evidence: `apps/status/src/go-live.ts`)
- Operational attention → Host observations: uses observations (evidence: `apps/status/src/attention.ts`)
- Operational attention → Maintenance: uses maintenance state (evidence: `apps/status/src/attention.ts`)
- Status application → Control plane: serves controls (evidence: `apps/status/src/app.ts`)
- Status application → Account control: serves account controls (evidence: `apps/status/src/app.ts`)
- Status application → Update requests: serves update requests (evidence: `apps/status/src/app.ts`)
