This is the official sample of the D-KMP architecture, presenting a simple master/detail app, for both Android and iOS.
For more info on the D-KMP Architecture, please read the relevant Medium article.
- it uses the latest declarative UI toolkits: JetpackCompose for Android and SwiftUI for iOS
- it fully shares the ViewModel (and the DataLayer) via Kotlin MultiPlatform
- coroutine scopes are cancelled/reinitialized automatically, based on the current active screens and the app lifecycle (using LifecycleObserver on Android and the SwiftUI lifecycle on iOS)
- it implements the MVI pattern and the unidirectional data flow
- it implements the CQRS pattern, by providing 2 types of functions to the UI layer: Events and StateProviders
- it uses Kotlin's StateFlow to trigger UI layer recompositions
- webservices (using Ktor Http Client)
- local db (using SqlDelight)
- local settings (using MultiplaformSettings)
- realtime db (using Firestore)
- graphQL (using Apollo GraphQL)
- device bluetooth (using Kable)
- etc...
If you want to create your own app using the D-KMP Architecture, here are the instructions you need:
May 13, 2021: UPDATE! There is an ongoing rewriting of the architecture, which should be completed by the end of May. So, the advise is not to go any deep into the current sample, as soon there will be major improvements, such as shared-code navigation.
- ๐ ๏ธ in the viewmodel/screens folder: create a folder for each screen of the app, containing these 4 files (as shown in the sample app structure above):
- screenEvents.kt, where the event functions for that screen are defined
- screenState.kt, where the data class of the state for that screen is defined
- screenStateProvider.kt, where the state provider function for that screen is defined
- screenStateReducers.kt, where the state reducers functions (called by the events) for that screen are defined
- ๐ ๏ธ in the ScreenEnum.kt file in the viewmodel folder, you should define the enum with all screens in your app
- โ the other 5 files in the viewmodel folder (DKMPViewModel.kt, Events.kt, StateManager.kt, StateProviders.kt, StateReducers.kt) don't need to be modified
- โ also DKMPViewModelForAndroid.kt in androidMain and DKMPViewModelForIos.kt in iosMain don't need to be modified
- ๐ ๏ธ in the datalayer/functions folder: create a file for each repository function to be called by the ViewModel's StateReducers
- ๐ ๏ธ in the datalayer/objects folder: create a file for each data class used by the repository functions
- ๐ ๏ธ in the datalayer/sources folder: create a folder for each datasource, where the datasource-specific functions (called by the repository functions) are defined
- โ the datalayer/Repository.kt file should be modified only in case you want to add an extra datasource
- ๐ ๏ธ in the screens folder: create a folder for each screen of the app, containing all JetpackCompose composables for that screen
- โ the DKMPApp.kt file doesn't need to be modified
- โ the DKMPNavigation.kt file doesn't need to be modified
- โ the MainActivity.kt file doesn't need to be modified
- โ the MainComposable.kt file doesn't need to be modified
- ๐ ๏ธ the ScreenComposables.kt file should be modified to define the screen composables in the app
- ๐ ๏ธ in the screens folder: create a folder for each screen of the app, containing all SwiftUI views for that screen
- โ the AppObservableObject.swift file doesn't need to be modified
- โ the DKMPApp.swift file doesn't need to be modified
- โ the DKMPNavigation.swift file doesn't need to be modified
- โ the MainView.swift file doesn't need to be modified
- ๐ ๏ธ the ScreenViews.swift file should be modified to define the screen views in the app
- we'll be adding also the web version, using Jetpack Compose for Web