Reflex-style: no shared production code, one shared spec
Context and problem
The game had to run on iPhone, Android and later the web, and play by the official rules and by our family’s house rules. Before any code, the question was how to share the rules between platforms: write them once and share the code, or write them per platform. Two Shopify Engineering articles from the same month described how Shopify rebuilt its app in native Swift and Kotlin, and Reflex, the architecture behind it.
Options considered
- A cross-platform app. One codebase for both phones. The diary lists “native or cross-platform” as one of the first day’s decisions.
- Native apps over one shared core. Native UI, with the rules written once and linked into each app. The records don’t show this being weighed on its own; Reflex rules it out by sharing no production code at all.
- Reflex: native apps, no shared production code, one shared spec. Each platform writes its own logic in its own language, and the tests are the shared artifact.
Decision
We chose option 3, following Shopify as closely as we could:
- Native apps in Swift (SwiftUI) and Kotlin (Compose), each over a UI-free core.
- The rules written separately in each language (Rust joined as the third copy, see 0002).
- One
spec/folder that every platform must pass: rule sets as JSON, so a house rule is data and never anif, plus scenarios, parity vectors and behaviour tests. - The same shape everywhere: state out, actions in, one
updatefunction, and a command-line tool per platform so an agent can drive it without a simulator. - Mirrored names across platforms (
RuleSet.swift,RuleSet.kt,rule_set.rs).
Consequences
Good
- The scenarios keep the copies honest. When two platforms disagree, a scenario fails and the spec decides who is right. The behaviour tests found that Swift accepted JSON with a trailing comma and Kotlin accepted unquoted words, two disagreements no human would have spotted.
- Parity became the backbone: the same PCG32 generator and Fisher–Yates shuffle deal the same hands everywhere, and seeded bot games match hash for hash.
- Writing the family rules down as data (26 rules households disagree on) did more for quality than any review.
Bad
- The rules are written three times. Every rule change, and every new rule-set setting, is added to every rule set and every platform’s model, and each checkpoint needs three builders and a reviewer who checks that the platforms mirror each other.
- The spec only protects what it pins. A behaviour with no scenario can differ between platforms without any test failing.
- Mirroring sometimes beats platform idiom on purpose, which can read oddly to a Swift or Kotlin developer.