<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Andrea on Medium]]></title>
        <description><![CDATA[Stories by Andrea on Medium]]></description>
        <link>https://medium.com/@andrea07021981?source=rss-a5505d3e4991------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Andrea on Medium</title>
            <link>https://medium.com/@andrea07021981?source=rss-a5505d3e4991------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:57:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andrea07021981/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Structure a Real Kotlin Multiplatform App Before You Write Your First Feature]]></title>
            <link>https://medium.com/@andrea07021981/how-to-structure-a-real-kotlin-multiplatform-app-before-you-write-your-first-feature-202dad47a732?source=rss-a5505d3e4991------2</link>
            <guid isPermaLink="false">https://medium.com/p/202dad47a732</guid>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <dc:creator><![CDATA[Andrea]]></dc:creator>
            <pubDate>Fri, 03 Jul 2026 12:57:44 GMT</pubDate>
            <atom:updated>2026-07-03T16:59:00.591Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Observability is the walkthrough — analytics, crash, perf, remote config — but the layout is vendor-neutral and reusable for auth, networking, persistence, and anything else you add next.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hYXetlzpNlqK8sdczjXNeg.png" /></figure><p><em>Figure 1 — Event flow: contracts in </em><em>api, seam in </em><em>spi, facade in </em><em>impl, vendor code only in provider modules.</em></p><p>Every Kotlin Multiplatform tutorial ends right where the hard part begins.</p><p>You get a blank Compose screen, a println(&quot;Hello, world!&quot;), and a pat on the back. Then you try to ship something real — observability on mobile, sensible no-ops on desktop and web, dependency injection that survives dozens of modules, and CI that builds all five targets — and the tutorial architecture folds like wet cardboard.</p><p>I built KMP-Umbrella-Template to answer the question no “Hello, world” ever does:</p><blockquote>What does a real Kotlin Multiplatform app look like at medium to large project scale?</blockquote><p>This article walks through that structure. Observability is the demo feature — not because it’s glamorous, but because it’s the perfect stress test: every platform has a different SDK, every team eventually wants to swap vendors, and every screen needs to fire events without knowing what’s behind the curtain. We use Firebase on Android and iOS only as the example provider; the same api / spi / impl split works for auth, networking, or any cross-cutting concern.</p><p>Get the module layout right once, and you can repeat it forever.</p><h3>The trap: coupling shared code to a vendor</h3><p>When teams bolt platform services onto KMP, they usually pick one of three paths:</p><ol><li>Adapters inside the umbrella module — simple, but shared code becomes vendor-aware overnight.</li><li>SDKs wired into each app — flexible, but you duplicate bindings and drift between platforms.</li><li>Dedicated provider modules — more Gradle files upfront, the cleanest boundary long-term.</li></ol><p>This template commits to Option 3. Shared code stays vendor-neutral. Providers are plug-in modules. The dependency graph assembles them at compile time, based on which platform you’re building.</p><p>It’s the same modularization instinct behind <a href="https://ralf-wondratschek.com/presentation/android-at-scale-at-square.html">Square’s “Android at scale” </a>work — small modules, clear contracts, composed at the edges — adapted to KMP’s defining constraint: <em>you ship to five runtimes from one repo.</em></p><h3>What’s in the box</h3><ul><li>Compose Multiplatform UI in sharedUI</li><li>Metro DI with Anvil-style aggregation across modules</li><li>Modular observability, split into api / spi / impl</li><li>Firebase on Android + iOS via dedicated provider modules <em>(demo provider only)</em></li><li>No-op providers so desktop and web compile without any mobile SDK</li><li>An iOS-only umbrella framework that exports clean APIs to Swift</li><li>Convention plugins in build-logic so every module shares one KMP + Metro setup</li><li>CI via Fastlane lanes and GitHub Actions</li></ul><p>Targets: Android, iOS, Desktop (JVM), JS, and Wasm — following JetBrains’ <a href="https://blog.jetbrains.com/kotlin/2026/05/new-kmp-default-structure/">new KMP default structure</a>: one shared UI library, per-platform entry points, and a hard line between <em>what the app does</em> and <em>how the platform boots.</em></p><h3>The module map</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sR31Z5PSv-iDnMdmH-REfw.png" /></figure><p><em>Figure 2 — Module map: apps → </em><em>sharedUI + </em><em>shared/di; providers plug in per platform source set.</em></p><pre>KMP-Umbrella-Template/<br>├── androidApp/                         → Android entry point<br>├── iosApp/                             → SwiftUI entry point (links SharedUmbrella.framework)<br>├── desktopApp/                         → JVM Compose entry point<br>├── webApp/                             → JS + Wasm Compose entry point<br>├── sharedUI/                           → Compose Multiplatform UI<br>├── shared/<br>│   ├── di/                             → Metro dependency graphs (all platforms)<br>│   ├── umbrella/                       → iOS-only framework packaging<br>│   ├── observability/<br>│   │   ├── api/                        → Contracts (AnalyticsLogger, ObservabilityGraph)<br>│   │   ├── spi/                        → Platform seam (AnalyticsPlatform)<br>│   │   └── impl/                       → Defaults (DefaultAnalyticsLogger)<br>│   └── core/                           → Domain, foundation, logger<br>├── platform-observability-firebase/    → Demo provider (Firebase adapters)<br>├── platform-observability-noop/        → No-op bindings for non-mobile<br>└── build-logic/                        → Convention plugins</pre><p>One idea holds the whole thing together:</p><blockquote>Feature code never imports a vendor SDK. It imports AnalyticsLogger from observability-api. Which implementation gets wired — Firebase, Datadog, or a no-op — is a compile-time decision made in shared/di.</blockquote><h3>The pattern: api → spi → impl → provider</h3><p>Three layers. Follow one analytics event from tap to SDK.</p><h3>Layer 1: API — what your features see</h3><p>The observability-api module defines the public contract. Feature modules and UI depend only on this:</p><pre>public interface AnalyticsEvent {<br>  public val name: String<br>  public val params: Map&lt;String, Any&gt;<br>}<br>public interface AnalyticsLogger {<br>  public fun track(event: AnalyticsEvent)<br>}</pre><p>Events are typed objects, not magic strings — self-documenting, refactor-safe, and unit-testable without a device:</p><pre>object SampleAnalyticsEvent : AnalyticsEvent {<br>  override val name = &quot;test_event&quot;<br>  override val params = mapOf(<br>    &quot;screen&quot; to &quot;App&quot;,<br>    &quot;action&quot; to &quot;tap&quot;,<br>    &quot;param1&quot; to &quot;value1&quot;,<br>    &quot;param2&quot; to 123,<br>    &quot;param3&quot; to true,<br>  )<br>}</pre><h3>Layer 2: SPI — the platform seam</h3><p>The observability-spi module holds the Service Provider Interface — the boundary between shared logic and platform SDKs:</p><pre>public interface AnalyticsPlatform {<br>  public fun logEvent(name: String, params: Map&lt;String, Any&gt;)<br>}</pre><p>This is the socket. Any vendor plugs into it. The SPI module depends on nothing vendor-specific.</p><h3>Layer 3: Impl — the thin glue</h3><p>observability-impl provides DefaultAnalyticsLogger, which delegates to whatever AnalyticsPlatform Metro injects:</p><pre>@ContributesBinding(<br>  scope = AppScope::class,<br>  binding = binding&lt;AnalyticsLogger&gt;(),<br>)<br>class DefaultAnalyticsLogger(<br>  private val platform: AnalyticsPlatform,<br>) : AnalyticsLogger {<br>    override fun track(event: AnalyticsEvent) {<br>      platform.logEvent(event.name, event.params)<br>    }<br>}</pre><p>AnalyticsLogger is what your Composables call. AnalyticsPlatform is what the provider implements.</p><p>On mobile, the chain is full. On desktop and web, it short-circuits:</p><p>Mobile: UI → AnalyticsLogger → DefaultAnalyticsLogger → AnalyticsPlatform → Provider adapter → SDK</p><p>Non-mobile: UI → AnalyticsLogger → NoOpAnalyticsLogger → (nothing)</p><p>Desktop and Wasm don’t need Firebase stubs. They need compilable, testable no-ops — and they get them.</p><h3>Provider modules: where vendor code actually lives</h3><p>Vendor adapters live in standalone Gradle modules at the repo root — platform-observability-firebase in this demo — never buried inside shared/.</p><p>Android maps Kotlin values into an Android Bundle and calls the SDK:</p><pre>@ContributesBinding(<br>  scope = AppScope::class,<br>  binding = binding&lt;AnalyticsPlatform&gt;(),<br>)<br>class FirebaseAnalyticsPlatform(<br>  private val firebase: FirebaseAnalytics,<br>) : AnalyticsPlatform {<br>    override fun logEvent(name: String, params: Map&lt;String, Any&gt;) {<br>      val bundle = Bundle()<br>      params.forEach { (key, value) -&gt;<br>        when (value) {<br>          is String -&gt; bundle.putString(key, value)<br>          is Int -&gt; bundle.putInt(key, value)<br>          // Long, Double, Float, Boolean…<br>          else -&gt; bundle.putString(key, value.toString())<br>        }<br>      }<br>      firebase.logEvent(name, bundle)<br>    }<br>}</pre><p>iOS uses Kotlin’s swiftPMDependencies to import the SDK via Swift Package Manager (no CocoaPods) and bridges to the native analytics API. Same @ContributesBinding contract, different runtime.</p><p>Because you can’t @Inject a third-party singleton, SDK handles come from a separate @Provides container:</p><pre>@ContributesTo(AppScope::class)<br>@BindingContainer<br>object FirebaseSdkBindings {<br>  @Provides<br>  fun provideFirebaseAnalytics(): FirebaseAnalytics = Firebase.analytics<br>}</pre><blockquote>Rule of thumb: @ContributesBinding for code you own. @ContributesTo + @Provides for SDK entry points you don&#39;t control.</blockquote><p>Swap Firebase for Datadog tomorrow? Replace the provider module. api, spi, and impl stay untouched.</p><h3>Metro DI: a graph with no binding list</h3><p>The template uses <a href="https://zacsweers.github.io/metro/latest/">Metro</a> with aggregation — the same mental model as Anvil on Android.</p><p>Every module tags implementations with @ContributesBinding(scope = AppScope::class). A convention plugin enables generateContributionHints, so Metro discovers bindings across the entire compile classpath. No central registry. No 300-line Dagger module.</p><p>The graph declares scope, not implementations:</p><pre>@DependencyGraph(scope = AppScope::class)<br>interface AndroidDependencyGraph : BaseDependencyGraph {<br>  @DependencyGraph.Factory<br>  fun interface Factory {<br>    fun create(): AndroidDependencyGraph<br>  }<br>}</pre><p>Dependencies surface through graph interfaces. ObservabilityGraph is the observability contract:</p><pre>public interface ObservabilityGraph {<br>  public val analyticsLogger: AnalyticsLogger<br>  public val breadcrumbLogger: BreadcrumbLogger<br>  public val crashReporter: CrashReporter<br>  public val performanceTracer: PerformanceTracer<br>  public val remoteConfig: RemoteConfig<br>}</pre><p>BaseDependencyGraph extends it with core dependencies like KMPLogger. Platform graphs (AndroidDependencyGraph, IosDependencyGraph, NonMobileDependencyGraph) implement BaseDependencyGraph.</p><p>The punchline — which provider lands on the classpath is decided in Gradle, not Kotlin:</p><pre>androidMain.dependencies {<br>  implementation(projects.platformObservabilityFirebase)<br>  implementation(projects.shared.observabilityImpl)<br>}<br>nonMobileMain.dependencies {<br>  implementation(projects.platformObservabilityNoop)<br>}</pre><blockquote>No if (platform). No runtime switching. The graph is correct because the build already chose the right modules.</blockquote><h3>One event. Five platforms.</h3><p>Android (Compose)</p><pre>class MainActivity : ComponentActivity() {<br>  override fun onCreate(savedInstanceState: Bundle?) {<br>    val graph = AndroidDependencyGraphFactory.createGraph()<br>      setContent {<br>        App(<br>          onTrackSampleEvent = {<br>            graph.analyticsLogger.track(SampleAnalyticsEvent)<br>          },<br>        )<br>      }<br>  }<br>}</pre><p>Desktop (JVM)</p><pre>fun main() = application {<br>  val graph = NonMobileDependencyGraphFactory.createGraph()<br>    Window(onCloseRequest = ::exitApplication, title = &quot;UmbrellaTemplate&quot;) {<br>      App(<br>        onTrackSampleEvent = {<br>          graph.analyticsLogger.track(SampleAnalyticsEvent)<br>        },<br>      )<br>    }<br>}</pre><p>iOS (SwiftUI) — same graph, exported through the umbrella framework:</p><p>ShareLayerDependency.shared.analyticsLogger.track(event: TestSample())</p><p>Bootstrapped at app launch:</p><pre>public static func initialize() {<br>  instance = Self(graph: IosAppDependencyGraphFactory.shared.createGraph())<br>}</pre><p>Swift can even implement AnalyticsEvent directly — the API is exported from SharedUmbrella.framework.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KM6Q2YM6y4BVSrulm9uFLg.png" /><figcaption>Android — IOS</figcaption></figure><p><em>Figure 3 — Same </em><em>sharedUI on Android and iOS; each app module creates the Metro graph at startup.</em></p><p>The shared UI knows none of this:</p><pre>@Composable<br>fun App(onTrackSampleEvent: () -&gt; Unit = {}) {<br>  Button(onClick = {<br>    onTrackSampleEvent()<br>    showContent = !showContent<br>  }) {<br>      Text(&quot;Click me!&quot;)<br>  }<br>}</pre><p>Same UI everywhere. Bootstrapping stays in each app. sharedUI is pure UI; apps own the wiring.</p><h3>The umbrella is packaging — not a god module</h3><p>A common KMP mistake: making shared depend on everything — Firebase, networking, database drivers — until it&#39;s a tangle nobody can refactor.</p><p>This template draws a hard line:</p><ul><li>shared:di — Metro graphs, used directly by Android, desktop, and web.</li><li>shared:umbrella — iOS-only SharedUmbrella.framework that export()s APIs Swift needs.</li></ul><p>Android, desktop, and web carry a Gradle guard that fails the build if they ever depend on :shared:umbrella. The umbrella exists because iOS wants one framework binary — <em>not</em> because shared logic should pile up there.</p><h3>Testing without a single emulator</h3><p>API contract test — no DI, no platform:</p><pre>@Test<br>fun analyticsEvent_contract() {<br>  val event = object : AnalyticsEvent {<br>    override val name = &quot;screen_view&quot;<br>    override val params = mapOf(&quot;screen&quot; to &quot;home&quot;)<br>  }<br>  assertEquals(&quot;screen_view&quot;, event.name)<br>}<br>Graph smoke test on JVM with no-op providers:<br>@Test<br>fun analyticsLogger_track_noopDoesNotThrow() {<br>  val graph = NonMobileDependencyGraphFactory.createGraph()<br>  graph.analyticsLogger.track(<br>    object : AnalyticsEvent {<br>        override val name = &quot;test_event&quot;<br>        override val params = emptyMap()<br>    },<br>  )<br>}</pre><p>No devices. No Firebase project. No network. That’s the dividend of the api / spi / impl split: fast, deterministic contract tests; integration tests only where SDKs truly matter.</p><h3>Adding your next feature: a five-step recipe</h3><p>The README documents a recipe that mirrors observability:</p><ol><li>Define the API in shared/&lt;feature&gt;/api — interfaces your graph will expose.</li><li>Implement in shared/&lt;feature&gt;/impl with @ContributesBinding(AppScope::class).</li><li>Add platform adapters in platform-&lt;feature&gt;-&lt;vendor&gt; if the feature touches native SDKs.</li><li>Wire the classpath in shared/di/build.gradle.kts — add impl (or platform) to the right source set.</li><li>Extend the graph — add a val to BaseDependencyGraph or a feature-specific graph interface. Metro fails compilation if a binding is missing.</li></ol><p>Do not duplicate the same binding with both @ContributesBinding and @Provides for the same type.</p><blockquote>This is how you grow from observability to auth, networking, persistence, and feature flags — without collapsing into a 200-dependency shared module.</blockquote><p>The repo also ships <a href="https://github.com/andrea07021981/KMP-Umbrella-Template/blob/master/docs/prompts/README.md">AI scaffolding prompts</a> for all three provider-placement options.</p><h3>Convention plugins: consistency at scale</h3><p>Every KMP library module applies one plugin:</p><pre>alias(libs.plugins.convention.kotlinMultiplatform)</pre><p>…and inherits Metro aggregation, target setup, and Android namespace conventions. Add module #15 and you copy-paste nothing.</p><pre>extensions.configure&lt;MetroPluginExtension&gt; {<br>  generateContributionHints.set(true)<br>  generateContributionHintsInFir.set(true)<br>}</pre><p>Small thing. Massive payoff when more than one person touches the repo.</p><h3>Should you use this template?</h3><p>Use it if:</p><ul><li>You’re shipping KMP to multiple platforms in production</li><li>You need cross-cutting infrastructure (observability, auth, etc.) from day one</li><li>You might swap or combine vendors over time</li><li>Your team is comfortable with modular Gradle and compile-time DI</li></ul><p>Skip it if:</p><ul><li>You want a minimal “Hello, world” to learn Compose syntax</li><li>You’re single-platform with no shared code</li><li>You prefer runtime DI (Koin) over compile-time graphs (Metro / Dagger-style)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GCep1dbaVJNpijQuvs7--g.png" /><figcaption><em>Figure 4 — When each architectural boundary is worth it. The larger your surface (platforms, vendors, engineers), the more each one pays off.</em></figcaption></figure><p>It optimizes for architectural clarity at scale — not the smallest possible build.gradle.kts.</p><h3>Get started</h3><p>Prerequisites: JDK 21, Android Studio, Xcode 16+ for iOS.</p><p>git clone <a href="https://github.com/andrea07021981/KMP-Umbrella-Template.git">https://github.com/andrea07021981/KMP-Umbrella-Template.git</a></p><p>cd KMP-Umbrella-Template</p><p>cp androidApp/google-services.json.example androidApp/google-services.json</p><p><em># Edit with your Firebase Android config (demo provider only)</em></p><p>./gradlew :androidApp:assembleDebug <em># Android</em></p><p>./gradlew :desktopApp:run <em># Desktop</em></p><p>./gradlew :webApp:wasmJsBrowserDevelopmentRun <em># Web (Wasm)</em></p><p>For iOS, resolve SwiftPM packages and open iosApp in Xcode. There&#39;s a rename script (scripts/rename-package.sh) and full setup in docs/TEMPLATE.md.</p><p>CI mirrors local builds:</p><p>bundle install</p><p>bundle exec fastlane ci_all</p><h3>Three principles that survived contact with production</h3><p>1. Vendor code belongs at the edges. The moment import com.google.firebase shows up in commonMain, you&#39;ve lost white-labeling and vendor-swapping. Keep it in platform-* modules.</p><p>2. Compile-time wiring beats runtime flags. Firebase on the Android classpath, no-ops on the JVM classpath — and suddenly there’s zero if (Platform.isAndroid) in your feature code. Gradle already solved the platform problem; let it.</p><p>3. Observability is the canary. Structure it cleanly — api, spi, impl, provider, graph — and you can structure anything. Crash reporting, remote config, performance tracing in this template follow the exact same pattern. Copy the module, rename the interfaces, plug in your SDK.</p><p>The hardest part of Kotlin Multiplatform isn’t writing shared code.</p><p>It’s deciding where that code belongs.</p><p>Get the module boundaries right before your first feature, and the hundredth feature becomes routine. Get them wrong, and every new SDK, platform, or engineer raises the cost of change.</p><p>That’s what this template is for.</p><p><em>Apache 2.0 licensed. Fork it, rename the package, and build something that ships on every screen.</em></p><p>⭐ <a href="https://github.com/andrea07021981/KMP-Umbrella-Template">github.com/andrea07021981/KMP-Umbrella-Template</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=202dad47a732" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>