# c4lopsitta/mir-controller architecture

> Architecture diagram of the GitHub repository c4lopsitta/mir-controller, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/c4lopsitta/mir-controller
- Repository: https://github.com/c4lopsitta/mir-controller

## Overview

##### Architectural Components
- Shared Module (composeApp/commonMain): This is where all platform-agnostic code lives. It includes:
- Core application logic such as API definitions (MirApi), business models, view models, and UI components.
- Shared UI resources (Compose code, Material 3 components) that can be rendered on multiple platforms.
- Platform-Specific Modules (composeApp/androidMain, iosMain, desktopMain):
- Android: Contains Android-specific entry points (e.g., MainActivity.kt, AndroidManifest.xml) and implementations (Platform.android.kt).
- iOS: Has the iOS-specific portion of the Kotlin code (Platform.ios.kt, MainViewController.kt) along with a separate native iOS project (iosApp) set up with SwiftUI.
- Desktop: Contains JVM-specific code (Platform.jvm.kt, main.kt) for desktop deployment.
- Build and Configuration: Gradle build scripts (build.gradle.kts, settings.gradle.kts, gradle configuration files) and environment-specific configuration (e.g., iosApp/Configuration/Config.xcconfig for iOS) which manage the build process and integration for different platforms.
- External Libraries and Frameworks:
- Kotlin Multiplatform framework for sharing code.
- Jetpack Compose leveraging Material 3 for UI.
- Platform-specific libraries (Android SDK, iOS native frameworks, etc.)

##### Relationships & Interactions
- The Shared Module acts as the core of the application where business logic and UI definitions are abstracted.
- Each Platform-Specific Module consumes the shared logic but provides its own UI entry points and adaptations:
- On Android, the data flow starts at MainActivity (and other Android-specific components) then interacts with common view models and UI components.
- On iOS, the native Swift app (iosApp) initializes the shared Kotlin code via bridging code (like App.ios.kt and MainViewController.kt) and handles platform-specific rendering.
- The Desktop module has its own main entry (main.kt) that invokes the shared application logic.
- Build system dependencies (Gradle) compile and bundle the modules accordingly for each target platform.
- External APIs or internal routing/flow systems (defined in definitions/Routes.kt and api/MirApi.kt) direct how different modules interact.

##### Architectural Patterns & Design Principles to Highlight
- Code Reusability & Separation of Concerns: Emphasize how the commonMain directory isolates shared logic, while platform-specific directories only contain the necessary adaptation code.
- Multiplatform Abstraction: Showcase the use of platform-specific implementations (e.g., Platform.android.kt, Platform.ios.kt, Platform.jvm.kt) that abstract each environment’s peculiarities from the common code.
- Modularization: Different layers of the app are neatly separated (UI components, API abstraction, data models, view models) to maintain clarity and ease future enhancements.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Shared Module"
        S["Shared Module\n(business logic, API, UI components)"]:::shared
    end

    subgraph "Android Module"
        A1["Android UI\n(MainActivity.kt)"]:::android
        A2["Android Platform\n(Platform.android.kt)"]:::android
    end

    subgraph "iOS Module"
        I1["iOS Kotlin Code\n(App.ios.kt, MainViewController.kt, Platform.ios.kt)"]:::ios
        subgraph "Native iOS (Swift)"
            I2["Native Swift App\n(iosApp)"]:::ios
            I3["iOS Config\n(iosApp/Configuration/Config.xcconfig)"]:::ios
        end
    end

    subgraph "Desktop Module"
        D["Desktop Module\n(App.desktop.kt, main.kt, Platform.jvm.kt)"]:::desktop
    end

    subgraph "Build & Configuration"
        B["Gradle Build Scripts\n(build.gradle.kts, settings.gradle.kts, gradle config files)"]:::build
    end

    %% Relationships
    A1 -->|"uses"| S
    A2 -->|"integrates"| S

    I1 -->|"consumes"| S
    I2 -->|"bridges"| I1
    I3 -->|"configures"| I2

    D -->|"invokes"| S

    B -->|"builds"| S
    B -->|"builds"| A1
    B -->|"builds"| I1
    B -->|"builds"| D
    B -->|"configures"| I3

    %% Click Events
    click S "https://github.com/c4lopsitta/mir-controller/tree/main/composeApp/src/commonMain"
    click A1 "https://github.com/c4lopsitta/mir-controller/blob/main/dev/robaldo/mir/MainActivity.kt"
    click A2 "https://github.com/c4lopsitta/mir-controller/blob/main/dev/robaldo/mir/Platform.android.kt"
    click I1 "https://github.com/c4lopsitta/mir-controller/tree/main/composeApp/src/iosMain"
    click I2 "https://github.com/c4lopsitta/mir-controller/tree/main/iosApp"
    click I3 "https://github.com/c4lopsitta/mir-controller/blob/main/iosApp/Configuration/Config.xcconfig"
    click D "https://github.com/c4lopsitta/mir-controller/tree/main/composeApp/src/desktopMain"
    click B "https://github.com/c4lopsitta/mir-controller/blob/main/build.gradle.kts"

    %% Styles
    classDef shared fill:#bbf,stroke:#333,stroke-width:2px;
    classDef android fill:#afa,stroke:#333,stroke-width:2px;
    classDef ios fill:#faa,stroke:#333,stroke-width:2px;
    classDef desktop fill:#ffa,stroke:#333,stroke-width:2px;
    classDef build fill:#ddd,stroke:#333,stroke-width:2px;
```
