# kotlin/kmp-basic-sample architecture

> Architecture diagram of the GitHub repository kotlin/kmp-basic-sample, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kotlin/kmp-basic-sample
- Repository: https://github.com/kotlin/kmp-basic-sample

## Overview

##### Project type and purpose
- This is a Kotlin Multiplatform (KMP) mobile sample. It demonstrates how to share business logic and utilities in a single Kotlin “shared” module, while hosting native UIs on Android and iOS.
- The goal is to illustrate expect/actual usage (Platform.kt), basic shared logic (Calculator, Greeting), plus platform-specific apps: Android with Jetpack Compose (composeApp) and iOS with SwiftUI (iosApp).

##### File structure
- Top level:
- build.gradle.kts, settings.gradle.kts, gradle wrapper and version catalogs
- Three subprojects: composeApp (Android UI), iosApp (Xcode/Swift), shared (Kotlin common logic + platform adapters + tests)
- composeApp:
- commonMain: cross-platform Compose resources
- iosApp:
- Xcode project, SwiftUI files (iOSApp.swift, ContentView.swift), asset catalogs, tests
- shared:
- commonMain: Calculator.kt, Greeting.kt, Platform.kt (expect)
- androidMain & iosMain: Platform.android.kt, Platform.ios.kt (actual implementations)
- tests: androidUnitTest, iosTest, commonTest
- CI config: .github/workflows/push.yml

##### README for additional insights
- Emphasizes KMP features: expect/actual, multi-platform testing
- Instructs using Kotlin Multiplatform Mobile plugin

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CI Pipeline
    CI["GitHub Actions CI"]:::ci
    CI -->|"trigger build & tests"| Gradle["Gradle Build & KMP Plugin"]:::build

    %% Build Artifacts
    Gradle -->|"produce AAR"| AAR["Android AAR"]:::artifact
    Gradle -->|"produce framework"| FRAME["Kotlin/Native Framework"]:::artifact

    %% Shared Module
    subgraph "Shared Module" 
        direction TB
        SM_DIR["shared/"]:::shared
        CM["commonMain"]:::shared
        AM["androidMain"]:::shared
        IM["iosMain"]:::shared
        SCT["commonTest"]:::tests
        SAT["androidUnitTest"]:::tests
        SIT["iosTest"]:::tests

        SM_DIR --> CM
        SM_DIR --> AM
        SM_DIR --> IM
        SM_DIR --> SCT
        SM_DIR --> SAT
        SM_DIR --> SIT
    end

    %% Android App
    subgraph "Android App (composeApp)"
        direction TB
        APP_DIR["composeApp/"]:::android
        MA["MainActivity.kt"]:::android
        AR["androidMain/res/"]:::android
        CR["commonMain/composeResources/"]:::android

        APP_DIR --> MA
        APP_DIR --> AR
        APP_DIR --> CR
    end

    %% iOS App
    subgraph "iOS App (iosApp)"
        direction TB
        IOS_DIR["iosApp/iosApp/"]:::ios
        IAPP["iOSApp.swift"]:::ios
        CV["ContentView.swift"]:::ios
        ASSETS["Assets.xcassets/"]:::ios
        XCODE["iosApp.xcodeproj/"]:::ios
        IOT["iosAppTests/"]:::tests
        UI_T["iosAppUITests/"]:::tests

        IOS_DIR --> IAPP
        IOS_DIR --> CV
        IOS_DIR --> ASSETS
        IOS_DIR --> XCODE
        IOS_DIR --> IOT
        IOS_DIR --> UI_T
    end

    %% Dependencies
    APP_DIR -->|uses| SM_DIR
    IOS_DIR -->|uses| SM_DIR
    AAR -->|import AAR| APP_DIR
    FRAME -->|import framework| IOS_DIR

    %% CI Tests
    Gradle -->|run shared tests| SCT
    Gradle -->|run android tests| SAT
    Gradle -->|run ios tests| SIT
    Gradle -->|run iOS app tests| IOT
    Gradle -->|run iOS UI tests| UI_T

    %% Click events
    click SM_DIR "https://github.com/kotlin/kmp-basic-sample/tree/master/shared/"
    click CM "https://github.com/kotlin/kmp-basic-sample/blob/master/shared/src/commonMain/kotlin/com/jetbrains/basicsample/Calculator.kt"
    click CM "https://github.com/kotlin/kmp-basic-sample/blob/master/shared/src/commonMain/kotlin/com/jetbrains/basicsample/Greeting.kt"
    click CM "https://github.com/kotlin/kmp-basic-sample/blob/master/shared/src/commonMain/kotlin/com/jetbrains/basicsample/Platform.kt"
    click AM "https://github.com/kotlin/kmp-basic-sample/blob/master/shared/src/androidMain/kotlin/com/jetbrains/basicsample/Platform.android.kt"
    click IM "https://github.com/kotlin/kmp-basic-sample/blob/master/shared/src/iosMain/kotlin/com/jetbrains/basicsample/Platform.ios.kt"
    click APP_DIR "https://github.com/kotlin/kmp-basic-sample/tree/master/composeApp/"
    click MA "https://github.com/kotlin/kmp-basic-sample/blob/master/composeApp/src/androidMain/kotlin/com/jetbrains/basicsample/MainActivity.kt"
    click AR "https://github.com/kotlin/kmp-basic-sample/tree/master/composeApp/src/androidMain/res/"
    click CR "https://github.com/kotlin/kmp-basic-sample/tree/master/composeApp/src/commonMain/composeResources/"
    click IOS_DIR "https://github.com/kotlin/kmp-basic-sample/tree/master/iosApp/iosApp/"
    click IAPP "https://github.com/kotlin/kmp-basic-sample/blob/master/iosApp/iosApp/iOSApp.swift"
    click CV "https://github.com/kotlin/kmp-basic-sample/blob/master/iosApp/iosApp/ContentView.swift"
    click ASSETS "https://github.com/kotlin/kmp-basic-sample/tree/master/iosApp/iosApp/Assets.xcassets/"
    click XCODE "https://github.com/kotlin/kmp-basic-sample/tree/master/iosApp/iosApp.xcodeproj/"
    click CI "https://github.com/kotlin/kmp-basic-sample/blob/master/.github/workflows/push.yml"
    click Gradle "https://github.com/kotlin/kmp-basic-sample/blob/master/build.gradle.kts"
    click Gradle "https://github.com/kotlin/kmp-basic-sample/blob/master/settings.gradle.kts"
    click Gradle "https://github.com/kotlin/kmp-basic-sample/blob/master/gradle/libs.versions.toml"
    click SCT "https://github.com/kotlin/kmp-basic-sample/blob/master/shared/src/commonTest/kotlin/com.jetbrains.basicsample/CalculatorTest.kt"
    click SAT "https://github.com/kotlin/kmp-basic-sample/blob/master/shared/src/androidUnitTest/kotlin/com/jetbrains/basicsample/androidTest.kt"
    click SIT "https://github.com/kotlin/kmp-basic-sample/blob/master/shared/src/iosTest/kotlin/com/jetbrains/basicsample/iosTest.kt"
    click IOT "https://github.com/kotlin/kmp-basic-sample/blob/master/iosApp/iosAppTests/iosAppTests.swift"
    click UI_T "https://github.com/kotlin/kmp-basic-sample/blob/master/iosApp/iosAppUITests/iosAppUITests.swift"

    %% Styles
    classDef shared fill:#f9f,stroke:#333,stroke-width:1px
    classDef android fill:#bbf,stroke:#333,stroke-width:1px
    classDef ios fill:#bfb,stroke:#333,stroke-width:1px
    classDef build fill:#ffb,stroke:#333,stroke-width:1px
    classDef ci fill:#eee,stroke:#333,stroke-width:1px
    classDef artifact fill:#fcf,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef tests fill:#fee,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2
```
