46+ modules, 37+ expect/actual seams, and the dependency graph rendered straight from the build.
Production Compose Multiplatform — Part 4 of 5. Part 2 — the case study· Part 3 — the invisible store swap.
There’s a moment in every KMP project where you stop asking whether code can be shared and start asking what genuinely can’t be. Getting to that question took us one full rewrite (Part 2 has the before/after numbers). Answering it produced a codebase where 93% of 128,801+ lines live in commonMain — every screen included — and the 7% that doesn't is an enumerable list I can walk you through.
This part is the architecture tour of GeoKrishi Farm as it runs in production today: the module structure, the DI seams, and the platform-bridge patterns for analytics, crash reporting, push, and biometrics. I’ve written before about individual layers — the Ktor networking stack, convention plugins, observability — so this piece is about how the whole thing hangs together.
46+ Modules, Two Kinds
The project is 46+ Gradle modules: 12 core modules, 31+ feature modules, two app shells, and a baseline-profile module, with a build-logic composite build holding two convention plugins (one for plain KMP libraries, one that layers Compose on top).
core/ resources, cache, models, logger, analytics/firebase,
network, platformspecific, utils, ui, appui, permission, video
feature/ login, signup, biometric, weather, farmland, plan, market,
diary, calculators, notification, settings, ... (31 total,
some nested: home/{private,public,shared})
composeApp navigation graph, Koin aggregation, App() root
androidApp 5 files: Activity, Application, FCM service, in-app updates
iosApp 8 Swift files
Three rules make the structure hold instead of decaying:
- Features never depend on features. A feature module may depend on core:*, never on a sibling. Cross-feature flows happen through navigation, not imports. However there are some constraints to this.
- Domain layers are framework-free. No Ktor, no Compose, no platform types inside domain/. Repositories are interfaces there; implementations live in data/.
- expect declarations live in core modules, organized by concern — not scattered wherever someone first needed a platform API. The pragmatic exception: a platform-split composable that only one feature uses (a map component, a WebView wrapper) stays inside that feature.
None of these rules is novel. What’s novel, in my experience, is that module boundaries enforce them. Convention doesn’t survive deadlines. implementation(projects.core.network) does.
And you don’t have to take my word for the graph’s shape. The dependency report published alongside this article was generated straight from the build by Aalekh — the architecture-visualization plugin I built after getting tired of reverse-engineering my own architecture. The premise there applies double here: the real architecture of a multi-module project lives in the Gradle dependency graph, not in any diagram or doc. Diagrams drift. Builds don’t.
What the 7% Actually Buys
The platform code is 37+ expect declarations plus the two app shells. Grouped by concern — the shared abstraction first, then how each platform fulfills it:
- Analytics & push — shared service objects behind an expect/actual seam; the Firebase SDK directly on Android, a Swift @objc bridge on iOS.
- Crash reporting — a sink on the shared logger, wired to Crashlytics (NDK) on Android.
- Biometrics — a shared authenticator + credential vault; BiometricPrompt + Keystore on Android, LAContext + Keychain on iOS.
- Secure storage — one preference-storage abstraction; KVault over the Keystore on Android, over the Keychain on iOS.
- Maps & Places — a shared composable + bridge interface; the Maps Compose SDK on Android, a Swift-implemented Kotlin interface on iOS.
- Media — shared audio and video players; ExoPlayer and a YouTube view on Android, AVPlayer and a WKWebView shim on iOS.
- Device — camera, gallery, contacts, location, share, dial; ActivityResult contracts + FusedLocation on Android, UIImagePickerController + CLLocationManager on iOS.
- Payment — a shared launcher seam; the payment service provider SDK as an .aar on Android and an .xcframework behind a Swift factory on iOS.
- DI — an expect val platformModule per core module; context-carrying registrations on Android, context-free on iOS.
That last item is the quiet backbone. Every platform-touching core module ships its own expect val platformModule, and the app aggregates them: Android boots Koin in the Application with an Android context; iOS boots it idempotently inside the Compose host — right after wiping stale Keychain state (Part 3explains why that wipe exists). Same graph, two doorways in.
One thing is missing from that list because it isn’t platform code so much as platform chrome: on iOS 26 the bottom navigation is a native UITabBar overlaid on this same shared container, switched on by a single CompositionLocal that defaults to off, so the shared code renders its normal bottom bar everywhere else and never learns the native bar exists. It's the sharpest test of whether these seams actually hold, and it opened this series in Part 1.
AnalyticsHelper — An Interface First, expect/actual Second
The mistake I see in most KMP analytics setups is jumping straight to expect fun logEvent(...). That welds every feature to one vendor and makes debug builds pollute production dashboards.
We layered it:
// commonMain -the only thing features ever see
interface AnalyticsHelper {
fun logEvent(event: AnalyticsEvent)
fun setUserId(userId: String?)
fun setUserProperty(name: String, value: String?)
}
// Koin decides the implementation per build type
single<AnalyticsHelper> {
if (isDebugBuild()) StubAnalyticsHelper() else FirebaseAnalyticsHelper()
}
StubAnalyticsHelper just logs locally — debug sessions never touch GA4. FirebaseAnalyticsHelper does something more valuable than forwarding: it enforces GA4's silent truncation limits (40-character event names, 100-character param values, 24/36 for user properties) in common code, once, before anything reaches a platform SDK. Get that wrong per-platform and your dashboards drift apart in ways you only notice months later.
Two more decisions paid off:
- Screen views are logged from one place — a single OnDestinationChangedListener on the navigation controller. No screen composable calls analytics for its own existence. Adding a screen automatically instruments it.
- User IDs are hashed before they’re set. The analytics layer never sees a raw phone number or account ID.
Crash Reporting Rides the Logger
There is no CrashlyticsHelper. There's a logging pipeline (the same one from my observability post), and Crashlytics is a sink on it:
// commonMain
internal expect fun crashlyticsSink(): LogSink?
The Android actual returns a sink that forwards WARN-and-above as breadcrumbs and ERROR-with-throwable as recorded exceptions, wrapped in a sanitizer so nothing sensitive rides along. Features never import a crash-reporting API; they log. Where a report goes is an installation detail decided at startup.
Push and Deep Links: Four Doors, One Hallway
FCM is the bridge with the most platform ceremony, so the design goal was to make the ceremony end as early as possible.
On Android, a FirebaseMessagingService subclass in the app shell receives the message, uploads rotated tokens, and rebuilds the notification. On iOS, the app delegate registers with APNs and receives taps. Two completely different doors — and both immediately hand the raw payload to the same commonMain resolver, which accepts every payload key spelling the backend has ever used and synthesizes routes for legacy payloads that carry only a type. What comes out is one URI, flowing into a small shared handler:
object ExternalUriHandler {
// Holds a URI that arrived before the UI was ready to route it.
private var cached: String? = null
var listener: ((uri: String) -> Unit)? = null
set(value) {
field = value
if (value != null) {
cached?.let { value.invoke(it) } // replay on attach
cached = null
}
}
fun onNewUri(uri: String) {
cached = uri
listener?.let {
it.invoke(uri)
cached = null
}
}
}
Cache the URI, replay it the moment the UI attaches. That closes the cold-start race — a notification tapped before Compose exists still navigates correctly once it does. The same cache-then-replay shape turned out to be reusable: it also carries the in-app-update restart prompt from the Android shell into shared UI.
Push is only two of the four doors. Android registers a custom scheme and verified HTTPS links (with the legacy path variants older shares still use); iOS handles the scheme through onOpenURL plus universal links through NSUserActivityTypeBrowsingWeb. A link tapped in a browser, a chat message, a QR code, or a notification — on either OS — lands in the same handler, resolves through the same rules, and navigates through the same type-safe routes. Adding a linkable screen is one declaration, not a per-platform project.
Biometric Login: The Invariant Is Invalidation
Biometric auth is where “share the interface, not the implementation” gets stress-tested, because the security semantics must match across two very different platform APIs.
The shared surface is two expect classes — an authenticator (can we prompt? what type of sensor?) and a credential vault (seal a secret behind biometrics, unseal it later) — with sealed results:
sealed class UnsealResult {
data class Success(val plaintext: String) : UnsealResult()
object KeyInvalidated : UnsealResult() // biometrics changed since sealing; vault wiped
object NoEnrollment : UnsealResult() // nothing sealed yet, or the vault was cleared
object Cancelled : UnsealResult()
object Failed : UnsealResult()
}
KeyInvalidated is the case that matters. If a fingerprint is added or removed, a stored credential must die — otherwise "biometric login" quietly becomes "whoever enrolls a finger next logs in."
- Android: an AES/GCM key in AndroidKeyStore created with setUserAuthenticationRequired(true) and setInvalidatedByBiometricEnrollment(true), and the prompt is cipher-bound — BiometricPrompt.CryptoObject wraps the cipher, so the OS won't decrypt without a fresh biometric.
- iOS: a Keychain item stored with kSecAccessControlBiometryCurrentSet, which is the same contract in Apple's vocabulary — the item is bound to the biometric set that existed when it was written.
Two implementations, one invariant. The login screen in commonMain handles KeyInvalidated with a re-enroll dialog and has no idea which platform bricked the key. That's the whole point.
Where the Series Goes From Here
Two topics earned their own parts. Firebase and Google Maps forced opposite integration strategies on iOS — header-only cinterop versus a Kotlin interface implemented in Swift — and the decision rule between them is Part 5. The app ships baseline + startup profiles generated from the real first-launch journey on low-end hardware; that harness is Part 6, and it closes the series.
What We’ve Built
- 46+ modules whose boundaries enforce the architecture instead of suggesting it — with the graph rendered from the build to prove it
- 93% of 128,801 lines in commonMain, UI included, with the 7% enumerable: 37 expect seams and two thin app shells
- Analytics behind an interface, vendor limits enforced once in common code
- Crash reporting as a logger sink, not an API features know about
- Push and deep-link routing that’s pure Kotlin behind thin platform doors — custom scheme, universal links, and notification payloads all speaking one grammar
- A biometric vault with matching invalidation semantics on Keystore and Keychain
What’s Next
Part 5: two ways to bridge a native SDK, and how to pick. If you’re weighing Compose Multiplatform for production and something here doesn’t add up — or your shared-code number is counted differently — I’d genuinely like to hear it in the comments.
Drop a ❤️ if this was useful — it helps more developers find the series.

Top comments (0)