← Back to list

kotlin-multiplatform-architecture
by ShotaIuchi
⭐ 0🍴 0📅 Jan 25, 2026
SKILL.md
name: Kotlin Multiplatform Architecture description: This skill should be used when implementing KMP features, creating shared modules, using expect/actual, setting up Koin/SQLDelight/Ktor, or implementing Compose Multiplatform. references:
- path: ../../references/common/clean-architecture.md
- path: ../../references/common/testing-strategy.md
- path: ../../references/languages/kotlin/coroutines.md
- path: ../../references/languages/kotlin/kmp-architecture.md external:
- id: kmp-docs
- id: compose-multiplatform
- id: kotlin-coroutines
Kotlin Multiplatform Architecture
Multiplatform development patterns based on Kotlin official documentation and Google's KMP recommendations.
Core Principles
- Share Business Logic - Place Domain/Data Layer in shared module
- Minimize Platform-Specific Code - Abstract with expect/actual
- Single Source of Truth (SSOT) - Repository in shared module is the SSOT for data
- Unidirectional Data Flow (UDF) - Events flow upstream, state flows downstream
- Dependency Direction - Shared module does not depend on platform
Platform UI → Shared (Presentation → Domain → Data)
Layer Structure
| Layer | Responsibility | Key Components |
|---|---|---|
| Presentation | UI state and logic (shared) | SharedViewModel, UiState |
| Domain | Business logic | UseCase, Domain Model |
| Data | Data retrieval and persistence | Repository, DataSource, API |
Module Structure
| Module | Responsibility | Tech Stack |
|---|---|---|
| shared | All business logic | Koin, Ktor, SQLDelight |
| androidApp | Android UI | Jetpack Compose |
| iosApp | iOS UI | SwiftUI / Compose MP |
| desktopApp | Desktop UI | Compose MP |
Directory Structure
shared/
├── commonMain/kotlin/ # Common to all platforms
│ ├── presentation/
│ ├── domain/
│ └── data/
├── androidMain/kotlin/ # Android-specific (expect/actual)
├── iosMain/kotlin/ # iOS-specific (expect/actual)
└── commonTest/kotlin/ # Common tests
expect/actual Pattern
// commonMain
expect class PlatformContext
// androidMain
actual typealias PlatformContext = android.content.Context
// iosMain
actual class PlatformContext(val nsObject: platform.darwin.NSObject? = null)
Platform-Specific Implementation Example
// commonMain
expect fun getPlatformName(): String
// androidMain
actual fun getPlatformName(): String = "Android ${android.os.Build.VERSION.SDK_INT}"
// iosMain
actual fun getPlatformName(): String = platform.UIKit.UIDevice.currentDevice.systemName()
Naming Conventions
| Type | Pattern | Example |
|---|---|---|
| SharedViewModel | {Feature}ViewModel | UserListViewModel |
| UI State | {Feature}UiState | UserListUiState |
| UseCase | {Action}{Entity}UseCase | GetUsersUseCase |
| Repository | {Entity}Repository | UserRepository |
| Platform Class | Platform{Component} | PlatformContext, PlatformLogger |
| expect/actual | {Platform}{Feature} | AndroidDatabase, IosDatabase |
Compose Multiplatform
// commonMain - Shared UI
@Composable
fun UserListScreen(viewModel: UserListViewModel) {
val state by viewModel.uiState.collectAsState()
// Shared composable implementation
}
- Use
@Composablefunctions in commonMain for shared UI - Platform-specific styling via expect/actual for resources
- Navigation handled per-platform or via shared navigation library
DI with Koin
// commonMain
val commonModule = module {
single { UserRepository(get()) }
factory { GetUsersUseCase(get()) }
}
// androidMain
val androidModule = module {
single<DatabaseDriver> { AndroidSqliteDriver(Database.Schema, get(), "app.db") }
}
// iosMain
val iosModule = module {
single<DatabaseDriver> { NativeSqliteDriver(Database.Schema, "app.db") }
}
Testing Strategy
| Test Type | Location | Purpose |
|---|---|---|
| Unit Tests | commonTest | Shared business logic |
| Platform Tests | androidTest/iosTest | Platform-specific implementations |
| Integration Tests | commonTest | Repository and DataSource interactions |
Detailed References
Score
Total Score
50/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
Reviews
💬
Reviews coming soon