Skip to content

Instance app

Path Contents
server/app.ts createApp({db, config, ...}) takes explicit dependencies, so tests use an in-memory database.
server/routes/ One Hono sub-app per resource.
server/lib/ Domain logic, including hub/ (the Net client) and auth/.
server/realtime/ The pub/sub hub, the radio room and live feeds.
server/migrations/ Migrations named NNNN_name.sql.
web/src/ The single-page app: pages/, components/ and lib/.
shared/ Pure code shared by the server, panel and supervisor.
admin/, supervisor/ The panel pages and the container entrypoint.

Tests are *.test.ts files beside the code, run with Vitest. Node 24 runs TypeScript directly, so imports use the .ts extension, including in shared/. The compiler option erasableSyntaxOnly forbids enums and constructor parameter properties. Lint is oxlint --deny-warnings and must stay at zero. Record any waiver in .oxlintrc.json with a reason.

The app uses better-sqlite3, which is synchronous and the only native dependency. Prepare statements with stmt(db, sql). Put every mutation and its audit() row in one db.transaction(() => ...)(), and make network calls before it, never inside it.

Tables are STRICT, with CHECK constraints for enums. PRAGMA user_version holds the number of the highest applied migration. Timestamps are ISO-8601 UTC. Per-day statistics use stats_day(), which applies the instance’s statistics time zone, so never slice a timestamp string. The app registers stats_day and distance_km when it opens the database.

  • Return errors with fail(status, msg), badRequest and notFound from server/lib/http.ts. Read request bodies with str, num and isoDate.
  • Every mutation writes to audit_log.
  • An unusual callsign returns 422 unless the request sets force. With force, the app saves the contact with a flag.
  • A destructive admin tool needs confirm: <count> from an earlier count request, plus a filter.
  • Frequencies are in MHz when stored or sent. Only the UI uses kHz, through formatKhz and parseKhzInput in shared/ham.ts.
  • Times are UTC strings. Format them with web/src/lib/format.ts and never with toLocale*. Both log books always show UTC.

Each tab opens one WebSocket at /api/ws. A {type:'sub', topic} message returns a snapshot, so a reconnect needs no refetch. The topics are global, radio, contest:<id> and admin:logs. The client in web/src/lib/realtime-client.ts resubscribes after a reconnect and falls back to REST polling after three failures.

lib/contest-stats.ts is an in-memory cache. The app appends to it after a commit and invalidates it on edits, deletes, imports and rule changes. Any change that affects how a QSO scores must call recomputeContest and invalidate the cache. The cache assumes a single process, by design.

  • All long text lives in shared/text.json and is read with t('messages.area.key', {name}). A test fails on a missing key. Button, field and heading names stay in code.
  • data-tip tooltips explain acronyms only. A table column is explained on its header.
  • Assign each usePermission() result to a const before you combine them. Do not chain them with ||.
  • Use the existing classes and tokens, and do not use inline styles for appearance.
  • Add new data or imagery providers to web/src/pages/Licenses.tsx.
Area Rule
Logging The general log needs contacts.log. Contest logging needs operator status and does not depend on the radio.
Shared computers Every contact needs an operator, and a shared account cannot be the operator.
Edits lib/contact-ops.ts is the only edit and remove path. It covers hand-off and change requests through an administrator.
Lookup The app tries HamQTH, callook.info and the prefix table, and caches results for 24 hours. The prefix table never supplies latitude or longitude.
Spots The app never prunes spots, because statistics count them. A contest QSO closes spots and credits the spotter in its own transaction.
Unknown operator The seeded system:unknown user receives bridge contacts when nobody is chosen. Any member who can log can claim them.