Skip to content

Architecture overview

Personal Health is a SvelteKit application served by the Node adapter. Server code uses libSQL through Drizzle ORM; browser routes render the health-record interface and server code accesses the database and file storage.

The system is local-first and single-user. SQLite defaults to data/health.db and original file blobs default to data/files. See Deployment for configuration and production constraints.

Key dependencies

  • SvelteKit and Vite provide routing, server rendering, and development.
  • Drizzle ORM and libSQL define and access the local SQLite model.
  • adapter-node creates the self-hosted Node server build.
  • Cornerstone3D is lazy-loaded only on supported record detail pages. Its DICOM, NIfTI, tools, and ECG viewport APIs render clinical images and DICOM waveforms.
  • dicom-parser classifies and extracts server-side DICOM metadata without rewriting originals; yazl streams native study exports.
  • Three.js is client-only and dynamically imported for the pill-appearance editor and the medication list's one-at-a-time missing-thumbnail baker; it never ships in the SSR/main bundle. See ADR-0005.
  • Poppler's pdftotext is an optional external tool used to read ŠÚKL patient leaflets. It is not an npm dependency: without it, leaflet-derived pill appearance is skipped and everything else still works. See ADR-0006.
  • Material for MkDocs renders this site at /docs/.

The complete direct-dependency inventory is generated.

External data sources

Terminology and product data come from public sources through src/lib/server/integrations/ (RxNorm/RxClass, MedlinePlus, LOINC, ICD-11, Open Food Facts), cached as versioned snapshots in api_cache.

The Slovak medicine registry is different in kind: ŠÚKL publishes bulk ZIP archives rather than an API, so it is mirrored into its own tables by src/lib/server/sukl/ and queried locally, with each ingest stamped by sukl_snapshots. Patient leaflets are read out of the published 3.8 GB archive by HTTP range request and converted to text on demand. Pill appearance extracted from that prose is kept apart from the authority's own fields — facts with provenance in pill_appearance_facts, resolved into pill_profiles.

National identifiers stop at the border, so a medication also carries INN, ATC, RxNorm and UNII, resolved once per substance through RxNav and cached in substances. See ADR-0007.

Unified record facade

/documents is the only record library. src/lib/server/records.ts merges ordinary document rows with logical imaging-study rows into discriminated record entries for listing, filtering, and navigation. Specialized tables remain authoritative for DICOM Study → Series → Instance structure, while the user-visible library has no Documents/Imaging split.

Opening a record selects a lazy viewer adapter: Cornerstone stack/volume rendering for DICOM and NIfTI, Cornerstone ECG for supported DICOM waveform SOP classes, native browser rendering for JPEG/PNG/WebP, and the existing PDF presentation.

The opened imaging record uses a responsive diagnostic workspace with native Cornerstone thumbnails and format-aware tools. Length, angle, and arrow annotations are stored as versioned per-series snapshots with optimistic concurrency; viewport presentation state remains temporary. See ADR-0003.