ECLIPTIC :app — the cockpit Layers & state

:app · the cockpit

Layers and state

Reactive core: delegates fold repository and source flows into one StateFlow<CockpitUiState> that the whole UI reads. Dependency injection is manual. The rule the codebase follows consistently is no new logic in a composable.

Layer map

MainActivity ─ immersive chrome, permission gate, kiosk engage
     │
CockpitScreen ─ burnInScaffold → theme → dispatch on CockpitConcept
     │            ├── RADAR   MotionTrackerScreen
     │            ├── MAP     InstrumentBayScreen
     │            ├── DRIVER  DriverNightScreen
     │            └── passengerScreen (when this device holds the passenger role)
     │
CockpitViewModel ─ one StateFlow<CockpitUiState>
     │   ├── MapCameraController    pan / zoom / rotate / tilt / recenter
     │   ├── NavigationController   drive-to targets, routing, street + art callouts
     │   ├── GpsController          source selection, fake-GPS nudges
     │   └── NavShareController     adopt / broadcast the shared $ZNAV destination
     │
data/ ─ VehicleConnectionGateway · TelemetryRepository · LocationSource
        ThreatSource · PlayaMapRepository · DiscoveryRepository · CockpitPreferences
        nav (NavShare send/receive) · art (pre-rendered art)
     │
core/ ─ pure logic, no Android: geo · navigation · ops · vision · telemetry
        sensor · model · connection · log · net · passenger · permission · kiosk

core/ is where every decision that can be tested without a device lives. Draw code turns decisions into pixels; the decisions live in core/ with tests. SurroundRing / SurroundRingCanvas is the clearest example of that split.

Dependency injection

Manual, in ZodiacApplication.kt — no Hilt or Dagger. Everything is by lazy in a process-lifetime CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate), so construction order is first-access order. onCreate does the only ordered work: plant the debug Timber tree, plant the file log tree, install the crash logger, then log a boot line naming the device, API level, active BRC year and log path.

Two objects are deliberately hoisted out of their registries so a second consumer can reach the same instance: fakeLocationSource (the debug nudge chips drive it) and networkLocationSource (the ViewModel reads its beaconSensors and audioLevel flows).

The ViewModel and its delegates

ui/viewmodel/ is five files. CockpitViewModel (~630 lines, 20 public functions) owns the single MutableStateFlow<CockpitUiState>, the flow subscriptions, and the vehicle-command actions. It constructs and delegates to four controllers that share that state handle.

FileOwns
CockpitViewModel.ktState ownership, init flow wiring, heading / speed / transport / concept actions, map-load retry
MapCameraController.ktsetMapMode, setTiltDeg, setPixelsPerMeter, panBy, nudgeViewRotation, recenterPan, auto-recenter scheduling
NavigationController.ktsetNavTarget, driveToNearestToilet, address entry, route recomputation, street-crossing and passing callouts
GpsController.ktselectLocationSource, restartLocationSource, fake-GPS nudge / reset
NavShareController.ktAdopt an inbound $ZNAV destination and broadcast local sets when this device is a nav authority (NavShareArbiter orders + de-echoes)

The public API of CockpitViewModel is unchanged by the split — the delegates are internal collaborators, not a new surface. The split followed the project's own standing rule, “split the file, don't bump the number”: TooManyFunctions was reverted 25 → 22 rather than raised.

Input validation lives in the ViewModel layer

Not in the UI — so every entry point (chip, gesture, synthetic GPS, persisted preference) is bounded by the same rules.

QuantityBound
Heading0–359
Speed0–160 kph
Tilt0–80°
Zoom0.05–5.0 px/m
Camera pan±5000 m per axis

CockpitUiState

One immutable data class of 42 fields, updated with .copy(). That is a known cost — a per-frame field change copies the whole state — tracked as item A5 in the development backlog.

Why it stays one flow

The targeted alternative (splitting into three flows) was considered and declined. One StateFlow is why all three concepts always render the same world and a concept switch can never show a different one. Three flows can be observed mid-update in inconsistent states — on a display that carries collision alerts. The recomposition half of the problem is already solved by MapUiInputs, an input slice that lets the map subtree smart-skip when unrelated state changes. If profiling ever justifies more, the move is more input slices, not more flows.

Two routers, deliberately opposite lifecycles

RoutedLocationSource.select() stops the old source before starting the new one. RoutedVehicleGateway.selectTransport() leaves the old adapter connected. Both are documented in place and pinned by tests. FailoverLocationSource exists precisely because the location policy makes failover-on-top-of-routing impossible any other way.

A proposal to collapse the Routed<T> shapes into one generic was declined: there are only two real routers (RoutedThreatSource is not a router at all — it is a fixed two-source combine with a demo-fallback policy and no selection), and a generic would need a policy parameter just to preserve the opposite switch semantics.

The vehicle command path is entirely simulated

Not built
TypeImplementations
TransportAdapterFakeTransportAdapter only. Three instances registered, one per TransportType (BLE / USB / WIFI).
TelemetryRepositoryFakeTelemetryRepository only in production.
VehicleCommandSetHeading(Int), SetSpeed(Int) — the entire vocabulary.

Real vehicle data does not travel this path at all. It arrives through NetworkLocationSource and NetworkThreatSource. The gateway is a boundary kept warm for a vehicle bus that does not exist yet.

Rendering pipeline

PlayaMapPanel is the shared map host used by both RADAR and MAP. It caches aggressively because the Fire HD 10 is the floor.

PlayaMap → ProjectedMap (paths + point batches, cached per camera change)
         → drawProjectedMap (per frame)
         → drawProjectedLabels (zoom-gated, same pass)

Polylines are held as flat DoubleArrays and walked with inline projection straight into a Path cursor, so the inner loop allocates nothing. Labels are measured colour-agnostically so a palette change never invalidates the layout cache.

What is not cached is the rasterised pixels — see the performance backlog.

Preferences

DataStoreCockpitPreferences persists 22 keys in one Preferences DataStore — GPS source, map mode, tilt, zoom, concept, passenger role, and every burn-in parameter. The $ZNAV Lamport counter is persisted separately so a rebooted authority does not mint a losing low seq.

  • Enums are stored by name, so a renamed constant falls back to the default rather than mis-mapping.
  • Every numeric read is clamped to the same range the UI enforces, so a tampered or stale file cannot strand the UI.
  • A ReplaceFileCorruptionHandler is installed because a torn file would otherwise be a crash loop on a kiosked tablet with no Settings access.
  • The default persisted GPS source is NET, not FAKE — a corrupt-prefs recovery on a deployed tablet should land on real GPS, not on a plausible synthetic map parked at the Golden Spike. Recovery also resets passengerMode, so a corrupted passenger tablet returns as a driver cockpit; it comes back running, and the role flip is one hidden-panel action.

Converted from
ARCHITECTURE.md §4.1–4.4, §4.9, §4.13 · tasks/open.md (private dev repo) · SYNC.md 2026-08-10 (private dev repo)