TL;DR
- Split your KMP project by feature (games, favorites, profile) and by layer inside each feature (presentation, domain, data).
- Shared infrastructure lives in core modules: network, database, design system, common utilities.
- Follow two rules: features never depend on other features, and domain depends on nothing except core:common.
- Move repeated Gradle setup into convention plugins, so a new module takes a few lines instead of 80.
- Ship one iOS framework from the app module. Don't turn every module into its own framework.
Every KMP project starts the same way: one shared module where everything goes. It's perfect for the
first few screens. Then the app grows, builds slow down, and a change to one screen recompiles everything.
Here's how to split a Kotlin Multiplatform project into modules that scale, and the rules that keep it clean.
Prefer video?Kotlin Multiplatform Modularization: build a scalable KMP multi-module project (2 hours)
00 New here? The basics, in plain words
Who this is for: you can build a simple Android app in Kotlin, and you've heard of Kotlin Multiplatform (KMP). If KMP itself is new to you, read Compose vs Kotlin Multiplatform first. It takes 5 minutes.
What is a module?
Think of your app as a house. When you start a KMP project, the template gives you one big room called
shared, and everything goes in there: screens, network calls, database code, helpers. That's fine for a small flat.
But as the house grows, one giant room gets messy, and every time you repaint one corner, the whole room has to dry again.
A module is a separate room with a door. Technically, it's a folder with its own
build.gradle.kts file. Gradle, the tool that builds your app, compiles each module on its own, and a module can only
use code from the modules it lists as dependencies.
Before: one module
Change one screen โ rebuild everything. Anything can call anything.
After: many small modules
Change one screen โ rebuild one module. Each module has one job.
Here's what one module looks like on disk. In KMP, each module has a folder per platform, called a source set:
feature/games/data/
โโโ build.gradle.kts โ this module's settings and dependencies
โโโ src/
โโโ commonMain/kotlin/ โ shared code: runs on Android, iOS and Desktop
โโโ androidMain/kotlin/ โ Android-only code (if needed)
โโโ iosMain/kotlin/ โ iOS-only code (if needed)
What does "depends on" mean?
If module A depends on B, code in A can use classes and functions from B. It only works in one direction:
B can't see A. You declare it in A's build.gradle.kts with a line like implementation(projects.core.network).
The whole point of modularization is choosing these arrows carefully.
What are "layers"?
Inside each feature, we split code by its job. A restaurant is a good way to picture it:
presentation = the waiter
Talks to the customer: screens and ViewModels. Takes orders and shows results, but never cooks.
domain = the menu
The rules of the business: what a Game is, what you can do with it. Doesn't care where ingredients come from.
data = the kitchen
Fetches the ingredients: API calls and the database. The waiter never walks into the pantry.
Keep this picture in mind. Everything below is just these three ideas, applied carefully: rooms, doors and jobs.
01 Why modularize at all?
A single shared module works until it doesn't. Splitting it up gives you four concrete wins:
Faster builds
Gradle only recompiles modules that changed, and their dependents. Touch one feature, rebuild one feature.
Real boundaries
If presentation can't see data, nobody can call the database from a screen "just this once".
Team ownership
Different people can own different features without merge conflicts in one giant module.
The fourth win is specific to KMP: modules make it obvious which code is truly shared and which is platform-specific, because each module declares its own targets and source sets.
02 The structure: features ร layers
This is the layout I use for real KMP apps, like Gamopedia in my Compose Multiplatform course:
gamopedia/
โโโ composeApp/ โ app entry: Android, Desktop, iOS framework
โโโ iosApp/ โ Xcode project, calls into composeApp
โโโ build-logic/
โ โโโ convention/ โ shared Gradle setup (convention plugins)
โโโ core/
โ โโโ common/ โ dispatchers, Result types, utilities
โ โโโ network/ โ Ktor HttpClient setup
โ โโโ database/ โ SQLDelight driver and schema
โ โโโ designsystem/ โ theme, colors, shared components
โโโ feature/
โโโ games/
โ โโโ domain/ โ models, repository interfaces, use cases
โ โโโ data/ โ repository implementations, DTOs, mappers
โ โโโ presentation/ โ screens and ViewModels
โโโ favorites/
โโโ domain/
โโโ data/
โโโ presentation/
Each layer has one job:
- domain: pure Kotlin. Models, repository interfaces and use cases. No Ktor, no SQLDelight, no Compose.
- data: implements the domain interfaces using core:network and core:database. DTOs never leave this module.
- presentation: Compose Multiplatform screens and ViewModels. Talks only to the domain layer.
Start smaller. For a new app, one module per feature (with packages for the layers) is fine. Split a feature into domain, data and presentation when it grows or gets a second developer.
03 The dependency rules (explore them)
Modules are only useful if the arrows point the right way. Tap any module to see what it contains, what it may depend on, and what it must never depend on.
Tap a module
Green modules are allowed dependencies. Red ones are forbidden.
The two rules that matter most:
- Features never depend on other features. If games needs something from favorites, move it into a core module or a small shared domain module. Otherwise you end up with circular dependencies and lose the build-speed win.
- Domain depends on nothing except core:common. That keeps your business logic easy to test in
commonTestand impossible to tangle with frameworks.
Only the app module sees everything. It wires features together: navigation between screens, and the dependency injection graph.
04 Stop copy-pasting Gradle: convention plugins
With ten modules, you'll have ten nearly identical build.gradle.kts files: the same targets, the same
Android SDK levels, the same dependencies. A convention plugin puts that setup in one place.
In plain words: a convention plugin is a cookie cutter for modules. You describe once how a KMP module should be set up (which platforms, which Android version), give it a name like awh.kmp.library, and every module just says "use that cutter".
It takes three steps. Step 1: in settings.gradle.kts (the file that lists every module in your project), tell Gradle about a separate build-logic folder where the plugin lives:
pluginManagement {
includeBuild("build-logic")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
// Lets you write projects.core.network instead of project(":core:network")
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
include(":composeApp")
include(":core:common", ":core:network", ":core:database", ":core:designsystem")
include(":feature:games:domain", ":feature:games:data", ":feature:games:presentation")
include(":feature:favorites:domain", ":feature:favorites:data", ":feature:favorites:presentation")
Step 2: write the plugin. Don't worry about every line. Read it as a list of instructions: "apply the KMP and Android plugins, target Android, iOS and Desktop, and use these Android settings."
class KmpLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {
with(pluginManager) {
apply("org.jetbrains.kotlin.multiplatform")
apply("com.android.library")
}
extensions.configure<KotlinMultiplatformExtension> {
androidTarget()
iosX64()
iosArm64()
iosSimulatorArm64()
jvm("desktop")
}
extensions.configure<LibraryExtension> {
compileSdk = 35
defaultConfig.minSdk = 24
// Namespace from the module path, e.g. com.example.feature.games.data
namespace = "com.example" + path.replace(':', '.').replace('-', '_')
}
}
}
Step 3: register the plugin under a name, so modules can use it:
plugins {
`kotlin-dsl`
}
dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
}
gradlePlugin {
plugins {
register("kmpLibrary") {
id = "awh.kmp.library"
implementationClass = "KmpLibraryConventionPlugin"
}
}
}
The payoff: every module's build file is now tiny and only says what's different about it, here just "which other modules do I need?":
plugins {
id("awh.kmp.library")
}
kotlin {
sourceSets.commonMain.dependencies {
implementation(projects.feature.games.domain)
implementation(projects.core.network)
implementation(projects.core.database)
}
}
Newer Android Gradle Plugin versions add a dedicated com.android.kotlin.multiplatform.library plugin for KMP modules. The idea is the same: whichever plugin your project template uses, configure it once in the convention plugin.
05 Wiring it together with Koin
In plain words: a screen needs a repository, but it shouldn't build one itself (it can't even see the data module). Dependency injection means something else creates objects and hands them over. Koin is a popular, beginner-friendly library that does this in KMP. You write small "recipes" for how to create things, and Koin follows them.
Each module writes its own recipes. Here the data module says: "when someone asks for a GameRepository, give them a GameRepositoryImpl":
val gamesDataModule = module {
singleOf(::GameRepositoryImpl) bind GameRepository::class
}
val gamesPresentationModule = module {
viewModelOf(::GameListViewModel)
viewModelOf(::GameDetailViewModel)
}
The app module is the only place that knows about every module, so it starts Koin with all of them:
fun initKoin(config: KoinAppDeclaration? = null) = startKoin {
config?.invoke(this)
modules(
networkModule,
databaseModule,
gamesDataModule,
gamesPresentationModule,
favoritesDataModule,
favoritesPresentationModule,
)
}
Notice that games:presentation asks for a GameRepository interface. It never learns that
GameRepositoryImpl exists. That's the boundary doing its job.
06 What about iOS?
In plain words: iOS apps are written in Swift and built with Xcode, which can't read Kotlin modules directly. So KMP compiles your Kotlin code into a framework, a ready-made package that Xcode can plug in, like a library.
This trips up a lot of teams: don't make every module its own iOS framework. Each Kotlin framework
carries its own copy of the Kotlin runtime, and types from one framework aren't the same types as in another, so
a Game from framework A can't be passed to framework B.
Instead, the app module produces one framework (often called ComposeApp or Shared),
and every feature and core module is simply a dependency of it. If Swift code needs to see a type from a library
module, export just that module:
kotlin {
listOf(iosX64(), iosArm64(), iosSimulatorArm64()).forEach { target ->
target.binaries.framework {
baseName = "ComposeApp"
isStatic = true
// Only if Swift needs these types directly
export(projects.feature.games.domain)
}
}
sourceSets.commonMain.dependencies {
implementation(projects.feature.games.presentation)
implementation(projects.feature.favorites.presentation)
api(projects.feature.games.domain) // required for export()
}
}
With Compose Multiplatform UI, Swift usually needs almost nothing: one function that returns the root view controller.
07 Common mistakes
Mistake Feature modules depending on each other.
It starts with one import and ends with circular dependencies and a build that recompiles half the app. Move the shared piece to core, and let the app module handle navigation between features.
Mistake A "core" module that holds everything.
If core contains networking, database, UI components and business logic, you've just renamed shared. Keep core modules small and focused on one concern each.
Mistake DTOs leaking into the UI.
If a screen uses GameDto straight from the API, every backend change breaks your UI. Map DTOs to domain models inside the data module.
Mistake Splitting too early.
Thirty modules for a five-screen app adds Gradle overhead with no benefit. Start with features, then split layers when a feature grows.
08 Jargon buster
Tap any term you're unsure about.
Gradle
The build tool for Android and KMP projects. It compiles your code, downloads libraries and packages your app. You configure it with .gradle.kts files written in Kotlin.
Module
A folder with its own build.gradle.kts. Gradle builds it separately, and it can only use code from the modules it declares as dependencies.
Source set (commonMain, androidMain, iosMain)
Folders inside a KMP module. Code in commonMain is shared by every platform; code in androidMain or iosMain only runs on that platform.
expect / actual
A KMP feature for platform differences: you expect a function in common code, and provide the actual version for each platform.
Interface vs implementation
An interface (like GameRepository) is a promise: "I can give you games." The implementation (GameRepositoryImpl) is the code that actually keeps the promise. Screens only know the promise.
DTO
Data Transfer Object: a class shaped exactly like the JSON your API returns. It stays in the data layer and gets converted into a clean domain model.
Dependency injection (DI) and Koin
DI means objects receive what they need instead of creating it themselves. Koin is a lightweight DI library that works in KMP.
Convention plugin
Your own small Gradle plugin that holds shared module setup, so you don't copy the same configuration into every module.
iOS framework
The package KMP produces so an Xcode (Swift) project can use your Kotlin code.
09 Your KMP modularization checklist
- Features split by feature, then by layer when they grow
- Shared infrastructure in small, focused
coremodules - No feature-to-feature dependencies
- Domain modules are pure Kotlin and depend only on core:common
- Convention plugins in
build-logicinstead of copy-pasted Gradle - One Koin module per module, assembled in the app
- One iOS framework, from the app module
Build it for real
Compose Multiplatform: Build Gamopedia
Build a feature + layer modularized KMP app with Koin, Ktor Client and SQLDelight, and run it on Android, iOS and Desktop.

