Skip to content

Community catalogue snapshot format

The contract between two programs that never meet: whatever builds a catalogue release, and every app that opens one. See ADR-0009 for why the catalogue exists and why it is downloaded whole rather than queried.

The columns are not listed here. src/lib/catalogue/snapshot-schema.ts holds the DDL and the reader's required-column list, and snapshot-schema.test.ts builds a snapshot from that DDL and runs the reader's own queries against it. A second copy of the schema in prose would drift, and the drift would surface as a release the app silently cannot read. This document covers what the DDL cannot say: what the fields mean, and what may change.

Two files, two jobs

A release is a manifest and a snapshot.

The manifest is small, fetched first, and is the only URL an app knows. It names the release, the snapshot's location and digest, the snapshot layout version, and the oldest app build able to read it. Everything else follows from it, which is why storage can move without shipping a client.

The snapshot is SQLite: indexed, queryable, and openable beside the health database. It is downloaded whole. An app never asks a server about a particular medicine, because the question would disclose what the person takes.

What a claim is

Every row in the catalogue is a claim about a pack, never a fact about a person, and never a single eternal truth about a product. Four fields carry that and appear on every claim table.

Identifier. sukl for a registry package, gtin for a barcode. A claim with no identifier cannot be matched to anybody's pack and must not be published.

Market. Appearance and composition are market-specific — the same medicine is packaged differently across borders, so a Czech claim is not evidence about a Slovak box.

Validity window. valid_from / valid_to, both nullable and open-ended. Manufacturers change tablets while identifiers stay put. A catalogue storing only current values would silently rewrite what an older pack looked like, and the person holding that older pack is the one who needs the answer.

Confidence. verified (official document), corroborated (independent agreeing submissions), community-sourced (one submission). It is not a formality: a reading app must show the level, because a rendered pill carries more authority than a blank space.

Reading rules

These are the reader's obligations, and a builder can rely on them.

  • Required columns are required; everything else is ignored. A reader names the columns it needs and tolerates any others, so a newer release may add data without stranding older builds.
  • The snapshot declares its own schema version in catalogue_meta, and it is checked as well as the manifest's. The manifest is written by the publisher and can describe the file incorrectly; the file describing itself is the claim that has to hold.
  • A layout that fails the check is refused and deleted, not adopted. A file the build cannot read would otherwise answer nothing, which looks like a catalogue with no data rather than a release that should have been rejected.
  • A claim is never an answer on its own. More than one may exist for one identifier; the caller selects by validity window first, then market, then confidence. Superseded claims lose before confidence is considered — a colour that stopped being true in 2023 must not describe a pack bought this year, however well attested.
  • Catalogue data ranks below every local source. It fills gaps the leaflet left; it never overrules a document that spoke or a correction a person made.

Changing the format

One question decides the version: would an existing reader misunderstand this file?

Change Version
New table, or new column on an existing table unchanged
New optional value in an existing column unchanged
Removing or renaming a column a reader names bump
Changing a column's type or meaning bump
Making an optional column required bump

A bump means older builds refuse the release rather than misreading it, so minimumAppVersion in the manifest must rise with it. That is a deliberate cost: a release that half-works on an old client is worse than one that plainly declines, because appearance data drives a picture people match against a pill in their hand.

Reusing a column for a new meaning is not a version bump, it is a data-integrity fault — every producer still emitting the old sense is now wrong. Add a field instead.

Building a release

npm run catalogue:build -- --in claims.json --out dist --version 2026.07.1 --base-url https://… does it, and --keygen mints a signing keypair. The builder lives in this repository on purpose: it reads SNAPSHOT_DDL out of the app's own module and gates its output with the reader's own check, so a release cannot be published in a shape the app refuses. A copy of the schema in a separate build repository would drift, and the drift would only surface as a release nobody could read.

Input is a JSON file of reviewed claims — the moderated queue's output, never raw submissions. The builder reviews nothing; it turns approved facts into a file.

A builder must produce a file that passes checkSnapshot, which is exported for exactly that use: the same function gates the app's download and the publisher's release. Beyond that:

  • Write schema_version into catalogue_meta. A snapshot that does not declare its version is refused.
  • Publish the digest in the manifest. Bytes that disagree with it are discarded rather than kept and flagged.
  • Serve the snapshot over https. Over plain http the bytes and the manifest describing them can both be replaced in transit, so the digest would be checked against the substitution.

Signing a release

The manifest is signed, not the snapshot. That is enough because the manifest carries the snapshot's digest, so a valid signature vouches for the bytes it names transitively. Signing only the database file would leave the digest, the version and minimumAppVersion unprotected — most of what a substitution would want to change.

Ed25519. The signed bytes are the manifest with its own signature field removed, serialised canonically: object keys sorted at every depth, undefined values dropped, array order preserved. signedBytes() is exported from src/lib/catalogue/manifest.ts so a publisher computes exactly what a reader will, from the same code rather than from a description of it. Field order in the published JSON does not matter.

The signature and the public key are base64; the key is a raw 32-byte Ed25519 key, and a signature is 64 bytes.

An app with CATALOGUE_PUBLIC_KEY set refuses an unsigned release, or one signed by any other key, rather than downgrading it to unverified. A key that tolerated unsigned releases would be decorative: anyone able to serve the manifest could omit the signature and be believed anyway. An app without a key configured uses releases but never marks them verified, and says so.

What signing defends: a compromised host or CDN serving different bytes. What it does not defend: a compromised build repository, a stolen signing key, a moderator approving bad data, or upstream data that is simply wrong. Keep the private key outside the repository, as a scoped CI secret.