Skip to content

Renderer hook architecture (multi-protocol)

Developer reference for renderer hooks/runtimes/stores, protocol entry points, identity hydration, the SQLite database layer, or tab/UI wiring. Repo-wide rules live in AGENTS.md.

See Renderer: hooks vs runtime vs lib (layout map in AGENTS.md). Legacy useDevice / useMeshCore are removed (#375, #377). Default rules for new UI:

Concern Use
Orchestration (App tab) Active tab reads connection / connectionView / queue / panel from useProtocolFacade(protocol). App mounts one <ConnectionPanel> from activeFacade.connection + capability-gated extras. By-protocol maps stay for inactive-protocol notifier, detail modal, dual-protocol security labels, and other cross-protocol picks (do not add per-protocol protocol === copies)
Active protocol identity useActiveMeshIdentity(protocol) — focused identityId per tab; prefer capabilities over protocol ===
LoRa dual-protocol panel bundles (App) useAllProtocolPanelActions (Meshtastic + MeshCore + Reticulum); prefer this over per-protocol panel-action hooks at the App shell
Reads (nodes, messages, connection fields) Zustand stores + useNodes / useMessages / useConnectionView
Writes (configure, send, admin, panel callbacks) Active-tab App writes/refresh: useProtocolFacade(protocol).panel (panelActions). Cross-protocol / detail-modal: selectByProtocol(panelActionsByProtocol, …). Otherwise usePanelActions(protocol, identityId, …) or useSendMessage(identityId) (outside React, such as the TAK relay: sendChatOnIdentity in lib/sendChatOnIdentity.ts, the same send)
Connect / disconnect / auto-connect ConnectionPanel: useProtocolFacade(protocol).connection. App builds once via useAllProtocolConnectionActions (pass that map into the facade); coordinators / startReticulumStack* read map entries (useProtocolConnect + useProtocolDisconnect). Meshtastic/MeshCore via ConnectionDriver; Reticulum via sidecar start/stop. RF auto-connect: useProtocolRfAutoConnect + protocolRfAutoConnectGate. LoRa reconnect: rfReconnectController
Wire subscriptions, MQTT IPC, reconnect, DB hydration useMeshtasticRuntime / useMeshcoreRuntime / useReticulumRuntime in runtime/ — mount once from App.tsx via context providers

Do not remount protocol runtimes in child components. Do not compare protocol === 'meshcore' for feature gates; use ProtocolCapabilities / useRadioProvider(protocol). useAllProtocolConnectionActions is the single App construction site for connection actions; coordinators read that map. The active tab reads connection / connectionView / queue / panel from useProtocolFacade; by-protocol maps stay for cross-protocol / inactive / detail-modal cases. ConnectionPanel still reads activeFacade.connection. Chat/nodes still use display adapters, not raw activeFacade.messages / .nodes.

Protocol SDK adapters: src/renderer/lib/protocols/. Connection lifecycle: ConnectionDriver (lib/drivers/); inbound domain events: Protocol → PacketRouter → identity stores, then side-effect listeners (ingest already applied). Meshtastic post-router side effects: lib/ingest/meshtasticIngest.ts, meshtasticRouterSideEffects.ts (MQTT uplink / notifications / device_log), meshtasticNodeSideEffects.ts, meshtasticRawPacketSideEffects.ts, meshtasticTraceSideEffects.ts, meshtasticModulePortSideEffects.ts, meshtasticStoreForwardSideEffects.ts; meshtasticTransportSideEffects.ts handles transport-state cleanup, while lifecycle-only SDK attach remains in meshtasticRuntimeWireEffects.ts (DeviceStatus / MyNodeInfo / FromRadio / heartbeat / config / remote-admin — not a second packet decode path). MeshCore post-router side effects: lib/ingest/meshcoreIngest.ts (chat persist, last_heard, path-updated), hooks/meshcore/meshcoreConnSideEffects.ts + MeshcoreConnSideEffectsCtx (meshcoreConnSideEffectsCtx.ts) (DM ack 130, waiting drain 131, RF RX 136, CLI, disconnect), lib/meshcore/meshcoreLiveContactPersist.ts (SQLite contact rows), lib/meshcore/meshcorePubKeyRegistry.ts (DM/trace pubkeys). Live UI nodes/messages read nodeStore / messageStore via identityStoreReads (getIdentityNode / getIdentityChatMessages); runtimes do not keep hook-local node/message wire mirrors. Transport params / Protocol attach helpers: meshIdentityBridge. Favorites: setNodeFavorited patches meshcoreIdentityIdRef (fallback getIdentityIdForProtocol('meshcore')). Dedup windows: cross-transport and channel RF 5 min; room/tapback 60 s. Path-updated (129) for existing contacts does not bump SQLite last_advert until the next advert (128).

Identity-scoped UI stores: identityStore, nodeStore, messageStore, connectionStore — nodes/messages keyed by identityId. Ephemeral relay coverage: relayCoverageStore (in-memory only; identityId:messageId) for outbound Chat bubble fillers — writers in useSendMessage / protocol runtimes / heardRepeatTracker / meshtasticHeardRepeat / reticulumRouteCoverage; messageStore.renameMessageId re-keys coverage + MeshCore listen windows; cleared on identity disconnect / Reticulum session teardown. See chat.md “Relay coverage”. MQTT status bridge: mirrorMqttStatusForProtocol copies main-process mqtt.onStatus IPC into connectionStore.mqttStatus from runtime handlers until MQTT moves fully into ConnectionDriver. SQLite → UI: lib/hydrateIdentityStoresFromDb.ts (coordinator: identityHydrationCoordinator.ts; Meshtastic node map: meshtasticDbCacheHydration.ts; message cap: meshtasticMessageLoadLimit.ts); manual refresh via hooks/useDbRefresh.ts. Identity-scoped Zustand hydration is the canonical UI path ([#375]). MeshCore contacts DB: meshcore_contacts.last_advert is Unix seconds; age prune uses src/shared/meshcoreContactAgeCutoff.ts (do not compare in ms).

Protocol entry points

  • Meshtastic: src/renderer/lib/protocols/MeshtasticProtocol.ts, useMeshtasticRuntime (side effects), src/renderer/lib/connection.ts (createConnection)
  • MeshCore: src/renderer/lib/protocols/MeshCoreProtocol.ts, useMeshcoreRuntime (side effects), @liamcottle/meshcore.js

Database

WAL SQLite; user_version in database.ts; migrations as migration_N(); db-compat.ts over node:sqlite. After schema changes: pnpm run check:db-migrations. Startup maintenance: lib/startupDbPrune.ts — single-flight per session from App.tsx (node/message retention, RF stub migration); do not re-invoke from unstable effect deps. useAppStartupDbPrune starts it in a layout effect, so it is in flight before any runtime mount effect runs; a load that reads SQLite on its own at launch awaits afterStartupDbPrune() first (the MeshCore runtime mount load does), or it shows rows the prune deletes, and App's post-prune upsert hydrate never removes them. Meshtastic and Reticulum read messages only on connect.

UI

TAK: useTakNodeReplicator (mounted once in AppContent) sends node positions from all three protocols, RMAP stations, and our Reticulum position to main over tak:pushNodeUpdates while useTakServer or useTakRemoteStatus reports an active sink. Which nodes qualify (per-protocol online window, no (0, 0) placeholders) lives in lib/takNodeFeed.ts. useTakContacts (mounted once from App.tsx) keeps inbound CoT contacts in takContactStore for the map, applying tak:contacts deltas onto the tak:getContacts snapshot. The TAK panel's relay section uses useTakRemoteRelay; certificates and keys stay in main (src/main/tak/remote-credentials.ts).

Panels: src/renderer/components/. New tabs: lazyTabPanels.ts / lazyAppPanels.ts + capabilities. Tab visibility: src/renderer/lib/tabSlotIds.ts (TAB_SLOT_IDS) → src/renderer/lib/appTabMappings.ts (TAB_CAPABILITY_REQUIREMENTS, computeTabMappings() in App.tsx). Shell (v6, issue #1062): src/renderer/components/shell/ — AppRail (MT / MC / RN switcher + Chat / Network / Map / Monitor / Device, then Incident / App), SectionHeader (the section's panels as sub-tabs, ids tab-<filtered index>), StatusBar (radio / MQTT / TAK / queue readouts, counts, update state) and PanelLauncher (Ctrl+K, Cmd+K on macOS; pins give Ctrl/Cmd+1..4, stored in mesh-client:launcherPins). A new tab slot must also be placed in a section in src/renderer/lib/navSections.ts (navSections.test.ts fails otherwise); badges come from lib/navBadges.ts. Visual rules: docs/style-guide.md. Stores: module defaults; persist vs SQLite IPC as elsewhere. MeshCore Open wire / path-hash UI mounts from RadioPanel, which persists meshcoreOpenWireCompatEnabled and meshcorePathHashMode as app settings via mergeAppSetting (ownership stays on RadioPanel, not AppPanel).

Node and peer detail (v6): NodeDetailModal and ReticulumPeerDetailModal take variant: 'modal' | 'pane'. A node or peer picked from the Nodes/Contacts/Peers list or the map opens as a pane beside it when the window is at least 1280px wide (NODE_DETAIL_PANE_MEDIA_QUERY + useMediaQuery in App.tsx; nodeDetailPane / peerDetailPaneHost record the host, 'list' | 'map'); chat, diagnostics and other entry points keep the modal. A pane selection stays hidden on other panels and comes back on the list or map it came from; it falls back to the modal only if the window narrows there. MapResizeInvalidator (both maps) re-measures Leaflet when the pane opens or closes. The pane does not capture focus or Escape. List rows expose the name as a button (aria-current on the selected one) so the detail opens from the keyboard.