# datepollsystems/waiterrobot-shared-android architecture

> Architecture diagram of the GitHub repository datepollsystems/waiterrobot-shared-android, 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/datepollsystems/waiterrobot-shared-android
- Repository: https://github.com/datepollsystems/waiterrobot-shared-android

## Overview

##### Main Architectural Components
- Android Application (androidApp directory)
– Built using Jetpack Compose for declarative UI (with Material components, Compose Destinations for navigation, etc.).
– Contains application-specific code (activities, UI components, view models, and integrations such as Stripe and barcode scanning).
– Uses Gradle (kts scripts) for build and configuration.

- Shared Module (shared directory)
– Written in Kotlin with multiplatform support (commonMain, androidMain, iosMain).
– Implements core business logic such as repositories, network API calls (using Ktor), local persistence (Realm for Kotlin), and error logging (Sentry integration).
– Uses dependency injection via Koin (platform- and shared-specific DI modules).
– Follows an MVI/MVVM pattern (Orbit MVI and Moko MVVM for viewModelScope) that underpins state management and view models.
– Provides components for features like authentication, billing, order management, settings, table management, and switch event handling.

- External Services and Integrations:
– Payment processing via Stripe.
– Remote API endpoints through Ktor.
– Sentry for dynamic error logging and performance monitoring.
– CI/CD services (GitHub Actions workflows) that automate testing, release tagging, and deploying to Google Play and the GitHub Package Registry.

##### Relationships and Interactions
- The Android app (UI layer) communicates mainly with the shared module, calling into its use cases, view models, and repositories.
- The Shared module encapsulates:
– API clients that handle remote calls (secured via Ktor with authentication).
– A local database layer (Realm and other abstractions) for offline and persistent data.
– Domain-specific logic handling events from various features (such as login/authentication, ordering, and billing).
– DI containers to wire dependencies via Koin, tailored for each platform.
- The shared business logic is provided to the iOS application as a Swift Package (via the SPM package published through GitHub Package Registry).

##### Architectural Patterns and Key Design Principles
- Separation of concerns is evident in the distinct boundary between the Android-specific UI code and the cross-platform shared module.
- The project follows modern mobile architectural patterns such as MVVM/MVI to clearly separate UI, state management, and business logic.
- Use of Dependency Injection (Koin) to promote modularity and testability.
- Emphasis on reusability via Kotlin Multiplatform, enabling the central business logic to be maintained in one place.
- The CI/CD pipelines are designed to automate release processes and ensure that versioning and deployments for Android and shared modules follow a consistent strategy.

##### Relevant Technologies and Frameworks
- For the Shared Module:
– Kotlin Multiplatform, KMMBridge, Ktor (with content negotiation, client auth, and logging), Realm (Kotlin) for the database, KotlinX Serialization and DateTime.
– Libraries like Koin for dependency injection, Orbit MVI for UI state handling, and Moko MVVM.
- For the Android App:
– Jetpack Compose (UI), Material components, Compose Destinations, and Accompanist Permissions.
– Integration libraries for barcode scanning, Stripe payment processing, and Gradle Play Publisher.

– Android App (with sub-components like UI, ViewModels, and Android-specific utilities).
– Shared Module (with divisions for common, androidMain, iosMain source sets).
– External Services (e.g., Stripe, Sentry, remote API endpoints).
– CI/CD Workflows that handle builds and releases.
– From UI components to shared view models and business logic.
– From the shared module to external API services, and vice versa.
– Platform-specific layers (Android, iOS) versus cross-platform/shared code.
– Build/infrastructure components (CI workflows) versus application-level layers.
- Component is clearly labeled with its purpose, technology choices (e.g., “Jetpack Compose” for Android UI, “Ktor” for network client), and any interconnection details.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Android Application Layer
    subgraph "Android Application"
        A1["MainActivity (Activity)"]:::android
        A2["WaiterRobotApp (Application)"]:::android
        subgraph "UI Components"
            A3["Android UI Components"]:::android
            A3a["Billing Screen"]:::android
            A3b["Login Screen"]:::android
            A3c["QR Code Scanner"]:::android
        end
        A4["Stripe Payment Integration"]:::android
    end

    %% Shared Module
    subgraph "Shared Module"
        S1["Business Logic"]:::shared
        S2["API & Networking"]:::shared
        S3["Database Access"]:::shared
        S4["Dependency Injection (Koin)"]:::shared
        S5["State Management / ViewModel"]:::shared
        
        subgraph "Feature Modules"
            S5a["Authentication"]:::shared
            S5b["Billing Feature"]:::shared
            S5c["Order Management"]:::shared
            S5d["Settings"]:::shared
            S5e["Table Management"]:::shared
            S5f["Switch Event Handling"]:::shared
        end
    end

    %% External Services
    subgraph "External Services"
        E1["Sentry Integration"]:::external
        E2["Sentry xcframework"]:::external
    end

    %% iOS Application (via Swift Package Manager)
    subgraph "iOS"
        I1["iOS Application (Swift Package)"]:::ios
    end

    %% CI/CD Workflows
    subgraph "CI/CD Workflows"
        C1["publishAndroidLava"]:::cicd
        C2["publishAndroidProd"]:::cicd
        C3["publishSharedSpm"]:::cicd
        C4["test Workflow"]:::cicd
        C5["checkStyle Workflow"]:::cicd
    end

    %% Relationships - Android Layer
    A1 -->|"triggersUI"| A3
    A2 -->|"initializes"| A3
    A3 -->|"triggersPayment"| A4

    %% Relationships - Android to Shared
    A3 -->|"updatesState"| S5
    S5 -->|"executesLogic"| S1
    S1 -->|"callsAPIs"| S2
    S1 -->|"queriesDB"| S3

    %% Dependency Injection flows
    S4 -->|"injects"| S1
    S4 -->|"injects"| S2
    S4 -->|"injects"| S3
    S4 -->|"injects"| S5

    %% Shared Feature Modules interactions
    S5 -->|"manages"| S5a
    S5 -->|"manages"| S5b
    S5 -->|"manages"| S5c
    S5 -->|"manages"| S5d
    S5 -->|"manages"| S5e
    S5 -->|"manages"| S5f

    %% Shared Module to External Service
    S1 -->|"logsErrors"| E1

    %% Shared Module provided to iOS
    S5 ---|"publishedAsSPM"| I1

    %% CI/CD triggering deployments
    C2 -->|"deploys"| A1
    C2 -->|"deploys"| A4
    C3 -->|"builds"| S1
    C3 -->|"builds"| S5

    %% UI Components internal breakdown
    A3 --- A3a
    A3 --- A3b
    A3 --- A3c

    %% Click Events for Android Application
    click A1 "https://github.com/datepollsystems/waiterrobot-shared-android/blob/develop/androidApp/src/main/java/org/datepollsystems/waiterrobot/android/MainActivity.kt"
    click A2 "https://github.com/datepollsystems/waiterrobot-shared-android/blob/develop/androidApp/src/main/java/org/datepollsystems/waiterrobot/android/WaiterRobotApp.kt"
    click A3 "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/androidApp/src/main/java/org/datepollsystems/waiterrobot/android/ui/"
    click A3a "https://github.com/datepollsystems/waiterrobot-shared-android/blob/develop/androidApp/src/main/java/org/datepollsystems/waiterrobot/android/ui/billing/BillingScreen.kt"
    click A3b "https://github.com/datepollsystems/waiterrobot-shared-android/blob/develop/androidApp/src/main/java/org/datepollsystems/waiterrobot/android/ui/login/LoginScreen.kt"
    click A3c "https://github.com/datepollsystems/waiterrobot-shared-android/blob/develop/androidApp/src/main/java/org/datepollsystems/waiterrobot/android/ui/scanner/QrCodeScanner.kt"
    click A4 "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/androidApp/src/main/java/org/datepollsystems/waiterrobot/android/stripe/"

    %% Click Events for Shared Module
    click S1 "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/core/"
    click S2 "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/core/data/api/"
    click S3 "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/core/data/db/"
    click S4 "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/core/di/"
    click S5 "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/core/viewmodel/"

    %% Click Events for Shared Feature Modules
    click S5a "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/features/auth/"
    click S5b "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/features/billing/"
    click S5c "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/features/order/"
    click S5d "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/features/settings/"
    click S5e "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/features/table/"
    click S5f "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/features/switchevent/"

    %% Click Events for External Services
    click E1 "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/core/sentry/"
    click E2 "https://github.com/datepollsystems/waiterrobot-shared-android/tree/develop/shared/Sentry-Dynamic.xcframework/"

    %% Click Events for CI/CD Workflows
    click C1 "https://github.com/datepollsystems/waiterrobot-shared-android/blob/develop/.github/workflows/publishAndroidLava.yml"
    click C2 "https://github.com/datepollsystems/waiterrobot-shared-android/blob/develop/.github/workflows/publishAndroidProd.yml"
    click C3 "https://github.com/datepollsystems/waiterrobot-shared-android/blob/develop/.github/workflows/publishSharedSpm.yml"
    click C4 "https://github.com/datepollsystems/waiterrobot-shared-android/blob/develop/.github/workflows/test.yml"
    click C5 "https://github.com/datepollsystems/waiterrobot-shared-android/blob/develop/.github/workflows/checkStyle.yml"

    %% Class Definitions for styling
    classDef android fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef shared fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef external fill:#FFFF99,stroke:#DAA520,stroke-width:2px;
    classDef ios fill:#FFC0CB,stroke:#C71585,stroke-width:2px;
    classDef cicd fill:#D3D3D3,stroke:#696969,stroke-width:2px;
```
