Skip to content

larroyo3/KMPSampleProject

Repository files navigation

🚀 KMPSampleProject

badge-android badge-ios

📱 Project Overview

KMPSampleProject is a sample mobile application built with Kotlin Multiplatform (KMP), Jetpack Compose, and SwiftUI. While the project showcases best practices for clean architecture and modular design in cross-platform mobile apps, it primarily focuses on Jetpack Compose, making it an ideal reference for developers working on native Android projects as well as those exploring Compose Multiplatform.

Whether you're building for Android or across multiple platforms, this project serves as a guide for creating maintainable, scalable applications with modern UI frameworks.

If you find my work helpful, please consider giving it a ⭐ ❤️.

Note: This project is currently in its early stages of development. More features and improvements will be added over time.


👤 About Me

Hi, I'm Lucas Arroyo, a mobile developer specializing in Android and cross-platform development using KMP. If you have any feedback or suggestions to improve this project, don't hesitate to contact me!


linkedin instagram twitterBuyMeACoffee


📚 Table of Contents

  1. 🛠 What is Kotlin Multiplatform (KMP) and Jetpack Compose?
  2. 📚 Tech Stack
  3. 🏗️ How to Build the App
  4. 🌍 Global Best Practices Implemented
  5. 🧩 Module-Specific Best Practices
  6. 🤝 Contributing

🛠 What is Kotlin Multiplatform (KMP) and Jetpack Compose?

Kotlin Multiplatform (KMP)

Kotlin Multiplatform (KMP) is an innovative technology that allows developers to share common code across multiple platforms, such as Android, iOS, desktop, and web, while still enabling platform-specific code when needed. This flexibility makes it easier to write maintainable, reusable code, reducing duplication and simplifying the development process for cross-platform applications.

With KMP, you can:

  • Write once, run anywhere: Share business logic, data models, and network code across platforms.
  • Use platform-specific code when needed: Access native APIs (like Android's Room database or iOS's CoreData) through platform-specific modules.
  • Streamline development: By having a single codebase for your business logic, you reduce the overhead of maintaining multiple codebases and simplify bug fixes and feature updates.

Why KMP?

  • Code Reusability: Write common code once, and share it across Android, iOS, desktop, and more.
  • Flexibility: KMP lets you use platform-specific code when necessary, ensuring you can still leverage native features.
  • Consistency: By using KMP, you maintain consistent business logic and architecture across all platforms, which leads to fewer inconsistencies between apps.
KMP Diagram

Learn more about Kotlin Multiplatform

Jetpack Compose

Jetpack Compose is Google's modern UI toolkit for building native Android UIs with a declarative, reactive programming model. It simplifies UI development by eliminating the need to use imperative UI frameworks like XML-based layouts. With Jetpack Compose, you describe your UI as functions (composables) that automatically recompose when data changes.

Learn more about Jetpack Compose

Key Features of Jetpack Compose:

  • Declarative UI: Instead of defining how the UI changes over time with imperative logic, you declare what the UI should look like at any given state.
  • Composability: Build UIs by combining small, reusable UI elements (composables) that can easily be assembled and reassembled.
  • Seamless Integration: Jetpack Compose is fully interoperable with existing Android views and code, meaning you can gradually adopt it in existing projects.
  • Kotlin-first: Jetpack Compose is designed to work with Kotlin, offering concise syntax, coroutines for asynchronous tasks, and interoperability with other Jetpack libraries.

SwiftUI (for iOS)

Just like Jetpack Compose for Android, SwiftUI is Apple's declarative UI framework for building UIs in iOS. With SwiftUI, you can build UIs in a similar fashion, using reactive programming concepts to automatically update the UI when data changes.

Learn more about SwiftUI

Why Compose and SwiftUI Together?

Using Compose for Android and SwiftUI for iOS in a Kotlin Multiplatform project lets you:

  • Leverage native performance: Each platform still uses its native UI framework, ensuring optimal performance.
  • Consistent UI patterns: Both Compose and SwiftUI share similar declarative patterns, making it easier for developers to switch between platforms.
  • Reduce learning curve: Developers familiar with declarative programming can more easily transition between Android and iOS development.

📚 Tech Stack


🏗️ How to Build the App

Android

  1. Clone the repository: [git clone https://github.com/your-repo.git](https://github.com/larroyo3/KMPSampleProject)
  2. Open the project in Android Studio.
  3. Sync the Gradle files.
  4. Run the app on an Android emulator or physical device.

iOS

  1. Clone the repository: [git clone https://github.com/your-repo.git](https://github.com/larroyo3/KMPSampleProject)
  2. Open the iOS project in Xcode.
  3. Select your target device (simulator or physical).
  4. Run the app.

🌍 Global Best Practices Implemented

Project Structure

  • /composeApp: Contains shared code for your Compose Multiplatform applications, with commonMain holding code that can run on both Android and iOS. Platform-specific code resides in corresponding folders like iosMain for iOS-specific implementations.

  • /iosApp: Contains the iOS-specific entry point and any SwiftUI code. Even when sharing the UI with Compose Multiplatform, you'll still need to manage the native entry points for the iOS app in Xcode.

  • /shared: Houses shared business logic, network, and data handling code that can be reused across all platforms. The commonMain folder inside /shared contains the core logic shared by both Android and iOS apps.

Here are the global coding practices applied across the entire project:

Note: Since this project is still in its early stages, additional best practices and refinements will be implemented as development progresses.


🧩 Module-Specific Best Practices

Each module in the project follows its own set of best practices. Here's a quick breakdown:

Note: As modules are still being developed, these best practices will continue to evolve.


🤝 Contributing

Contributions are welcome! Feel free to fork the repository, make your improvements, and submit a pull request. Let's collaborate to make this project even better!