Starter

Table of contents

The first step is always the hardest,
And in a project that is expected to run on 6 platforms, that can be scary 😬!

But scary no more with this KMP project starter!

Create New Project

Prerequisite

  • Mac OS (to support iOS)
  • Install NodeJs
  • Install Yarn

Project

The starter will provide a project that can build libraries,
You can read more on multiplatform-libraries here

Each project will output 2 main SDKs

  • Client
  • Models

Structure

The project uses the Gradle build system and is composed of multiple modules.
The source code is organized into two main directories lib and models.
Additionally, there are sample modules and other platform wrappers (eg: ReactNative)

Lib

The lib module will contain the client SDK,
which can be used as a wrapper for one or multiple backend services, or as common logic that needs to be shared across different parts of the project.

The module is packaged as follows:

Cache

Includes your Dao and your Settings logic

Responsible for handling all database and long-term persistence caching.

The Dao uses SqlDelight by Cashapp.

The Settings uses multiplatform-settings by Russhwolf.

Remote

Includes your api services and handles the http networking.

The services will be using Ktor .

Repositories

The Repositories module contains the main logic for your client.

You can add your other repositories here, and ensure that both dao and apiService are injected so that you can fetch and save data, and provide reactive flows.”

ClientManager

The ClientManager module serves as the entry point to the SDK and is used by consumers.

Its main role is to initialize the SDK and provide an API to the repositories.

Additionally, the manager handles multithreading by wrapping any suspended calls with a Task.


Models

This module contains any classes that need to be exposed to all platforms. These classes must be Serializable and exported to JS.
Additionally, it is recommended that they be implemented as data classes.

example

@Serializable
@JsExport
data class User @JvmOverloads constructor(
    val id: String,
    var name: String? = null,
    var age: String? = null
)

Internal Models

If your data class is a request or a response wrapper and is not needed to be exposed to clients you can keep it in the lib module under a models package also add internal modifier to it.


ReactNative

The ReactNative module provides support for bridging Kotlin Multiplatform code into native libraries for both Android and iOS platforms.
You can learn how to enable this feature here

The module contains a folder for React Native, which includes the React Native library, as well as examples for both Android and iOS platforms.


Flutter 🏗️

Will be available by end of this year (2023)


Samples

Issues

If you encounter any issues while working with the project, you can report them by creating an issue in the project repository here


Table of contents