How morpheapp/morphe-cli works
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: PatchEngine.kt Patch engine · MainCommand.kt Main · HomeViewModel.kt ViewModels · PatchCommand.kt Patch cmd
Components 21
CLI
Terminal commands and command execution
- Main · Top-level command tree for the terminal interface
src/main/kotlin/app/morphe/cli/command/MainCommand.kt - Patch cmd · Runs patching and output generation from the CLI
src/main/kotlin/app/morphe/cli/command/PatchCommand.kt - List patches · Lists available patches and compatible versions
src/main/kotlin/app/morphe/cli/command/ListPatchesCommand.kt - Options · Parses serializable patch options and command results
src/main/kotlin/app/morphe/cli/command/OptionsCommand.kt - Utility cmds · Install and uninstall commands for device-side operations
src/main/kotlin/app/morphe/cli/command/utility/UtilityCommand.kt - CLI I/O · 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 · Coordinates patch application and backend orchestration
src/main/kotlin/app/morphe/engine/PatchEngine.kt - Data model · Shared runtime data and release/version context
src/main/kotlin/app/morphe/engine/MorpheData.kt - Multi-source · Combines patch data from multiple sources
src/main/kotlin/app/morphe/engine/MultiSourceLoader.kt - Platform check · Validates platform and compatibility constraints
src/main/kotlin/app/morphe/engine/PlatformCheck.kt - Updater · Checks for newer releases and update metadata
src/main/kotlin/app/morphe/engine/UpdateChecker.kt - Patch sources · Remote patch source implementations and bundle loading
src/main/kotlin/app/morphe/engine/patches/RemotePatchSourceFactory.kt - APK utils · 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 · Compose desktop startup and application wiring
src/main/kotlin/app/morphe/gui/App.kt - DI module · Provides dependency injection for the desktop app
src/main/kotlin/app/morphe/gui/di/AppModule.kt - Repositories · Configuration, patch preferences, patch inventory, and updates
src/main/kotlin/app/morphe/gui/data/repository/PatchRepository.kt - Screens · Home, patches, patching, quick patch, and result screens
src/main/kotlin/app/morphe/gui/ui/screens/home/HomeScreen.kt - ViewModels · Screen state and orchestration for Compose flows
src/main/kotlin/app/morphe/gui/ui/screens/home/HomeViewModel.kt - Device tools · ADB, device monitoring, download resolution, and patch execution bridge
src/main/kotlin/app/morphe/gui/util/AdbManager.kt - UI helpers · File, checksum, source-loading, and support-metadata helpers
src/main/kotlin/app/morphe/gui/util/FileUtils.kt
Other components
- Launcher · Starts CLI or GUI runtime
src/main/kotlin/app/morphe/MorpheLauncher.kt
Connections 27
- 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