garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/adr/030-platform-capability-model.md

raw

ADR-030: Platform Capability Model (Substitutable Providers + Additive Plugins)


Metadata:


Context

Problem: We want a browser (wasm32) build without foreclosing native-only features (in-world browsers, local file import, the embedded solo sim), and without letting the browser's limits dictate the whole architecture. Today the client assumes native primitives throughout — raw TCP (systems/network.rs), an in-process cartopolis_simulator over loopback (solo.rs, ADR-016), blocking ureq on std::thread::spawn (tile/transit/overpass/lod22 loaders), std::fs caches, and rusqlite for offline mode. None of these exist in a browser sandbox. The naive fixes pull in opposite directions: design for the intersection of both platforms and native-only features become impossible; design for native and the web build won't compile.

The framing trap is treating native as a superset of web. It isn't — opening a real link in a new tab or compositing an <iframe> is trivial on web and hard on native. Each platform has a capability set; neither contains the other.

Requirements:

Decision

Adopt a two-tier capability model. Every platform-varying concern is classified as one of:

Supporting rules:

Web build is necessarily online-only: solo (ADR-016), --offline, and all rusqlite usage are additive capabilities the wasm App omits; it connects to a remote cartopolis_simulator via the WebSocket transport provider.

Rationale

Primary Reasoning:

  1. No lowest-common-denominator tax. Additive capabilities let native keep full-fat features; the fallback contract keeps web shipping. We design for the union, gated by capability — not the intersection.
  2. Extends work already sanctioned. The transport abstraction is needed for web regardless (ADR-008); making it the first Transport provider costs nothing extra and sets the pattern. solo (ADR-016) is already a build-time capability gate — this generalizes it.
  3. Protocol/data neutrality is preserved (P-02, P-05). Portable DTOs mean a web user sees what a surface shows even when it can't render live, and the wire format is untouched.
  4. Graceful degradation is a UI contract, not an accident — the Capabilities resource makes "what can I offer here" a first-class query.

Alternatives Considered:

AlternativeProsConsRejected Because
Design for the intersection onlySimplest; one code pathNative-only features become impossibleDirectly causes the limitation the ADR exists to prevent
Native-first, bolt on wasm laterFastest short-termWeb build won't compile; retrofit touches everythingPlatform assumptions calcify into core loop
#[cfg] inline per call siteNo new abstractionRots silently; smears platform logic through featuresThe egui test-rot failure mode, codebase-wide
Separate web fork/crateClean isolationDuplicate feature logic; driftViolates single-source feature code (P-05)

Consequences

Positive:

Negative:

Related