Deployment
Build the application and start the generated Node server:
npm ci
npm run db:migrate
npm run build
ORIGIN=http://localhost:3000 PORT=3000 npm run start
npm run db:migrate applies each checked migration in migrations/ once to
DATABASE_URL. Each migration and its filename/SHA-256 journal entry are committed
atomically; later runs skip matching entries and reject an applied file whose
checksum changed. The production server checks this local journal before accepting
requests, so an existing installation receives schema additions during upgrade.
A brand-new empty database is initialized rather than migrated:
npm run db:push # full current schema, straight from schema.ts
node scripts/migrate.mjs --baseline # record every migration as applied
db:push builds the schema as schema.ts describes it today, which already
contains every column and table the checked migrations add. Replaying them on
top fails on the first ALTER TABLE ... ADD COLUMN with duplicate column
name, so a new installation is stamped instead. --baseline refuses a
partially journalled database, where neither stamping nor running is knowably
correct. Later upgrades use npm run db:migrate as normal.
ORIGIN is required for adapter-node form-action CSRF protection. It must match
the browser-facing scheme, host, and port. Behind a reverse proxy, configure
SvelteKit's forwarded protocol and host headers instead of hardcoding an origin.
The project launcher defaults BODY_SIZE_LIMIT to 134217728 bytes so DICOM and
NIfTI uploads work without extra configuration. The imaging upload route still
streams and enforces its independent 128 MiB application cap. If a proxy has its
own request-size limit, configure it to at least the same value. FILE_STORE
must be durable and writable; original medical files are immutable blobs keyed by
SHA-256.
Study ZIP exports and medical-file responses contain sensitive health data. The application sends private/no-store headers for exports and private immutable headers for stored instances; reverse proxies must not override them with public caching.
The production build runs the documentation build first. MkDocs writes its site
to static/docs/; adapter-node includes that directory in the app's static
assets, exposing docs at /docs/ on the same server and origin. /docs redirects
to /docs/, which keeps MkDocs relative assets resolving correctly.
Optional label-OCR service
Supplement label photo capture uses a separate LAN microservice
(services/label-ocr — see its README for setup). Set LABEL_OCR_URL (e.g. http://127.0.0.1:8990) to enable it. Without it the
app still works fully; barcode lookup and pasted-text parsing need no service,
and photo capture reports that OCR is not configured.
Optional community catalogue
Entirely optional. With none of the variables below set, the app never reaches the network: the ŠÚKL mirror, the label parser and the nutrient vocabulary all work offline. See data flow for the shape of the whole cycle and ADR-0009 for why it is built this way.
App variables
| Variable | Effect when unset |
|---|---|
CATALOGUE_MANIFEST_URL |
no snapshot is fetched; nothing is read from the catalogue |
CATALOGUE_PUBLIC_KEY |
a signed release cannot be verified, so none is accepted |
CATALOGUE_SUBMIT_URL |
contributions are still captured and held, but cannot be sent |
TURNSTILE_SITE_KEY |
no challenge is shown — see the pairing rule below |
Submission endpoint
Deployed from services/catalogue-submit (see its README). Once:
npx wrangler d1 create catalogue-submissions # id goes in wrangler.toml
npx wrangler d1 execute catalogue-submissions --file schema.sql --remote
npx wrangler secret put CALLER_SALT # long random string, required
npx wrangler secret put TURNSTILE_SECRET # optional; see pairing rule
npx wrangler deploy
CALLER_SALT is required in practice, not optional: the rate limiter stores a
hash of the caller's address, and an unsalted IPv4 hash is reversible by
enumerating about four billion values — which would turn the table into a list
of who submitted.
Pairing rule. TURNSTILE_SECRET on the Worker and TURNSTILE_SITE_KEY in
the app are two halves of one switch and must be set or unset together. Secret
without site key means the app sends no token and every send is refused with
403. Site key without secret means a challenge is displayed that nothing
verifies. Creating the widget needs a Cloudflare token with Turnstile: Edit,
or the dashboard; add every origin the app is served from, since Turnstile
validates the requesting hostname.
After changing a Worker secret, expect a short window in which some edge locations still run the previous configuration. A first request may behave as though the secret were unset; it settles within seconds.
Publishing a release
Nothing is published automatically. Two deliberate manual gates stand between a submission and a release:
npm run catalogue:review # what is waiting, with local cross-check
npm run catalogue:review -- --approve 3 5 # gate 1: a person decides
npm run catalogue:review -- --export 2026.08.1
The export writes claims/<version>.json. Copy it into the catalogue
repository, commit, and push a matching v<version> tag — gate 2. The tag
triggers the release workflow, which checks out both the catalogue repository
(for claims/) and this one (for the builder and the snapshot schema, so reader
and writer cannot drift), builds, signs with CATALOGUE_PRIVATE_KEY, and
publishes the snapshot and manifest as release assets.
The review CLI needs CLOUDFLARE_API_TOKEN in the environment. It is read from
the shell, so a token added to a profile file is not visible until that file has
actually been sourced.
If the app repository is private, the workflow needs APP_REPO_TOKEN in the
catalogue repository — a fine-grained token scoped to the app repository with
Contents: read-only, because a workflow's own github.token cannot read a
second repository. Record its expiry: when it lapses the failure appears as a
checkout 404 on a repository that plainly exists. Once the app repository is
public, delete that secret and revoke the token; the workflow falls back to
github.token.
The signing key lives only as a CI secret. node scripts/build-catalogue.mjs
--keygen generates a pair; the private half belongs in the catalogue
repository's secrets and nowhere else, including this repository and any .env.