Republished from radiofreq’s architecture documentation.
The control plane
RadioFreq programs Uniden scanners (the SDS100, SDS200, BCD436HP and BCD536HP families) from RadioReference data and
drives them over their USB serial link. Its control plane has two halves that never touch. A natural-language
assistant turns a sentence into edits of the person's favorites lists, every edit a validated tool call whose
effect is shown as a diff and applied only on their say so. A separate, person-initiated act moves a list onto the
radio: as files on the card, or over the serial link, where the sequence of commands is planned, shown with a
file-level diff, confirmed, backed up, run through a connection that refuses the hazardous commands, and unwound on
failure. The assistant has no tool that reaches the radio. This document is the map; docs/INVENTORY.md Part 1
is the exhaustive survey it was written from, and docs/live/device-layer.md is the device layer in detail.
Components
| Component | Where | What it is |
|---|---|---|
| Client surfaces | apps/web (desktop and phone layouts), apps/ios |
React, Vite and zustand. Pages: Lists with Browse, the list editor, Profile, Scanner, Tools, Live control (/live), Account, Admin. The iOS wrapper is Capacitor with no native plugins. |
| Backend | apps/server, apps/edge |
Fastify 5 with SQLite, one process; every per-user table carries user_id and Store scopes every statement to the person set per request. The edge is a dependency-free proxy that holds requests through a deploy. |
| Language layer | apps/server/src/ai/agent.ts, tools.ts, services/proposals.ts |
The assistant: Claude with a fixed system prompt, 20 tools with JSON schemas, a loop of at most 24 requests per turn, and the review gate that diffs and holds every write. |
| Operation layer | ai/tools.ts validation, packages/shared/src/macros.ts, apps/web/src/hpdb/savePlan.ts |
The typed shapes between a model output or a click and anything that changes state. Described below. |
| Device layer | apps/web/src/live/device/, scripts/scanner-service.mjs, the uniden-api package |
uniden-api's Connection (one request in flight, fail-closed timeouts, the command classifier, the deny list, read-only mode), Scanner, the routines and the HTTP handler table, in the browser over Web Serial and in the local service over the port. The emulator for the SDS100 lives in the package. |
| Serial transports | apps/web/src/live/store.ts, live/tabs.ts, live/remote/ |
web-serial (the browser owns the port), http (the local service), remote (a phone through the relay), tab (another tab holds the Web Lock on the port). |
| HPDB reader | packages/hpdb, apps/web/src/hpdb/worker.ts |
The scanner's own database read off the card and indexed in a web worker on the device. The server learns its model, version and date only. |
| External data | packages/rr, apps/server/src/rr |
A hand-built SOAP client behind a gateway that meters, rate-limits, logs and caches per RadioReference account for at most 15 minutes. Public Census and FCC data in data/public/ stands in for someone with neither RadioReference nor a scanner. |
| Alerting | apps/server/src/services/push.ts, notifyFilters.ts |
Web push to phones: a notification per matching call, per scheduled Dispatch Report, at 80 and 100 percent of the month's usage. docs/architecture/events-and-alerts.md. |
| Remote control | apps/server/src/services/relay.ts, apps/web/src/live/remote/ |
A phone drives the scanner connected to the person's own computer through a websocket hub that joins one account's devices only. Below. |
One request, from a sentence to the radio
"Add the county fire dispatch channels to my favorites." The assistant's half ends in the database. The device's half starts when the person presses Save to my scanner.
The assistant never emits a serial command: no tool in ai/tools.ts reaches the device, the prompt says so, and
apps/server/test/boundary.test.ts guards the module boundaries. The one indirect path is a macro the assistant
saves and the person later runs from the Macros panel.
The operation model
There is no single operation type. Four typed, validated shapes stand between a model output or a click and anything that changes state, and each is applied only after its shape passed.
| Shape | Where | What it validates | How it is applied |
|---|---|---|---|
| A tool call | apps/server/src/ai/tools.ts |
Each tool's input_schema has additionalProperties: false; run(input) checks every field by hand: ids are integers the tool then looks up, frequencies are checked against the scanner's 31 bands, tones through the tone codec, enumerations against the file schema. A bad value is an is_error result the model sees. |
The same services the pages call (addToList, addOnRange, applyUpdates, setFieldOnNodes, Store.updateList), inside a turn whose writes are captured. |
| A proposal | apps/server/src/services/proposals.ts |
After a turn with any write, the lists are diffed row by row against a snapshot taken before it, restored to the snapshot, and the diff held in memory for an hour as { id, intent, summary, lists: [{ listId, created?, deleted?, renamedFrom?, diff: { added, removed, changed, rows: [{ uid, level, name, change, fields: [{ key, before, after }] }] } }] }. |
POST /api/ai/proposals/:id/apply writes only the touched lists and answers 409 when a list changed since the capture. |
| A macro | packages/shared/src/macros.ts (zod) |
A discriminated union of nine steps (menu open, value and back, monitor lists, quick keys, services, keys, wait) with bounds on counts, names and waits; validated when the assistant saves it and again on the REST route. | apps/web/src/live/macros/runner.ts turns each step into Live control API calls, checks each landed, and stops at the first failure with a reason. A macro run has a hold-to-run gate, no dry run and no backup. |
| A save plan | apps/web/src/hpdb/savePlan.ts |
planSerialSave(lists, removing, inputs) is the exact command sequence serialSave.ts will send (PlannedCommand { line, why, when? }) and the predicted file set (FileChange { path, action: create or write or same, bytes, diff }), each file with a line diff against the scanner's copy as the account last saw it. Values the radio decides at run time are placeholders. |
The confirm dialog shows the diffs; Dry run prints the sequence and sends nothing; Save runs saveListsOverSerial, which follows the plan. |
Device safety
- One connection, one request in flight. uniden-api's
Connectionserializes requests, matches each reply by command name (the protocol has no transaction ids), and fails closed: a timeout closes the connection and reports the outcome as unknown unless the caller asked to abandon the reply and keep the link, which the page does only inside the loading window after a menu exit, when the radio goes silent for up to three minutes while it reloads its lists. - The deny list and read-only mode. The package's command data marks the commands that can drop the port,
reboot the radio, lock its keypad or need a power cycle (
PRG,MSM,POF,TST,FTX, the debug modes, the sub-CPU keys). The connection refuses them before the wire unless the caller passesallow_deniedfor that one command. Since Phase C this holds on both routes: the local service and the page's own Web Serial connection (apps/web/test/live/deviceApi.test.ts). A read-only connection (/live?readonly=1) refuses every command that changes the radio, even withallow_denied. The console sends what is typed withallow_denied, by the owner's decision; the card routes pass it inside the package for their deliberatePRG,FTXandMSM. - Mode pairing. Program mode is entered with
PRGfrom scan mode only and left only withMSM,<seconds>, which saves the radio's state and reboots it, dropping the link; the page reconnects afterwards.MSMis sent only once program mode was confirmed with aDIRprobe, because outside program mode the same command switches the radio to a USB drive.EPGis never sent: on the SDS100 it answersERRand once left the radio silent until a power cycle. The BCD436HP has no program mode and is written as a drive only. - Plan, diff, confirm, dry run. Every list save over the serial link is planned first (above), shown with a
file-level diff, and confirmable or rehearsable without touching the radio. Card writes as a drive show a file
preview, ask twice, delete
app_data.cfgfirst, and re-read every file byte for byte. - Backup and restore. A before and after snapshot of the settings files goes into the account's history for
every card write and every over-serial save (
apps/web/src/hpdb/history.ts), restorable from the Scanner page after a confirm. A save that fails part way unwinds infinally: leaves the menu, restores the volume, and sendsMSM,2only if program mode was entered. - Validation before sending. Volume and squelch ranges by model, key codes and modes against the enumerations,
quick keys 0 to 99, hold and avoid targets checked against the radio's
DB_Counterso a stale index is refused, and every setter read back rather than trusted (OKis not confirmation:VOL,99answersOKand sets 0). - What is not there. A macro run has no backup or restore. A failure in the middle of a multi-file write says
which files landed only through the history snapshot. There is no per-command rate-limit document yet; the
timeouts and pacing (3 s default,
FTXat 512 bytes per 5 ms, the audio feed one pull at a time) live in the package's data and indocs/live/device-layer.md.
The radio's own behavior, keys, menus and timing traps are in docs/live/sds100-behavior.md and its menu tree in
docs/live/sds100-menu-map.md.
Remote control
A phone drives the scanner connected to the person's own computer.
- Transport. One websocket,
GET /api/relay?role=host|client(apps/server/src/routes/relay.ts), 256 KB frames, proxied as raw TCP by the edge. The computer's tab that holds the Web Lock on the port connects as the host when "Phone control" is on; the phone connects as a client. - Authentication. The same
rf_sessioncookie as any request. No session closes 4401; a guest is refused with- The hub keys everything by user id: a client may attach only to a host of the same account, and a result is accepted only from the host the call went to. There is no pairing code and no per-device token: any browser signed into the account may drive the scanner, and the host sees a count of clients.
- Messages. Host to server:
hello{name, model, key},result{id, ok, data | error},ping. Server to host:call{id, path, method, body?},clients{count}. Client to server:attach{host},call{...}. Server to client:hosts{hosts[]},attached{host | null},host-gone{host},result{...}. Limits: a 30 s call timeout, 32 calls in flight per client, a 256-character path, a 64,000-character body, methods GET, POST, PUT and DELETE. - The host answers with its own API. Each call becomes a Live control API call on the computer, so the phone
never touches the port, and
phoneRules.tsrefuses every/v1/card/*route from a phone; a phone's Save to my scanner runs whole on the computer as one job (live/remote/cardJob.ts), which the phone polls. - On disconnect. The server pings every 25 s and drops a socket that missed a pong. A host closing fails its
pending calls with 503 and tells its clients
host-gone; the same page reconnecting with its key replaces the dead entry so phones re-attach. The browser pings every 15 s, declares the link dead 8 s later, reopens with 1 s to 10 s backoff, and re-checks ononline,pageshow,focusandvisibilitychange. The relay carries control only, never audio: the phone plays calls from/api/recordingslike any device.
Tests: apps/server/test/relay.test.ts, apps/web/test/live/remote.test.ts, cardJob.test.ts, phoneRules.test.ts.
Where to read next
docs/live/device-layer.md: the device layer file by file, what the page adds to the package, the deny list, program mode, the save plan, the catalogs.docs/architecture/dispatch-pipeline.md: the audio and transcription pipeline that shares the serial link.docs/architecture/events-and-alerts.md: the notifications and the Dispatch Report.docs/INVENTORY.md: every component, command, write path, guard, secret and test, as surveyed.- The uniden-api package: the protocol, the command data model with provenance per command, the emulator and the conformance suite.
