Expert Analysis and Synthesis: Cross-Platform Architecture with Rust
Domain Identification: Software Architecture / Cross-Platform Mobile & Web Development / Systems Programming (Rust)
Persona Adopted: Senior Software Architect / Principal Systems Engineer
Abstract:
This presentation introduces "Crux," an open-source architectural framework designed by Red Badger to facilitate the sharing of business logic across iOS, Android, and web platforms using a single Rust core. The core thesis argues for a "Headless App" approach: a pure, functional business logic layer isolated from side effects through the Ports and Adapters (Hexagonal) architecture. By treating the User Interface (UI) as a side effect and pushing all imperative actions (HTTP requests, persistence, time) to the platform-specific "shells," developers can achieve native performance and UX while maintaining 100% logic parity. A critical highlight of the framework is its impact on testability; by decoupling the core from the runtime, complex behaviors—including collaborative editing with CRDTs—can be validated in milliseconds using native Rust test suites without the overhead of UI automation or mocking frameworks.
Detailed Summary and Key Takeaways:
0:00 Introduction and Context: Stuart Harris discusses the long-standing challenge of "write once, run anywhere." He critiques existing solutions for either compromising native UX (Flutter) or introducing high maintenance/testing overhead (React Native).
2:36 Defining "Headless Apps": The architecture relies on a "functional core/imperative shell" paradigm. The core contains pure logic, while the shell (iOS, Android, or Web) manages side effects and platform-idiomatic UI.
5:27 UI as a Side Effect: Harris posits that platforms (Apple, Google) are best at UI. Crux intentionally avoids reinventing UI components, instead leveraging native declarative frameworks like SwiftUI and Jetpack Compose.
7:53 Motivation for Rust in the App Layer: Rust provides high confidence by "pulling bugs from the future." It is used to replace the "layer on layer of sand" found in JavaScript ecosystems with a robust, type-safe foundation.
13:25 The Ports and Adapters Pattern: Crux implements the Hexagonal architecture. The core communicates through "capabilities" (ports) which the platform shells implement via "adapters." This allows the core to remain entirely agnostic of the underlying OS or network stack.
iOS: Statically linked library (.a) using UniFFI for Swift bindings.
Android: Shared object library (.so) using JNA for Kotlin bindings.
Web: Compiled to WebAssembly (Wasm) with wasm-bindgen for TypeScript/JavaScript interop.
Serialization: Uses serde_generate to share types across boundaries, ensuring type safety from the Rust core to the Swift/Kotlin/TS UI.
21:42 The Capability System: Capabilities facilitate interactions. Harris demonstrates an HTTP capability that uses a "Request-Response" pattern where the core yields an effect, and the shell provides the response back to the core as a new event.
Demonstrates a simple counter app synchronized across iOS, Android, and Web in real-time.
Introduces a complex "Notes" application utilizing CRDTs (Conflict-free Replicated Data Types) to handle collaborative editing logic entirely within the Rust core.
37:16 High-Velocity Testing: Harris showcases the "Alice and Bob" sync test. Because the core is pure, two instances of the app can be instantiated in a single test thread. An entire suite of complex integration tests runs in ~30ms, eliminating the need for brittle tools like Appium or Selenium.
40:35 Project Maturity and Roadmap: Crux is currently in an experimental phase. Future goals include improving developer ergonomics, expanding the library of pre-built capabilities, and stabilizing the "shell-side" adapter code.
48:55 Q&A - Handling Platform Specifics: Addressing specialized hardware (e.g., Apple Pencil), Harris explains that shells can simply ignore irrelevant events or handle them uniquely, but the Rust compiler enforces exhaustive pattern matching, ensuring no event is left unhandled across any platform.