kotlin-multiplatform

Kotlin Multiplatform

Specific best practices and architectural patterns when working with Kotlin Multiplatform.

Details

Language / Topic
kotlinKotlin
Category
framework

Rules

balanced
- Use `expect`/`actual` declarations to share interfaces across platforms while providing platform-specific implementations.
- Place shared business logic in `commonMain`; keep platform-specific code (UI, native APIs) in platform source sets.
- Use `expect`/`actual` declarations for platform abstractions — define the interface in `commonMain`, implement in `androidMain`/`iosMain`.
- Place business logic, data models, and networking in `commonMain`; keep UI and platform APIs in platform-specific source sets.
- Use `kotlinx.coroutines` for async code and `kotlinx.serialization` for JSON — both are multiplatform-compatible.
- Prefer Ktor for HTTP clients in shared code — it supports all KMP targets with platform-specific engines.
- Use `commonTest` for shared unit tests; platform-specific tests go in `androidTest`/`iosTest`.