スキル一覧に戻る
ShotaIuchi

kotlin-multiplatform-architecture

by ShotaIuchi

0🍴 0📅 2026年1月25日
GitHubで見るManusで実行

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

  1. Share Business Logic - Place Domain/Data Layer in shared module
  2. Minimize Platform-Specific Code - Abstract with expect/actual
  3. Single Source of Truth (SSOT) - Repository in shared module is the SSOT for data
  4. Unidirectional Data Flow (UDF) - Events flow upstream, state flows downstream
  5. Dependency Direction - Shared module does not depend on platform
Platform UI → Shared (Presentation → Domain → Data)

Layer Structure

LayerResponsibilityKey Components
PresentationUI state and logic (shared)SharedViewModel, UiState
DomainBusiness logicUseCase, Domain Model
DataData retrieval and persistenceRepository, DataSource, API

Module Structure

ModuleResponsibilityTech Stack
sharedAll business logicKoin, Ktor, SQLDelight
androidAppAndroid UIJetpack Compose
iosAppiOS UISwiftUI / Compose MP
desktopAppDesktop UICompose 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

TypePatternExample
SharedViewModel{Feature}ViewModelUserListViewModel
UI State{Feature}UiStateUserListUiState
UseCase{Action}{Entity}UseCaseGetUsersUseCase
Repository{Entity}RepositoryUserRepository
Platform ClassPlatform{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 @Composable functions 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 TypeLocationPurpose
Unit TestscommonTestShared business logic
Platform TestsandroidTest/iosTestPlatform-specific implementations
Integration TestscommonTestRepository and DataSource interactions

Detailed References

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

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

レビュー

💬

レビュー機能は近日公開予定です