Kmtemplate
A robust Kotlin Multiplatform template with a modern multi-module architecture for building cross-platform applications across Android, JVM, and WASM using Jetpack Compose .
Install / Use
/learn @mshdabiola/KmtemplateREADME
Kmtemplate
<p align="center"> <img src="./fastlane/metadata/android/en-US/images/icon.png" width="200" /> </p> <p align="center"> <img src="images/screenshot.png" width="800" alt="Application Screenshot" /> </p> <div align="center"> <!-- <a href="https://apt.izzysoft.de/packages/com.mshdabiola.kmttemplate/"><img src="https://gitlab.com/IzzyOnDroid/repo/-/raw/master/assets/IzzyOnDroid.png" height="80"></a> --> <a href="https://f-droid.org/en/packages/com.mshdabiola.kmttemplate"><img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" height="80" alt="Get it on F-Droid"></a> <a href="https://kmtemplate-download.onrender.com"><img src="images/desktop-icon.png" height="80" alt="Download for Desktop"></a> <a href="https://kmtemplate.onrender.com/"><img src="images/web-icon.png" height="80" alt="Try it on Web"></a> <a href="https://github.com/mshdabiola/Kmtemplate/releases"><img src="https://raw.githubusercontent.com/NeoApplications/Neo-Backup/034b226cea5c1b30eb4f6a6f313e4dadcbb0ece4/badge_github.png" height="80" alt="Get it on Github"></a> </div> <br> <br>Kotlin Multiplatform Template is a robust project starter designed with a modern multi-module architecture. It enables seamless code sharing and modular development across JVM, Android, and WASM platforms. The template leverages Kotlin Multiplatform to maximize code reuse, maintainability, and scalability, making it ideal for building cross-platform applications with a clean separation of concerns and platform-specific optimizations.
This project focuses on promoting a modular, scalable, maintainable, and testable architecture. It incorporates a leading-edge tech stack and embodies the finest practices in software development. While the application may appear straightforward, it encompasses all the crucial components that lay the groundwork for a robust, large-scale application.
The design principles and architectural choices applied in this project are ideally suited for larger teams and extended application lifecycles.
🏗️ Architecture
This project follows Clean Architecture principles, ensuring a scalable, maintainable, and testable codebase. The architecture divides the application into three main layers with clear boundaries, promoting a strong separation of concerns.
<p align="center"> <img src="images/Architecture - overall.png" width="800" alt="Overall Architecture Diagram" /> </p>💻 Presentation Layer
This layer is closest to what the user sees on the screen. It's responsible for managing the UI state and handling user interactions.
- View: The UI components, built with Compose Multiplatform, that consume the UI state and present it to the user. They forward user interactions to the ViewModel.
- ViewModel: Manages and stores UI-related data in a lifecycle-aware way. It exposes the View State to the View via observable state holders like Kotlin Flow. User actions trigger updates to this state.
- ViewState: A common, immutable state for a single view, acting as a single source of truth.
🧠 Domain Layer
This is the core layer of the application. It contains the business logic and is completely independent of other layers. Changes to the UI (Presentation) or data source (Data) will not affect this layer.
- UseCase: Contains the application's business logic, orchestrating actions and data flow.
- DomainModel: Defines the core structure of the data used within the application. This is the source of truth for all application data.
- Repository Interface: An abstraction that defines the contract for data access. It allows the Domain layer to remain independent from the specific data implementation in the Data layer.
💾 Data Layer
This layer is responsible for encapsulating application data. It provides the necessary data to the Domain layer and handles the details of data retrieval, storage, and synchronization.
- Repository: Implements the repository interface defined in the Domain layer. It's responsible for fetching data from one or more data sources (e.g., network, local database).
- Mapper: Transforms data from Data Models (e.g., API responses, database entities) into Domain Models, ensuring the Domain layer remains decoupled from the specific data source implementation.
- Data Sources: The low-level implementation for data access, such as Ktor for network requests or Room for local database storage.
🧩 Modularization
The codebase is organized into multiple Gradle modules to improve maintainability, scalability, and reusability. This modular approach enables independent development, easier testing, and faster build times, while supporting code sharing across all supported platforms.
<p align="center"> <img src="images/Modularization.png" width="800" alt="Modularization Diagram" /> </p>- :app: The main application module that wires everything together. It contains platform-specific code for each target (Android, JVM, WASM) and the entry points for the application.
- :features:: Feature-specific modules (e.g.,
main,detail,setting) that contain all the code related to a given feature, including its Presentation, Domain, and Data layers. - :modules: Common library modules that are shared across different parts of the application. Examples include
designsystem,network,database,data, anddomain.
🛠️ Tech Stack & Open-source Libraries
This project leverages a modern, production-ready tech stack and a curated set of open-source libraries to ensure high performance, maintainability, and a delightful developer experience.
- Multiplatform:
- Kotlin Multiplatform (KMP): Enables code sharing of business logic across Android, JVM, and WASM platforms.
- Jetpack Compose & Compose Multiplatform: The modern, declarative UI toolkit for building native user interfaces across all platforms from a single codebase.
- Architecture:
- Clean Architecture: A software architecture that promotes a scalable, maintainable, and testable codebase by separating concerns into distinct layers.
- Kotlin Coroutines & Flow: Used for asynchronous and reactive programming, providing a streamlined way to handle background operations and data streams.
- Koin: A pragmatic and lightweight dependency injection framework that simplifies dependency management.
- Data & Networking:
- Ktor: An asynchronous HTTP client for making network requests across all platforms.
- Kotlinx Serialization: A powerful library for serializing and deserializing JSON data in a type-safe manner.
- Room: A local database library for structured data persistence on Android.
- DataStore: A modern and type-safe data storage solution for simple, key-value pairs or typed objects on Android.
- Testing & Quality:
- Spotless, ktlint, detekt: Static analysis tools for enforcing consistent code formatting and detecting code smells.
