[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M74FV0EA058XMC31YR0799P0":3,"skill-same:01M74FV0EA058XMC31YR0799P0":49},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":20,"frontMatter":21,"refName":22,"commitSha":23,"skillDirectory":24,"forksCount":13,"repositoryHtmlUrl":25,"repositoryHomepageUrl":6,"ownerHtmlUrl":26,"ownerBlogUrl":6,"ownerDescription":27,"updatedAt":28,"install":29,"resources":42},"01M74FV0EA058XMC31YR0799P0","koin-kmp",null,"Astrumon\u002Fspovishun-skills","Astrumon","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F67917191?v=4","01M74FSGPFMM3XWY2PMSEN8Z2W","Danylo Bidnyk","01M74FSGQ12JX4QM4FEY6NEH6N",0,"MIT","https:\u002F\u002Fgithub.com\u002FAstrumon\u002Fspovishun-skills\u002Fblob\u002Fmain\u002Fskills\u002Fkoin-kmp\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"# Koin for KMP Skill\n\nKoin wiring in a Kotlin Multiplatform project: what belongs in `commonMain` versus behind\n`expect val platformModule: Module`, obtaining a ViewModel in a Compose Multiplatform screen, scopes,\nClassic DSL versus KSP annotations, and turning a missing binding into a failing test rather than a\nruntime crash.\n\nLayer boundaries and the dependency direction are normative — see `.claude\u002Frules\u002Fkmp\u002Farchitecture.md`\nand `.claude\u002Frules\u002Fkmp\u002Fmodularization.md`. This skill wires against those rules; it does not restate\nthem.\n\n## Supersedes `dependency-injection-architecture` in KMP projects\n\n`dependency-injection-architecture` is gated `requires: [kotlin]`, so it installs here too, but three\nof its Always-Active Rules are backend-specific and **wrong for KMP**. In a KMP project this skill\nwins on exactly these points:\n\n| `dependency-injection-architecture` says | In a KMP project |\n|---|---|\n| `Dependency direction is presentation → domain ← data` | `ui → domain ← data` — see `.claude\u002Frules\u002Fkmp\u002Farchitecture.md` |\n| `Only data\u002Fdb\u002FDatabaseFactory.kt may use Dispatchers.IO` | there is no such file, and `Dispatchers.IO` **does not exist** on native or wasm. Inject a `CoroutineDispatcher` |\n| `Use Service, never UseCase` | the KMP layer rules name the domain orchestration class `UseCase` |\n\nEverything else it says — constructor injection over `by inject()`, interface types for bindings,\nnever inject the container, `CoroutineExceptionHandler` as its own keyed dependency — still holds.\n\n## Scope\n\n**In scope**\n- Module layout across source sets; `expect val platformModule: Module` and its `actual`s.\n- Binding platform-typed dependencies (HTTP engine, `Context`, settings\u002Fkeychain backing).\n- Obtaining a ViewModel or a service inside a `@Composable`.\n- Scopes and when a scope is the wrong tool.\n- Classic DSL versus `koin-annotations` + KSP, and the generated-module accessor.\n- `checkModules()` \u002F `verify()` as a test.\n- Diagnosing `NoDefinitionFoundException` and \"compiles but fails at the call site\".\n\n**Out of scope — hand off, do not answer here**\n- Which layer a class belongs to → `.claude\u002Frules\u002Fkmp\u002Farchitecture.md`\n- Visibility of a DI-bound implementation → `.claude\u002Frules\u002Fkmp\u002Fmodularization.md`\n- Building the `HttpClient` that gets bound → **`ktor-client-kmp`**\n- Choosing and configuring the storage that gets bound → **`kmp-persistence`**\n- Source-set mechanics and `expect`\u002F`actual` in general → **`kmp-multiplatform-specialist`**\n- Writing the tests → **`kmp-testing`**\n- Backend (JVM-only, Exposed\u002FKtor-server) DI → **`dependency-injection-architecture`**\n\n## Procedure\n\n1. **Read the build files first.** `gradle\u002Flibs.versions.toml` and the module's `build.gradle.kts` —\n   report the Koin version **and which `koin-*` artifacts are actually on the classpath**. This is\n   not optional: half of the failures below are a missing artifact, not wrong code.\n2. **Find the existing modules** (`di\u002F` package, `initKoin`\u002F`startKoin` call site) and the current\n   style. Do not introduce a second style.\n3. **Add the binding at the lowest layer that owns the type**, `internal` unless another module\n   consumes it.\n4. **Verify.** Run the module-verification test (below). A binding added without it is unproven.\n\n## Source-set layout\n\nMost bindings are platform-free and belong in `commonMain`. Only genuinely platform-typed ones go\nbehind the platform module:\n\n```kotlin\n\u002F\u002F commonMain\nexpect val platformModule: Module\n\nval appModule = module {\n    single { createHttpClient(get(), BASE_URL) }\n    singleOf(::UserRepositoryImpl) bind UserRepository::class\n    factoryOf(::LoadUserUseCase)\n    viewModelOf(::UserViewModel)\n}\n\n\u002F\u002F androidMain\nactual val platformModule = module {\n    single\u003CHttpClientEngine> { OkHttp.create() }\n    single\u003CCoroutineDispatcher> { Dispatchers.IO }\n}\n\n\u002F\u002F iosMain\nactual val platformModule = module {\n    single\u003CHttpClientEngine> { Darwin.create() }\n    single\u003CCoroutineDispatcher> { Dispatchers.Default }   \u002F\u002F no Dispatchers.IO on native\n}\n```\n\nThe dispatcher binding is the KMP-specific one: `Dispatchers.IO` exists only on JVM\u002FAndroid, so a\nclass that hardcodes it does not compile for native or wasm. Bind it per platform and inject it.\n\n**iOS startup.** Swift reserves `init`, so the shared entry point is normally named `doInitKoin` and\ncalled from `iOSApp.init()` as `InitKoinKt.doInitKoin(config: nil)`.\n\n> **Unverified** — no consumer project here declares an iOS target; the iOS lines above are adapted\n> from `rcosteira79\u002Fandroid-skills` → `koin\u002FSKILL.md`.\n\n## Compose: `koinViewModel`, not `koinInject`\n\n`koinInject\u003CT>()` resolves through the ordinary graph and returns a `single`\u002F`factory` instance. Used\nfor a ViewModel it produces one with **no `ViewModelStoreOwner`**: it is not scoped to the navigation\nentry, `onCleared()` never runs at the right moment, and a `single` binding makes the \"ViewModel\"\noutlive the screen entirely, carrying stale state back on re-entry.\n\n```kotlin\n\u002F\u002F wrong — no ViewModel store, no lifecycle\nval viewModel: UserViewModel = koinInject()\n\n\u002F\u002F right — scoped to the nav entry\nval viewModel: UserViewModel = koinViewModel()\nval detail: DetailViewModel = koinViewModel { parametersOf(userId) }\n```\n\n`koinViewModel` lives in **`koin-compose-viewmodel`** (KMP) or `koin-androidx-compose` (Android-only).\n`koin-core` and `koin-compose` alone do not provide it — which is why a project missing that artifact\n\"has to\" use `koinInject`. That is a missing dependency, not a style choice: add the artifact.\nWithout the right artifact `koinViewModel` fails at the call site rather than at compile time.\n\nFor plain services, defaulting the parameter keeps the composable testable:\n\n```kotlin\n@Composable\nfun UserScreen(analytics: AnalyticsService = koinInject()) { … }\n```\n\n## Classic DSL vs KSP annotations\n\nPick one per module; mixing inside a single module is what breaks. The accessor most often missed is\nthat `@Module @ComponentScan class UserModule` is passed as **`UserModule().module`**:\n\n```kotlin\n@Single class UserRepositoryImpl(private val service: UserService) : UserRepository\n@Factory class UserFormValidator\n@KoinViewModel class UserDetailViewModel(\n    @InjectedParam private val userId: String,\n    private val repository: UserRepository,\n) : ViewModel()\n\n@Module @ComponentScan(\"com.example.feature.user\") class UserModule\n\u002F\u002F startKoin { modules(UserModule().module) }\n```\n\nAnnotations need `koin-annotations` + the `koin-ksp-compiler` wired per target. Classic DSL needs no\ncodegen and stays readable in a small graph — prefer it unless the module is large enough that the\nboilerplate is the actual problem.\n\n## Scopes\n\nA scope is for state with a lifetime **between** \"one call\" and \"the whole app\" — a multi-step flow\nkeyed by an id, for example. Own it explicitly and close it:\n\n```kotlin\nval scope = getKoin().createScope\u003CCheckoutFlow>(\"checkout-$orderId\")\nval cart: CheckoutCart = scope.get()\n\u002F\u002F …\nscope.close()\n```\n\nA scope that is never closed is a leak that no test catches. If the lifetime you want is \"this\nscreen\", that is what `koinViewModel` already gives you — use it instead.\n\n## Verification as a test\n\n`checkModules()` walks every declaration's constructor and fails when a dependency is not declared,\nturning a runtime `NoDefinitionFoundException` into a red test.\n\n```kotlin\n\u002F\u002F commonTest\nclass ModuleVerificationTest {\n    @Test\n    fun should_resolve_every_declaration() {\n        koinApplication { modules(appModule, platformModule) }.checkModules()\n    }\n}\n```\n\nFor constructor parameters supplied at runtime (`SavedStateHandle`, a `parametersOf` value), declare\nthem with `verify(extraTypes = listOf(SavedStateHandle::class))` — otherwise verification fails on a\nbinding that is actually correct.\n\n## Do NOT\n\n- Do NOT use `koinInject()` for a ViewModel — use `koinViewModel()` and add the artifact.\n- Do NOT bind a ViewModel as `single`; it then survives navigation with stale state.\n- Do NOT hardcode `Dispatchers.IO` inside a class — it does not exist on native\u002Fwasm. Inject it.\n- Do NOT put a platform type in `commonMain` bindings; that is what `platformModule` is for.\n- Do NOT inject `Koin`, `Scope` or `KoinComponent` into a class — that is the service-locator\n  anti-pattern back in disguise.\n- Do NOT mix Classic DSL and annotations inside one module.\n- Do NOT widen a binding's implementation class to `public` just to declare it — declarations see\n  `internal` types within the same module.\n- Do NOT create a scope you have no code path to close.\n\n## Error handling\n\n- **`NoDefinitionFoundException` at runtime** → the graph is unverified. Add `checkModules()` first,\n  then fix the binding it names.\n- **`koinViewModel` unresolved or failing at the call site** → report the missing artifact\n  (`koin-compose-viewmodel`) and its catalog entry; do not work around it with `koinInject`.\n- **`checkModules()` fails on a runtime-supplied parameter** → add `extraTypes`; do not delete the\n  test.\n- **An `actual platformModule` is missing for a declared target** → name the target and the missing\n  bindings, and hand source-set mechanics to **`kmp-multiplatform-specialist`**.\n- **The question is about layering, not wiring** → point at `.claude\u002Frules\u002Fkmp\u002Farchitecture.md` and\n  stop.\n\n## Example\n\n> \"Add a settings screen backed by a repository that reads from encrypted storage.\"\n\n1. Read `libs.versions.toml`; report the Koin version and whether `koin-compose-viewmodel` is\n   present. If it is not, propose the catalog entry before writing any Compose code.\n2. Bind the storage in `platformModule` per target (encrypted on Android, keychain on iOS, plain on\n   Desktop) — the choice itself belongs to **`kmp-persistence`**.\n3. Bind `SettingsRepositoryImpl` as `internal` behind the `public` `SettingsRepository` interface in\n   `commonMain`.\n4. Declare `viewModelOf(::SettingsViewModel)` and obtain it in the screen with `koinViewModel()`.\n5. Extend the module-verification test to include the new module; run it and report the output.\n\nExpected outcome: the graph verifies in `commonTest`, and no platform type appears in `commonMain`.\n\n## Related Skills\n\n- `kmp-multiplatform-specialist` — source sets, `expect`\u002F`actual`, targets\n- `ktor-client-kmp` — the client and engine that get bound\n- `kmp-persistence` — choosing the storage behind the binding\n- `kmp-testing` — fakes, `commonTest` placement, overriding bindings in tests\n- `kotlin-specialist` — dispatchers, scopes, `CoroutineExceptionHandler`\n- `dependency-injection-architecture` — the backend (JVM-only) counterpart\n",{},"main","4ad702b3d4f403306c1a016277020693dd669f55","skills\u002Fkoin-kmp","https:\u002F\u002Fgithub.com\u002FAstrumon\u002Fspovishun-skills","https:\u002F\u002Fgithub.com\u002FAstrumon","Software Engineer","2026-10-14 01:01:46",{"source":7,"skillName":5,"commands":30,"prompt":40,"zipAvailable":41},[31,34,37],{"tool":32,"command":33},"npx","npx skills add Astrumon\u002Fspovishun-skills --skill koin-kmp",{"tool":35,"command":36},"bunx","bunx skills add Astrumon\u002Fspovishun-skills --skill koin-kmp",{"tool":38,"command":39},"pnpm","pnpm dlx skills add Astrumon\u002Fspovishun-skills --skill koin-kmp","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FAstrumon\u002Fspovishun-skills\u002Fblob\u002Fmain\u002Fskills\u002Fkoin-kmp\u002FSKILL.md",true,[43],{"path":44,"resourceType":45,"resourceTypeDesc":46,"sizeBytes":47,"sourceHtmlUrl":48},"manifest.yaml","REFERENCE","参考文档",1065,"https:\u002F\u002Fgithub.com\u002FAstrumon\u002Fspovishun-skills\u002Fblob\u002Fmain\u002Fskills\u002Fkoin-kmp\u002Fmanifest.yaml",[50,56,62,69,74,79],{"skillNo":51,"name":52,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":18},"01M74FX71JH2KNG5KX7TZHSKCB","universal-skill","https:\u002F\u002Fgithub.com\u002FAstrumon\u002Fspovishun-skills\u002Fblob\u002Fmain\u002Ftest\u002Ffixtures\u002Fsource\u002Fskills\u002Funiversal-skill\u002FSKILL.md",[],[],{"skillNo":57,"name":58,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":18},"01M74FX57GTEFPJVCPWPSP6CCW","notion-skill","https:\u002F\u002Fgithub.com\u002FAstrumon\u002Fspovishun-skills\u002Fblob\u002Fmain\u002Ftest\u002Ffixtures\u002Fsource\u002Fskills\u002Fnotion-skill\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":18},"01M74FX30F3K8906P5ASQ3DNXR","inline-frontmatter-skill","Hand-authored description that already lives in the body and must not be double-wrapped.","https:\u002F\u002Fgithub.com\u002FAstrumon\u002Fspovishun-skills\u002Fblob\u002Fmain\u002Ftest\u002Ffixtures\u002Fsource\u002Fskills\u002Finline-frontmatter-skill\u002FSKILL.md",[],[],{"skillNo":70,"name":52,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":18},"01M74FX18AGHM2KHQ502PMJZRJ","https:\u002F\u002Fgithub.com\u002FAstrumon\u002Fspovishun-skills\u002Fblob\u002Fmain\u002Ftest\u002Ffixtures\u002Fsource-v2\u002Fskills\u002Funiversal-skill\u002FSKILL.md",[],[],{"skillNo":75,"name":58,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":18},"01M74FWZJ193G810P0ZJ1PKEZ9","https:\u002F\u002Fgithub.com\u002FAstrumon\u002Fspovishun-skills\u002Fblob\u002Fmain\u002Ftest\u002Ffixtures\u002Fsource-v2\u002Fskills\u002Fnotion-skill\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":18},"01M74FWPNEZWWGQ2Q37N6MMWP1","write-a-skill","https:\u002F\u002Fgithub.com\u002FAstrumon\u002Fspovishun-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwrite-a-skill\u002FSKILL.md",[],[]]