# morpheapp/morphe-cli architecture

> Architecture diagram of the GitHub repository morpheapp/morphe-cli, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/morpheapp/morphe-cli
- Repository: https://github.com/morpheapp/morphe-cli

## Overview

1. **Repository shape**
   - This repo is a Kotlin/Gradle application that ships two front ends over a shared patching core: a **command-line tool** and a **Compose-based desktop GUI**.
   - The architectural center is the `app.morphe.engine` package; both UIs call into it rather than implementing patching logic themselves.

2. **Primary user flows**
   - The main flow is: **user selects an APK/app target → Morphe loads patch bundles and metadata → patches are applied → a signed/output APK is produced**.
   - Secondary flows include **listing available patches/versions**, **installing/uninstalling apps via ADB or root**, and **checking for updates**.

3. **Core patching engine**
   - `PatchEngine`, `MorpheData`, `MultiSourceLoader`, and `PlatformCheck` form the backend that coordinates patch application.
   - `engine/model/Release.kt` suggests the engine also reasons about release/version information as part of compatibility and update handling.
   - This layer is the main boundary between UI/commands and low-level APK manipulation.

4. **Patch bundle and source integration**
   - Patch definitions are loaded from local or remote sources through `engine/patches/*`.
   - `GitHubPatchSource`, `GitLabPatchSource`, `RemotePatchSource`, and `RemotePatchSourceFactory` indicate the app can resolve patch bundles from multiple hosted sources.
   - `PatchBundleLoader` is the bridge from downloaded bundle content into the engine’s internal patch model.

5. **APK/file-processing utilities**
   - `engine/util/ApkManifestReader`, `ApkOutputNaming`, `KeystoreSigner`, and `PortablePaths` are the low-level file/APK helpers.
   - These utilities are the boundary where the app touches the actual APK artifact: reading package metadata, naming outputs, signing outputs, and dealing with filesystem portability.
   - `gui/util/ChecksumUtils`, `FileUtils`, and related helpers support the same artifact-handling concerns on the UI side.

6. **CLI subsystem**
   - `app.morphe.cli.command` contains the command tree for the terminal interface.
   - `MainCommand`, `PatchCommand`, `ListPatchesCommand`, `OptionsCommand`, and the `utility` subcommands (`InstallCommand`, `UninstallCommand`) expose the supported operations.
   - `CliHttpClient`, `PatchFileResolver`, and `CommandUtils` handle CLI-side resolution of remote/local inputs and user-facing command execution.
   - `cli/command/model/*` captures structured command results such as patch failures, patch steps, and serializable patch options.

7. **GUI application shell**
   - The desktop app starts in `gui/GuiMain.kt` and `gui/App.kt`.
   - The UI is organized as a screen-based Compose application with distinct flows for **home**, **patch selection**, **patching progress**, **quick patch**, and **result**.
   - `gui/di/AppModule.kt` provides dependency wiring for the UI layer.

8. **GUI state and data repositories**
   - `gui/data/repository/*` is the persistence and coordination layer behind the desktop UI.
   - `ConfigRepository` and `ConfigMigration` manage user settings; `PatchPreferencesRepository` persists patch choices; `PatchRepository` and `PatchSourceManager` manage available patches and source enablement.
   - `UpdateCheckRepository` encapsulates update lookup logic for the UI.

9. **GUI domain helpers and device integration**
   - `gui/util/AdbManager` and `DeviceMonitor` indicate the GUI can interact with connected Android devices.
   - `DownloadUrlResolver`, `SupportedAppExtractor`, and `PatchService` connect the UI to downloadable artifacts, supported-app metadata, and the patch execution backend.
   - This layer is where the desktop app crosses from pure UI into device/file operations.

10. **UI composition**
   - The `gui/ui/components` package contains reusable visual building blocks such as dialogs, banners, source selectors, and device indicators.
   - The screen packages (`home`, `patches`, `patching`, `quick`, `result`) represent the actual user journey and are driven by corresponding ViewModels.
   - The separation is classic: **screen state in ViewModels, presentation in Compose components**.

11. **External services and network dependencies**
   - Remote patch retrieval is a first-class architectural concern, with explicit support for **GitHub** and **GitLab** sources.
   - Update checking is also a networked concern, likely tied to release metadata from the project’s hosting platform.
   - The repo’s workflows and release setup reinforce that remote release artifacts are part of the product’s runtime model, not just build-time output.

12. **Build and packaging**
   - The project uses **Gradle Kotlin DSL** with a version catalog and a custom `buildSrc` transformer (`NoticeMergeTransformer`) for packaging notices.
   - `aboutlibraries` and the license/notice files indicate the build collects third-party license information into distributable artifacts.
   - GitHub Actions cover pull-request builds, releases, and documentation updates.

13. **Tests**
   - Tests are concentrated around CLI patching behavior and option parsing under `src/test`.
   - The presence of APK fixtures in `src/test/resources/nowinandroid-apk` shows the test strategy is artifact-driven, validating real patching inputs rather than only isolated unit logic.

14. **How to diagram it**
   - A useful architecture diagram would show two entrypoints—**CLI** and **GUI**—feeding into the shared **engine**.
   - From the engine, show outbound connections to **remote patch sources**, **APK/signing utilities**, and **device/ADB operations**.
   - On the GUI side, add the **repository/DI layer** between screens and the engine, with update/config/storage concerns alongside device monitoring.

Main entry points: [`src/main/kotlin/app/morphe/engine/PatchEngine.kt`](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/PatchEngine.kt) (Patch engine), [`src/main/kotlin/app/morphe/cli/command/MainCommand.kt`](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/MainCommand.kt) (Main), [`src/main/kotlin/app/morphe/gui/ui/screens/home/HomeViewModel.kt`](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/ui/screens/home/HomeViewModel.kt) (ViewModels), [`src/main/kotlin/app/morphe/cli/command/PatchCommand.kt`](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/PatchCommand.kt) (Patch cmd)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI"]
  node_cli_main["Main<br/>cli root<br/>[MainCommand.kt]"]
  node_cli_patch["Patch cmd<br/>cli action<br/>[PatchCommand.kt]"]
  node_cli_list["List patches<br/>cli action"]
  node_cli_opts["Options<br/>cli input<br/>[OptionsCommand.kt]"]
  node_cli_util["Utility cmds<br/>cli utility<br/>[UtilityCommand.kt]"]
  node_cli_io["CLI I/O<br/>cli support<br/>[CommandUtils.kt]"]
end

subgraph group_engine["Engine"]
  node_engine_core{{"Patch engine<br/>core engine<br/>[PatchEngine.kt]"}}
  node_engine_data["Data model<br/>engine state<br/>[MorpheData.kt]"]
  node_engine_loader["Multi-source<br/>engine loader"]
  node_engine_check["Platform check<br/>engine gate<br/>[PlatformCheck.kt]"]
  node_engine_update["Updater<br/>engine service<br/>[UpdateChecker.kt]"]
  node_patch_sources["Patch sources<br/>source adapters"]
  node_apk_utils["APK utils<br/>artifact helpers"]
end

subgraph group_gui["GUI"]
  node_gui_shell(("App shell<br/>desktop entrypoint<br/>[App.kt]"))
  node_gui_di["DI module<br/>gui wiring<br/>[AppModule.kt]"]
  node_gui_repo[("Repositories<br/>gui state<br/>[PatchRepository.kt]")]
  node_gui_view["Screens<br/>compose ui<br/>[HomeScreen.kt]"]
  node_gui_vm["ViewModels<br/>ui state<br/>[HomeViewModel.kt]"]
  node_gui_device["Device tools<br/>device integration<br/>[AdbManager.kt]"]
  node_gui_helpers["UI helpers<br/>gui utilities<br/>[FileUtils.kt]"]
end

node_launcher(("Launcher<br/>app entrypoint<br/>[MorpheLauncher.kt]"))

node_launcher -->|"CLI mode"| node_cli_main
node_launcher -->|"GUI mode"| node_gui_shell
node_cli_main -->|"routes"| node_cli_patch
node_cli_main -->|"routes"| node_cli_list
node_cli_main -->|"routes"| node_cli_opts
node_cli_main -->|"routes"| node_cli_util
node_cli_patch -->|"uses"| node_cli_io
node_cli_patch -->|"invokes"| node_engine_core
node_cli_list -->|"queries"| node_engine_loader
node_cli_opts -->|"serializes"| node_engine_data
node_cli_util -.->|"device ops"| node_gui_device
node_engine_core -->|"reads"| node_engine_data
node_engine_core -->|"loads"| node_engine_loader
node_engine_core -->|"validates"| node_engine_check
node_engine_core -->|"writes apk"| node_apk_utils
node_engine_loader -->|"resolves"| node_patch_sources
node_patch_sources -.->|"feeds"| node_engine_update
node_gui_shell -->|"wires"| node_gui_di
node_gui_shell -->|"shows"| node_gui_view
node_gui_view -->|"state"| node_gui_vm
node_gui_vm -->|"reads/writes"| node_gui_repo
node_gui_vm -->|"patch flow"| node_engine_core
node_gui_vm -->|"device flow"| node_gui_device
node_gui_vm -->|"uses"| node_gui_helpers
node_gui_repo -->|"checks"| node_engine_update
node_gui_repo -->|"manages"| node_patch_sources
node_gui_device -.->|"artifact ops"| node_apk_utils

click node_launcher "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/MorpheLauncher.kt"
click node_cli_main "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/MainCommand.kt"
click node_cli_patch "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/PatchCommand.kt"
click node_cli_list "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/ListPatchesCommand.kt"
click node_cli_opts "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/OptionsCommand.kt"
click node_cli_util "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/utility/UtilityCommand.kt"
click node_cli_io "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/CommandUtils.kt"
click node_engine_core "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/PatchEngine.kt"
click node_engine_data "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/MorpheData.kt"
click node_engine_loader "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/MultiSourceLoader.kt"
click node_engine_check "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/PlatformCheck.kt"
click node_engine_update "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/UpdateChecker.kt"
click node_patch_sources "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/patches/RemotePatchSourceFactory.kt"
click node_apk_utils "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/util/ApkManifestReader.kt"
click node_gui_shell "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/App.kt"
click node_gui_di "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/di/AppModule.kt"
click node_gui_repo "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/data/repository/PatchRepository.kt"
click node_gui_view "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/ui/screens/home/HomeScreen.kt"
click node_gui_vm "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/ui/screens/home/HomeViewModel.kt"
click node_gui_device "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/util/AdbManager.kt"
click node_gui_helpers "https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/util/FileUtils.kt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli_main,node_cli_patch,node_cli_list,node_cli_opts,node_cli_util,node_cli_io toneBlue
class node_engine_core,node_engine_data,node_engine_loader,node_engine_check,node_engine_update,node_patch_sources,node_apk_utils toneAmber
class node_gui_shell,node_gui_di,node_gui_repo,node_gui_view,node_gui_vm,node_gui_device,node_gui_helpers toneMint
class node_launcher toneNeutral
```

## Components

### CLI

Terminal commands and command execution

- [Main](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/MainCommand.kt): cli root · Top-level command tree for the terminal interface · `src/main/kotlin/app/morphe/cli/command/MainCommand.kt`
- [Patch cmd](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/PatchCommand.kt): cli action · Runs patching and output generation from the CLI · `src/main/kotlin/app/morphe/cli/command/PatchCommand.kt`
- [List patches](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/ListPatchesCommand.kt): cli action · Lists available patches and compatible versions · `src/main/kotlin/app/morphe/cli/command/ListPatchesCommand.kt`
- [Options](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/OptionsCommand.kt): cli input · Parses serializable patch options and command results · `src/main/kotlin/app/morphe/cli/command/OptionsCommand.kt`
- [Utility cmds](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/utility/UtilityCommand.kt): cli utility · Install and uninstall commands for device-side operations · `src/main/kotlin/app/morphe/cli/command/utility/UtilityCommand.kt`
- [CLI I/O](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/cli/command/CommandUtils.kt): cli support · Resolves files, HTTP inputs, and execution helpers · `src/main/kotlin/app/morphe/cli/command/CommandUtils.kt`

### Engine

Shared patching and artifact-processing core

- [Patch engine](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/PatchEngine.kt): core engine · Coordinates patch application and backend orchestration · `src/main/kotlin/app/morphe/engine/PatchEngine.kt`
- [Data model](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/MorpheData.kt): engine state · Shared runtime data and release/version context · `src/main/kotlin/app/morphe/engine/MorpheData.kt`
- [Multi-source](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/MultiSourceLoader.kt): engine loader · Combines patch data from multiple sources · `src/main/kotlin/app/morphe/engine/MultiSourceLoader.kt`
- [Platform check](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/PlatformCheck.kt): engine gate · Validates platform and compatibility constraints · `src/main/kotlin/app/morphe/engine/PlatformCheck.kt`
- [Updater](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/UpdateChecker.kt): engine service · Checks for newer releases and update metadata · `src/main/kotlin/app/morphe/engine/UpdateChecker.kt`
- [Patch sources](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/patches/RemotePatchSourceFactory.kt): source adapters · Remote patch source implementations and bundle loading · `src/main/kotlin/app/morphe/engine/patches/RemotePatchSourceFactory.kt`
- [APK utils](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/engine/util/ApkManifestReader.kt): artifact helpers · Reads manifests, names outputs, signs APKs, and normalizes paths · `src/main/kotlin/app/morphe/engine/util/ApkManifestReader.kt`

### GUI

Compose desktop app, state, and device integration

- [App shell](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/App.kt): desktop entrypoint · Compose desktop startup and application wiring · `src/main/kotlin/app/morphe/gui/App.kt`
- [DI module](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/di/AppModule.kt): gui wiring · Provides dependency injection for the desktop app · `src/main/kotlin/app/morphe/gui/di/AppModule.kt`
- [Repositories](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/data/repository/PatchRepository.kt): gui state · Configuration, patch preferences, patch inventory, and updates · `src/main/kotlin/app/morphe/gui/data/repository/PatchRepository.kt`
- [Screens](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/ui/screens/home/HomeScreen.kt): compose ui · Home, patches, patching, quick patch, and result screens · `src/main/kotlin/app/morphe/gui/ui/screens/home/HomeScreen.kt`
- [ViewModels](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/ui/screens/home/HomeViewModel.kt): ui state · Screen state and orchestration for Compose flows · `src/main/kotlin/app/morphe/gui/ui/screens/home/HomeViewModel.kt`
- [Device tools](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/util/AdbManager.kt): device integration · ADB, device monitoring, download resolution, and patch execution bridge · `src/main/kotlin/app/morphe/gui/util/AdbManager.kt`
- [UI helpers](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/gui/util/FileUtils.kt): gui utilities · File, checksum, source-loading, and support-metadata helpers · `src/main/kotlin/app/morphe/gui/util/FileUtils.kt`

### Other components

- [Launcher](https://github.com/morpheapp/morphe-cli/blob/main/src/main/kotlin/app/morphe/MorpheLauncher.kt): app entrypoint · Starts CLI or GUI runtime · `src/main/kotlin/app/morphe/MorpheLauncher.kt`

## Connections

- Launcher → Main: CLI mode · Launches the terminal command tree
- Launcher → App shell: GUI mode · Launches the desktop Compose app
- Main → Patch cmd: routes · Dispatches patching commands
- Main → List patches: routes · Dispatches listing commands
- Main → Options: routes · Dispatches option parsing and result commands
- Main → Utility cmds: routes · Dispatches install and uninstall commands
- Patch cmd → CLI I/O: uses · Resolves input files and command execution details
- Patch cmd → Patch engine: invokes · Runs shared patching logic
- List patches → Multi-source: queries · Loads available patch and version data
- Options → Data model: serializes · Maps CLI options to engine data structures
- Utility cmds → Device tools: device ops · Shares device installation and removal concerns
- Patch engine → Data model: reads · Uses runtime data and release context
- Patch engine → Multi-source: loads · Collects patch bundles from configured sources
- Patch engine → Platform check: validates · Checks compatibility before patching
- Patch engine → APK utils: writes apk · Reads metadata, signs output, and names artifacts
- Multi-source → Patch sources: resolves · Fetches patch bundles from local and remote sources
- Patch sources → Updater: feeds · Supplies release and source metadata for updates
- App shell → DI module: wires · Builds application dependencies
- App shell → Screens: shows · Hosts the screen-based Compose UI
- Screens → ViewModels: state · Screens are driven by ViewModels
- ViewModels → Repositories: reads/writes · Persists config, patch preferences, sources, and updates
- ViewModels → Patch engine: patch flow · Delegates patch execution to the shared engine
- ViewModels → Device tools: device flow · Coordinates ADB and device monitoring
- ViewModels → UI helpers: uses · Supports file handling, checksums, and support metadata
- Repositories → Updater: checks · Encapsulates update lookup for the UI
- Repositories → Patch sources: manages · Tracks enabled patch sources and inventory
- Device tools → APK utils: artifact ops · Works with downloadable APKs and patch outputs
