# mmrlapp/mmrl architecture

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

- Interactive diagram: https://gitdiagram.com/mmrlapp/mmrl
- Repository: https://github.com/mmrlapp/mmrl

## Overview

##### Project Type and Purpose
- This is a full-stack, multi-module Android application (“MMRL”) whose primary function is to help users manage and install Android modules (Magisk, KernelSU, APatch) both online and locally. It also embeds a WebUI for advanced module management and exposes native platform capabilities via AIDL/JNI.

##### File-Structure Overview
- Top-level Gradle modules:
- app – the Android application entry point; ties everything together.
- datastore – wrapper around Jetpack DataStore for user preferences.
- ext – Kotlin extension library shared by other modules.
- platform – platform-level module: AIDL interfaces + JNI/C++ code to invoke root operations.
- hidden-api – generated Android hidden APIs for direct system calls.
- ui – reusable Compose UI components.
- webui – assets and Kotlin server layer to serve the in-app WebUI.
- Build-logic folder contains custom Gradle convention plugins (Hilt, Room, Compose).

##### README Highlights
- MVVM architecture with Compose.
- Hilt for DI.
- Room for on-device DB (AppDatabase + DAOs under app/src/**/database).
- DataStore for key-value preferences.
- AIDL/JNI bridge for root-level operations.
- Embedded WebUI served from assets, communicating via JavaScript interfaces.

a. Presentation Layer
– Android Activities & Composables (app/ui packages)
– ViewModels (app/viewmodel)
b. Domain Layer
– Repositories (app/repository + datastore/repository)
c. Data Layer
– Room Database (app → AppDatabase, DAOs, Entities)
– Jetpack DataStore (datastore module)
– Remote Network Services (app/network + retrofit/HTTP clients)
d. Platform Layer
– AIDL interfaces & Bindings (platform/src/main/aidl → com.dergoogler.mmrl.platform.content)
– JNI/C++ layer (platform/src/main/jni)
– Hidden-API stubs (hidden-api module)
e. WebUI Layer
– Static assets (webui/src/main/assets/webui)
– Embedded HTTP server in WebView (WebUIAssetLoader → handlers)
– JS ↔ Kotlin bridge (WebUIClient & JS interfaces)

##### Relationships & Interactions
- UI → ViewModel: Compose UI injects ViewModels via Hilt.
- ViewModel → Repository: Business logic obtains data from repositories.
- Repository → DataSources:
- Local: Room DB (Entity/DAO) & DataStore (key-value).
- Remote: HTTP via Network.kt and Moshi serialization.
- Platform: AIDL service calls through ServiceManager and JNI code.
- Services (DownloadService, ModuleService, RepositoryService) run in the background and talk to repositories and platform.
- WebUI: WebView requests asset URLs → WebUIAssetLoader → passes requests to path handlers → some handlers forward to platform/ServiceManager or file APIs.

##### Architectural Patterns & Design Principles
- MVVM: clear separation of UI, state (ViewModel), and data.
- Repository Pattern: abstracts data sources.
- Layered Modules: each Gradle module has a single responsibility.
- DI with Hilt: modules injected into consumers.
- AIDL + JNI Bridge: exposes native OS operations through strong-typed interfaces.

##### Technologies & Frameworks
- Kotlin + Coroutines
- Jetpack Compose (UI)
- Hilt (DI)
- Room (SQLite ORM)
- DataStore (Preferences)
- Retrofit/Moshi (Network & JSON)
- AIDL & JNI (Platform integration)
- WebView + embedded HTTP server (WebUI)

##### Essential Elements
– Module boundaries (app, ui, datastore, platform, hidden-api, webui, ext)
– MVVM flow (UI → ViewModel → Repository → DataSource)
– Platform bridge (AIDL → JNI → root operations)
– WebUI asset server and JS interfaces
– Background services and notification utilities
– Database schemas (AppDatabase) and key DataStore serializers

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "app Module"
        direction TB
        UI["UI Components"]:::presentation
        VM["ViewModels"]:::presentation
        Services["Background Services"]:::presentation
    end

    subgraph "ui Module"
        direction TB
        UIComp["Compose UI Library"]:::presentation
    end

    %% Domain Layer
    subgraph "app Module"
        RepoApp["App Repositories"]:::domain
    end

    subgraph "datastore Module"
        DSRepo["UserPreferencesRepository"]:::domain
    end

    subgraph "ext Module"
        Ext["Extensions"]:::domain
    end

    %% Data Layer
    subgraph "app Module"
        direction TB
        Room["Room Database"]:::storage
        DataStoreLocal["DataStore"]:::storage
        Network["Remote Network"]:::data
    end

    subgraph "datastore Module"
        DSDataSource["UserPreferencesDataSource"]:::data
    end

    %% Platform Layer
    subgraph "platform Module"
        direction TB
        AIDL["AIDL Interfaces"]:::platform
        JNI["JNI/C++ Layer"]:::platform
        PlatAPI["Platform API & ServiceManager"]:::platform
    end

    subgraph "hidden-api Module"
        Hidden["Hidden-API Stubs"]:::platform
    end

    %% WebUI Layer
    subgraph "webui Module"
        direction TB
        Assets["WebUI Assets"]:::webui
        AssetLoader["WebUIAssetLoader"]:::webui
        Handlers["WebUI Handlers"]:::webui
        Bridge["JS-Kotlin Bridge"]:::webui
    end

    %% MVVM Flow
    UI -->|"injects"| VM
    VM -->|"uses"| RepoApp
    VM -->|"uses"| DSRepo
    VM -->|"uses ext"| Ext

    %% Repository to DataSources
    RepoApp -->|"reads/writes"| Room
    RepoApp -->|"reads/writes"| DataStoreLocal
    RepoApp -->|"calls"| Network
    DSRepo -->|"reads/writes"| DSDataSource

    %% Services interactions
    Services -->|"calls"| RepoApp
    Services -->|"calls"| PlatAPI

    %% Platform interactions
    RepoApp -->|"AIDL calls"| AIDL
    AIDL -->|"JNI bridge"| JNI
    JNI -->|"executes"| PlatAPI

    %% WebUI Flow
    Assets -->|"served by"| AssetLoader
    AssetLoader -->|"routes to"| Handlers
    Handlers -->|"invokes repos"| RepoApp
    Handlers -->|"invokes platform"| PlatAPI
    Handlers -->|"communicates via"| Bridge

    %% Cross-module integration
    UIComp -->|"composable libs"| UI
    Ext -->|"helpers"| RepoApp

    %% Click Events
    click UI "https://github.com/mmrlapp/mmrl/tree/master/app/src/main/kotlin/com/dergoogler/mmrl/ui"
    click VM "https://github.com/mmrlapp/mmrl/tree/master/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel"
    click RepoApp "https://github.com/mmrlapp/mmrl/tree/master/app/src/main/kotlin/com/dergoogler/mmrl/repository"
    click DSRepo "https://github.com/mmrlapp/mmrl/blob/master/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/repository/UserPreferencesRepository.kt"
    click Room "https://github.com/mmrlapp/mmrl/blob/master/app/src/main/kotlin/com/dergoogler/mmrl/database/AppDatabase.kt"
    click DataStoreLocal "https://github.com/mmrlapp/mmrl/blob/master/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/UserPreferencesDataSource.kt"
    click Network "https://github.com/mmrlapp/mmrl/blob/master/app/src/main/kotlin/com/dergoogler/mmrl/network/Network.kt"
    click AIDL "https://github.com/mmrlapp/mmrl/tree/master/platform/src/main/aidl/com/dergoogler/mmrl/platform/content"
    click JNI "https://github.com/mmrlapp/mmrl/tree/master/platform/src/main/jni"
    click PlatAPI "https://github.com/mmrlapp/mmrl/blob/master/platform/src/main/kotlin/com/dergoogler/mmrl/platform/service/ServiceManager.kt"
    click Hidden "https://github.com/mmrlapp/mmrl/tree/master/hidden-api/src/main/java/android"
    click Ext "https://github.com/mmrlapp/mmrl/tree/master/ext/src/main/kotlin/com/dergoogler/mmrl/ext"
    click UIComp "https://github.com/mmrlapp/mmrl/tree/master/ui/src/main/kotlin/com/dergoogler/mmrl/ui/component"
    click Assets "https://github.com/mmrlapp/mmrl/tree/master/webui/src/main/assets/webui"
    click AssetLoader "https://github.com/mmrlapp/mmrl/blob/master/webui/src/main/kotlin/com/dergoogler/mmrl/webui/WebUIAssetLoader.kt"
    click Handlers "https://github.com/mmrlapp/mmrl/tree/master/webui/src/main/kotlin/com/dergoogler/mmrl/webui/handler"
    click Bridge "https://github.com/mmrlapp/mmrl/blob/master/webui/src/main/kotlin/com/dergoogler/mmrl/webui/client/WebUIClient.kt"

    %% Styles
    classDef presentation fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef domain      fill:#D2F8D2,stroke:#333,stroke-width:1px
    classDef data        fill:#FFD8B1,stroke:#333,stroke-width:1px
    classDef storage     fill:#FFEB99,stroke:#333,stroke-width:1px
    classDef platform    fill:#FFC1C1,stroke:#333,stroke-width:1px
    classDef webui       fill:#E5C1FF,stroke:#333,stroke-width:1px
```
