Lesson 7 · Mobile and offline architecture
Native, cross-platform or web?
A practical framework for choosing an app architecture.
About 25 minutes
Tab indents. Press Escape, then Tab, to leave the editor.
Every app architecture decision is a bet about where your costs will be: in duplicated code, in fighting an abstraction, in waiting for a framework to support a platform feature, or in a team learning a new stack. There's no universally right answer, but there is a right process: decide which constraints are hard, then pick the option that satisfies them with the fewest codebases you have to keep in sync. This lesson lays out the current options accurately, gives a decision sequence, and walks through a real one: the architecture OfflineOwl itself uses.
The options as they stand
Fully native per platform. SwiftUI (with UIKit/AppKit underneath and available through UIViewRepresentable and UIHostingController) on Apple platforms; Jetpack Compose (with Views interop) on Android. You get day-one access to every platform API, the platform's own controls, accessibility and text behavior for free, and the best tooling (Xcode Instruments, Android Studio profilers). You pay with two complete implementations of everything, business logic included, and two sets of bugs.
Kotlin Multiplatform (KMP). Share Kotlin code (models, networking, storage, business rules) across Android, iOS, desktop and web, compiled to native code on iOS. UI stays native: SwiftUI on iOS calls into a Kotlin framework. Google supports KMP for sharing business logic between Android and iOS. The iOS team works against Kotlin-generated Objective-C-style headers, which is the main ergonomic friction (Swift export is improving it).
Compose Multiplatform. JetBrains' extension of Jetpack Compose to iOS, desktop (JVM: Windows, macOS, Linux) and the web. The iOS target has been stable since Compose Multiplatform 1.8.0 (May 2025); the web target, built on Kotlin/Wasm, reached Beta in 1.9.0 (September 2025) and is the least mature. Shared UI and logic in Kotlin. On iOS it renders its own widgets rather than UIKit controls, so it can look and behave native-adjacent rather than native, and you interoperate with UIKit/SwiftUI for anything platform-specific.
React Native. JavaScript/TypeScript with React, rendering real platform views. The New Architecture (the default since React Native 0.76) replaced the asynchronous JSON bridge with JSI (direct, synchronous calls between JS and C++), the Fabric renderer and TurboModules, which removes the old bridge bottleneck. Expo provides the toolchain, native modules and build service most teams use. Strengths: web-developer skills transfer, one codebase for iOS and Android, over-the-air updates for the JS bundle within store rules. Costs: a JavaScript runtime (Hermes) in the app, native modules for anything the ecosystem lacks, and upgrade churn across the JS/native boundary.
Flutter. Dart, with its own rendering engine (Impeller) drawing every pixel on a canvas, on iOS, Android, desktop and web. Pixel-identical UI across platforms and excellent rendering performance; the flip side is that platform controls, text input, accessibility and new OS design changes are reimplemented by Flutter rather than inherited, and embedding native views (maps, web views) has a cost.
Progressive web apps. One web codebase, installable, offline via service workers, updated instantly without store review. The gaps are on iOS: Home Screen web apps get push notifications (since iOS 16.4) but no Background Sync, no background execution, storage the system may evict, and many device APIs (Bluetooth, NFC, USB, rich background audio) are Chromium-only or absent. Discovery is via URL, not the store, which is a feature or a problem depending on your audience.
A shared Rust core with native UIs. Write storage, sync, search and domain logic once in Rust; generate Swift and Kotlin bindings with UniFFI (Mozilla's binding generator; Python and Ruby are also supported, with community generators for other languages); build fully native UIs on top. It's the same split as KMP, with a language that compiles to every target including WebAssembly, no garbage collector or runtime to embed, and a strong ecosystem for SQLite, full-text search and parsing. The costs are a cross-compilation build matrix, an FFI boundary to design and debug across, and a language your UI developers may not know.
The constraints that actually decide it
Most debates about frameworks argue about the wrong things (benchmarks, syntax). The constraints that decide real projects:
- Platform API depth. Widgets, Live Activities, App Intents, watch and car apps, HealthKit, background transfers, on-device ML frameworks: if the product depends on these, you'll write native code regardless. The question becomes how much.
- UI fidelity expectations. Do users expect it to feel exactly like the platform (navigation, text selection, scrolling physics, accessibility, the latest OS design language), or is a consistent brand UI across platforms the goal?
- Targets. iOS + Android only? Desktop too? Linux? Web? Each framework covers a different set, and maturity varies by target.
- Offline and data complexity. Sync engines, local databases, conflict resolution and search are the most expensive logic to write twice and the worst place for platforms to drift apart.
- Team. What the team knows, and how many people there are. A two-person team can't maintain four idiomatic codebases.
- Distribution and update cadence. Store review latency, enterprise distribution, or "anyone with a URL".
Step by step
A decision sequence
Could it be a website?
If the app is mostly content and forms, works on intermittent networks with a service worker, and needs nothing iOS withholds from the web (background work, reliable storage, deep device APIs), ship a PWA first. It's one codebase with instant updates. Wrap it later if store presence matters.
Case study: OfflineOwl's architecture
OfflineOwl, the app you're reading this in, is a reasonable real example because its constraints are unusual. It's offline-first by definition: survival guides, preparedness checklists, and a personal knowledge base (import your own PDFs and documents, then full-text search them offline). It targets iPhone, iPad, Mac, Android, Windows, Linux and the web, with a small team.
The current architecture:
owl-core, a Rust library, owns storage (SQLite), the content library, preparedness tracking, document import and offline search, and sync. It's exposed through UniFFI proc-macros.- A SwiftUI app for iPhone, iPad and Mac, using system navigation and the current Apple design.
- A Compose Multiplatform app for Android and desktop (Windows and Linux), with Material 3.
- The Next.js web app, which is both the web client and the auth and sync server every native client talks to.
It replaced an earlier pair of stacks, a Tauri desktop app and an Expo (React Native) mobile app, each of which had its own copy of the data and search logic. The reasoning maps onto the constraints above: the expensive logic (storage, search, sync) is written once, so platforms can't drift; the UIs are native where users notice (Apple platforms) and shared where the platforms are close (Android and desktop via Compose); and Compose Multiplatform covers Windows and Linux, which SwiftUI can't.
The binding layer looks like this (simplified from the core's contract):
// Rust: owl-core
uniffi::setup_scaffolding!();
#[derive(uniffi::Record)]
pub struct SearchHit {
pub document_id: String,
pub snippet: String,
pub score: f64,
}
#[derive(Debug, thiserror::Error, uniffi::Error)]
pub enum CoreError {
#[error("not found: {what}")]
NotFound { what: String },
#[error("storage error: {detail}")]
Storage { detail: String },
}
#[derive(uniffi::Object)]
pub struct OwlCore { /* SQLite pool, paths, ... */ }
#[uniffi::export(async_runtime = "tokio")]
impl OwlCore {
#[uniffi::constructor]
pub fn new(data_dir: String) -> Result<Arc<Self>, CoreError> { /* open + migrate */ }
pub async fn search_documents(&self, query: String, limit: u32) -> Result<Vec<SearchHit>, CoreError> {
/* full-text search over imported documents */
}
}
// Swift: generated bindings. snake_case becomes camelCase, Result becomes throws.
let core = try OwlCore(dataDir: dataURL.path)
let hits = try await core.searchDocuments(query: "water purification", limit: 20)
// Kotlin: the same API. async fns become suspend fns, errors become exceptions, u32 becomes UInt.
val core = OwlCore(dataDir)
val hits = core.searchDocuments("water purification", 20u)
What it costs, honestly:
- A build matrix. The core is compiled for iOS devices, the iOS simulator and macOS (packaged as an XCFramework), for each Android ABI (via the NDK), and for each desktop OS, with bindings regenerated on every API change. That's scripts and CI time a single-codebase framework doesn't need.
- A contract to manage. The Rust API is a public interface for two UI codebases, so changes go through a written contract first. Designing an FFI surface (coarse-grained calls, records instead of chatty getters, explicit threading rules: blocking calls must stay off the main thread) is its own skill.
- Three UIs. SwiftUI, Compose and the React web client each implement every screen. The shared core removes logic duplication, not UI work.
- Debugging across the boundary. A crash in Rust called from Swift needs symbols and tooling on both sides.
The trade is the right one when the shared logic is large, correctness across platforms matters more than UI development speed, and the targets include ones that most cross-platform UI frameworks serve poorly. It would be the wrong one for a content-only app (see the quiz above) or a team that needs to ship one mobile app fast.
Failure modes to plan for
- The framework lags the platform. New OS features (a design refresh, a new widget type, a new permission model) arrive in native SDKs first. Budget for native modules or waiting.
- The abstraction leaks at the edges. Text input, accessibility, keyboard handling, deep links and background work are where cross-platform UI frameworks most often need platform-specific code.
- The shared layer becomes a bottleneck. Whatever is shared (a Kotlin module, a Rust core, a JS layer) needs owners and a stable interface, or every feature waits on it.
- Rewrites are expensive. The decision tends to last the life of the product. Make it with the constraints you'll have in two years, not just this quarter.
Recap
- Decide by hard constraints: platform API depth, UI fidelity, targets, data complexity, team, distribution, in roughly that order.
- Separate the question of shared logic (KMP, Rust + UniFFI, React Native's JS layer) from shared UI (React Native, Flutter, Compose Multiplatform).
- PWAs are the lowest-cost option when the app fits what the web can do on iOS; check background work, storage and device APIs first.
- A shared core with native UIs, like OfflineOwl's Rust
owl-corewith SwiftUI and Compose Multiplatform, buys one implementation of the hard logic at the cost of a build matrix, an FFI contract and several UI codebases. - Prototype the riskiest integration before committing; the choice usually outlives the people who made it.
Finished this lesson?
Mark it complete to track your progress on this device.