{"id":24801596,"url":"https://github.com/futuredapp/arkitekt-kmm","last_synced_at":"2025-10-27T00:40:26.385Z","repository":{"id":40353836,"uuid":"363918617","full_name":"futuredapp/arkitekt-kmm","owner":"futuredapp","description":"KMM library for UseCase abstraction","archived":false,"fork":false,"pushed_at":"2023-02-24T12:59:57.000Z","size":31108,"stargazers_count":44,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-16T12:15:03.117Z","etag":null,"topics":["android","ios","kotlin","kotlin-multiplatform"],"latest_commit_sha":null,"homepage":"https://futuredapp.github.io/arkitekt-kmm","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/futuredapp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-03T12:14:48.000Z","updated_at":"2023-12-08T18:38:50.000Z","dependencies_parsed_at":"2022-08-09T18:01:21.294Z","dependency_job_id":null,"html_url":"https://github.com/futuredapp/arkitekt-kmm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futuredapp%2Farkitekt-kmm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futuredapp%2Farkitekt-kmm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futuredapp%2Farkitekt-kmm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futuredapp%2Farkitekt-kmm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/futuredapp","download_url":"https://codeload.github.com/futuredapp/arkitekt-kmm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236298292,"owners_count":19126500,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","ios","kotlin","kotlin-multiplatform"],"created_at":"2025-01-30T04:29:23.710Z","updated_at":"2025-10-13T03:30:25.401Z","avatar_url":"https://github.com/futuredapp.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Arkitekt kmm\n\n## Km-usecases\n\nIs a Kotlin multiplatform mobile library that helps you with\nabstraction of Usecase as a component from clean architecture.\nIts main objective is separation of concerns and better domain modeling.\nIt is backed by `Kotlinx Coroutines`\n\n### Benefits\n - delegate work to background thread\n - cancel on reexecution (optional)\n - error handling\n - auto-cancel of coroutine context\n \n### Usage\n\nLibrary contains two main parts `UseCase` and `FlowUseCase`. \n- `UseCase` is for events that return single response. (e.g. REST API call GET, POST...)\n- `FlowUseCase` is for events that return multiple responses. (e.g. Location data updates...)\n\n#### UseCase\n\nUseCase same as FlowUseCase has two generic parameters. The first is argument type, the second specify return type.\nIf you don't need any of these, just put `Unit` in there.\nWhen creating a usecase, don't forget to `freeze()` it in init block, but after local parameters initialization.\nIf you use DI, inject before freezing, or you will end up with `InvalidMutabilityException`. This step won't be necessary\nafter release of New Native Memory Model. You can preview it with Kotlin 1.6.0-M1.\n\n#### Define a usecase in common module\n\n```kotlin \n// Common\nclass GetCoinsListUseCase : UseCase\u003cUnit, List\u003cCoin\u003e\u003e() {\n    private val coinStore: CoinStore = CoinStore(RestApiManager, DatabaseManager)\n\n    init {\n        freeze()\n    }\n\n    override suspend fun build(arg: Unit): List\u003cCoin\u003e {\n        return coinStore.fetchCoins().coins.map {\n            Coin(\n                it.id,\n                it.name,\n                it.icon,\n                it.symbol,\n                it.price\n            )\n        }\n    }\n}\n ```\n\n\n#### Consume the Usecase from Android. \nYou can execute the Usecase anywhere you want, but you have to implement the `CoroutineScopeOwner`\ninterface and specify the `coroutineContext` where the Usecase will be executed. \nSo the `ViewModel` is the most common option.\n\n```kotlin\n// Android\nclass CoinsViewModel : ViewModel(), CoroutineScopeOwner {\n\n      override val coroutineScope: CoroutineScope\n          get() = viewModelScope\n        \n      private val getCoinsUseCase = GetCoinsListUseCase()\n      var coins by mutableStateOf(emptyList\u003cCoin\u003e())\n\n      fun fetchCoins() {\n          getCoinsUseCase.execute(Unit) {\n              onSuccess { coins = it.list }\n              onError { print(it.message) }\n          }\n      }\n}\n```\n\n#### Consume the Usecase from iOS.\nAs the Swift language also features closing lambdas, you can execute the Usecase nearly in the same fashion as on Android.\n```swift\n// iOS\nclass CoinsViewModel : BaseViewModel, ObservableObject {\n    @Published var coins = [Coin]()\n\n    private let getCoinsUseCase = GetCoinsListUseCase()\n\n    func getCoins() {\n        getCoinsUseCase.execute(self, args: KotlinUnit()) {\n            $0.onNext { list in\n                guard let coinsList = list?.list else { return }\n                self.coins = coinsList as [Coin]\n            }\n            $0.onError { error in\n                print(error)\n            }\n        }\n    }\n}\n```\n\n### Example\nCheck out the full example in my other project the [KMM Template](https://github.com/RudolfHladik/Template)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturedapp%2Farkitekt-kmm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuturedapp%2Farkitekt-kmm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturedapp%2Farkitekt-kmm/lists"}