Files
julian 1efa77bf56 devices: pool-of-spaces model — drop lane, per-relay direction
A parking lot is one pool of spaces with a flexible set of entry/exit
points — no "lane". Direction is a property of each RELAY inside an access
controller; readers/cameras bind to a controller relay and inherit it.

Schema:
- drop `lane` from ledger_events, device_events, sessions
- rename lane_devices -> devices (no lane/direction columns)
- access config.relays=[{relay,direction,button?}]; reader/camera
  config.controllerId+relay binding
- fresh 0000_baseline migration (history reset; dev data was throwaway)

Signed ledger:
- remove `lane` from canonicalize(); bump signer keyId sw-hmac-v1 -> v2
  (v1 events won't verify under v2 — intentional, gated per-event by keyId)

Server:
- new device-resolve.ts (replaces lane-map.ts): relayForButton,
  relayForDevice, firstRelayByDirection, devicesByDirection
- entry-flow: button terminal -> its relay; exit/permit: reader's bound
  relay; dispatcher resolves the bound relay + inherited direction
- camera snapshots fire by direction site-wide, async, never block open
- DeviceConfig widened to nested JSON for relays[]

Web:
- wizard: no lane selector; add controllers (relay map + entry-button
  terminal) first, then bind readers/cameras/printers to a controller relay

Wiki: new entry-exit-points.md (replaces lane-direction); reworked
entry-exit-readers, parking-session, first-run-setup, device-registry,
append-only-event-chain, device-events; removed stale lane/LaneMap mentions.
2026-06-16 20:29:38 +02:00

1.6 KiB

type, tags, sources, updated
type tags sources updated
concept
parking
architecture
devices
parking-system-architecture
2026-06-14

Device-Adapter Pattern

How the system stays device-agnostic: business logic talks only to interfaces, never to a device SDK. Each physical device is an adapter implementing one interface; swapping hardware means writing a new adapter and nothing else changes. Implemented as isolated fastify plugins emitting onto a shared internal event bus. (See parking-system-architecture §5.)

interface CardReaderDevice {
  connect(): Promise<void>
  onCardRead(cb: (cardNumber: string, door: number) => void): void
  disconnect(): Promise<void>
}
interface PrinterDevice {
  printTicket(data: TicketData): Promise<void>
  checkStatus(): Promise<'ready' | 'offline' | 'paper_out'>
}
interface RelayDevice {
  pulseOpen(doorId: number): Promise<void>   // intent only — see safety note
  getDoorStatus(doorId: number): Promise<'open' | 'closed'>
}

Note the RelayDevice expresses intent only — see the barrier-not-a-door safety principle. The choice of which adapter to trust is the trust-boundary decision.

In practice the adapters are made selectable: a device-registry catalogs the supported drivers (ZKTeco / ESP32 relay, Wiegand / TCP-IP readers, Hikvision / Dahua cameras), and the admin assigns instances during first-run-setup. Adding hardware support = one more registered driver, no business-logic change. (The implemented interfaces add a CameraDevice for entry/exit snapshots alongside reader/relay/printer.)