Skip to content
Kotlin Multiplatform Template
Kotlin Swift HTML Ruby
Branch: master
Clone or download
bffcorreia Merge pull request #7 from pink-room/use-dependencies-https
Use https instead of http to download dependencies.
Latest commit 2ad0004 Oct 27, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
android Add multiplatform serialization and http client for android and ios c… Aug 21, 2018
backend Add multiplatform serialization and http client for android and ios c… Aug 21, 2018
common-client-ios Add multiplatform serialization and http client for android and ios c… Aug 21, 2018
common-client-js Add multiplatform serialization and http client for android and ios c… Aug 21, 2018
common-client-jvm Add multiplatform serialization and http client for android and ios c… Aug 21, 2018
common-client Add todo info for serialization. Aug 23, 2018
common-ios Change architecture to caontain a common client module. Aug 14, 2018
common-js Add multiplatform serialization and http client for android and ios c… Aug 21, 2018
common-jvm Remove serialization. Aug 2, 2018
common Change architecture to caontain a common client module. Aug 14, 2018
gradle/wrapper Add multiplatform coroutines. Aug 14, 2018
ios Remove cached file that belongs to .gitignore now. Aug 23, 2018
web Change architecture to caontain a common client module. Aug 14, 2018
.gitignore Ignore ios.xcworkspace. Aug 23, 2018
LICENSE Add readme. Aug 7, 2018
README.md Add license badge. Sep 27, 2018
android.png Update readme. Aug 23, 2018
architecture.png Update readme. Aug 23, 2018
build.gradle Use https instead of http to download dependencies. Oct 27, 2019
gradlew First commit. Jul 26, 2018
gradlew.bat First commit. Jul 26, 2018
ios.png Update readme. Aug 23, 2018
multiplatform_template.png Add readme. Aug 7, 2018
settings.gradle Change architecture to caontain a common client module. Aug 14, 2018
web.png Add readme. Aug 7, 2018

README.md

Kotlin Multiplatform Template

This is a Kotlin Multiplatform starter template inspired by Clean Architecture and the MVP pattern.

Currently we are using IntellijIDEA as the main IDE. However, the Android client was developed in Android Studio and the iOS client with Xcode.

Tweet


ArchitectureBackendWebAndroidiOS


Why?

This project started because we wanted to test the power of Kotlin Multiplatform. As opposed to other cross-platform approaches, Kotlin doesn't want you to write your code once and compile it to multiple platforms. Instead, it focus on sharing the part of the code that contains logic and left the platform specific part to be implemented natively using its specific SDK's.

Although this may look like a dream, Kotlin Multiplatform is still on the early days and we quickly realised how difficult is to find concise documentation to setup and build such a project.

With this in mind, we decided to write this "easy" and small template that we think that might be useful if you want to start a multiplatform project. Please note that this project will evolve according to the maturity of the Kotlin multiplatform support, tools and libraries. 🙂

Architecture

The architecture of this project is composed by one common module and its platform specific implementations (jvm, js and ios). A common-client module and the platform specific modules. One backend and three clients (android, ios and web).

Project Architecture

  • common: Contains all the common code shared between the modules. In this case are only the data models.
  • common-jvm/js/ios: Where the common platform specific implementations are placed.
  • common-client: Where the clients common code is implemented. Such as the business and presentation logic.
  • common-client-jvm/js/ios: Responsible for the common client specific implementations.
  • backend: Contains the server logic and a REST API.
  • android: Responsible for the android clients. Contains a mobile module but you can add others (e.g.: wear).
  • ios: The iOS client!
  • web: The web client that runs in the browser.

How everything is connected?

This project uses Gradle that is responsible to build and connect all the modules.

The common module contains only the data models since it's the only code that we want to share between the backend and the client modules.

But, what if this common module needs specific implementations for each platform? This's why we have the common-jvm, common-js and common-ios platform modules. They are connected with the common module by an expectedBy dependency and implement the actual classes that are expected in the common module (e.g.: date, etc...).

The common-client module is responsible to implement the repositories, use cases and presenters. This is the code that we want to share only between clients. And, again, if we want to implement platform specific parts (e.g.: coroutines dispatcher, etc...) we have the common-client-jvm, common-client-js and common-client-ios platform modules.

The other modules (android, ios, and web) use the common-client modules by compiling the platform specific module. And, since we are using the MVP pattern, clients only need to implement the View part that is specific for each platform.

Finally, the backend module is connected with the common code by compiling the common-jvm module.

Note: This architecture was designed to work with both backend and clients. If you only want to implement a multiplatform project with clients (probably the most common use case), you can merge the common modules with the common-client modules. Moreover, don't forget to remove the platform specific modules if you will not implement modules which use that platform.

Backend

The backend is implemented using the ktor framework.

To run it, simply execute ./gradlew :backend:run in the root of the project and the server will start listening at localhost:8080.

You can test it by opening the memes route in your browser.

Since the server will run in your localhost, I suggest you to use ngrok to expose your local server to a public URL. Don't forget to change the server host in the ApiUtils.kt.

Android

Android Screens

If you are used to Android Studio you can open the project on it and run the mobile module.

Otherwise, use gradle to assemble the app: ./gradlew :android:mobile:assembleDebug.

And install it via adb: adb install android/mobile/build/outputs/apk/debug/mobile-debug.apk.

iOS

iOS Screens

To run the iOS module you need to have the Xcode and the CocoaPods installed.

To install CocoaPods simply run: sudo gem install cocoapods.

Then, install the dependencies: pod install.

After that, double click on the ios.xcworkspace file to open the project.

Now, before running the project you also need to build the common-client-ios module: ./gradlew :common-client-ios:build.

Then, build the project by clicking in the run button. This will build and run the iOS project in an emulator.

Web

Note: Currently the web module is not working since we are waiting for ktor to release the JS client.

Web Screen

To build the web client we use the Kotlin Frontend Plugin.

Currently, we are only using Kotlin/JS in order to manipulate the DOM. However, you can easily use this plugin to write your UI in React.

Run it with ./gradlew :web:run and then open it on your browser.

Credits

This project wouldn't be possible without the help of the community and other amazing open source projects. Here are some really good examples that you can also look at:

To Do

  • Dependency Injection
  • Tests
  • JS Http Client (ktor will publish a client soon...)
  • Add a DB
  • Share Images / Resources
  • Improve gradle configurations
  • More...

License

Copyright 2018 Pink Room, Lda.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You can’t perform that action at this time.