How morpheapp/morphe-manager works
1. Product shape
- This is an Android Kotlin app that manages and runs local APK patching for YouTube, YouTube Music, and Reddit.
- The key architectural constraint is that patching happens on-device; APKs and user data are not uploaded to a backend.
2. Top-level layers
- The codebase is organized into a fairly standard presentation / domain / data / infrastructure split.
- ui contains Compose screens, dialogs, and view models.
- domain contains repositories, installers, managers, patching logic, and workers.
- data contains Room entities/DAOs plus platform wrappers and Redux-like state management utilities.
- network contains API clients and release/update DTOs.
- service contains long-lived Android services for privileged work and messaging.
3. User interface and state flow
- The main navigation is centered around Home, Patcher, and Settings screens.
- UI is built with Jetpack Compose and driven by view models such as HomeViewModel, PatcherViewModel, SettingsViewModel, and UpdateViewModel.
- UI state is converted into patch selections, install actions, and preference updates through repositories and managers rather than directly touching storage or patching code.
4. Patching subsystem
- The core patching engine lives under patcher.
- It includes patch bundle parsing, library resolution, split-APK inspection/merging, runtime execution, logging, and a separate process runtime.
- Important boundary: the patcher is not just a library call from UI; it can run in a dedicated process for stability and memory control, with AIDL interfaces under patcher/runtime/process.
5. APK acquisition and manipulation flow
- The app operates on original APKs and patch bundles as separate inputs.
- Split APK support is explicit: split packages are inspected, merged, and filtered by architecture/locale/density before patching.
- After patching, native libraries may be stripped for unsupported architectures to produce an installable output APK.
6. Storage and persistence
- Persistent state is handled with Room via AppDatabase.
- The database stores installed apps, original APK metadata, applied patches, patch bundles, options, selections, and “seen” state.
- Schema history and migration files indicate long-lived user data and frequent app evolution, so persistence is a meaningful architectural boundary.
7. Repositories and managers
- Repositories in domain/repository mediate all data access for apps, selections, bundles, and options.
- Managers in domain/manager encapsulate cross-cutting concerns such as app icons, keystores, preferences, and patch-option persistence.
- This keeps UI and patcher logic decoupled from Room and shared preference details.
8. Installer architecture
- Installation is abstracted behind an installer layer with multiple strategies:
- standard Android session installation,
- root-based installation,
- Shizuku-based installation,
- and any detected third-party installer apps.
- InstallerManager chooses between these paths, and the app can prompt per session for the desired installer.
- This is a major boundary because post-patch installation depends on device privileges and runtime environment.
9. Privilege and service boundaries
- Root-related behavior is isolated in service/RootService and root-specific assets under assets/root.
- The app also declares an AIDL root system service interface, showing that some operations are delegated across process/service boundaries rather than executed inline in the UI.
- This separation matters for diagramming because patching, privileged install, and system-level operations are not all in one execution context.
10. Network and update model
- The app contacts remote services through network/api/MorpheAPI and related DTOs for release metadata.
- It uses GitHub release information plus source/bundle metadata to discover updates and patch bundle releases.
- UpdateCheckWorker and notification utilities indicate background update polling and user-visible update alerts.
11. Patch sources and bundle management
- Patch content is treated as an external “bundle” source, with both local and remote bundle models.
- Users can add compatible patch bundles via GitHub URL or deep link, and sources can expose pre-release channels.
- This makes patch definitions a dynamic input rather than a compile-time asset, which is important for the architecture diagram.
12. Preferences, import/export, and device customization
- Settings are split across appearance, system, advanced, and patch-option domains.
- The app supports import/export of Morphe settings and keystores, plus per-app patch selection persistence.
- Theme, locale, app icon, background, and accent color choices are persistent configuration concerns handled separately from patching.
13. Background work and messaging
- One-off or periodic background tasks are handled with Android WorkManager via the worker module.
- Firebase Cloud Messaging is present (google-services.json, MorpheFcmService), which supports remote notifications for things like update events.
- The repo also includes a helper script for FCM testing in CI, showing messaging is part of the operational architecture.
14. Build, release, and localization pipeline
- The project is built with Gradle Kotlin DSL and uses Android-specific tooling plus a native C++ component (cpp/prop_override.cpp).
- GitHub Actions drive PR builds, releases, Crowdin translation sync, and FCM testing.
- The large set of localized values-xx resources and Crowdin workflows show that localization is a first-class part of the delivery pipeline, not an afterthought.
Main entry points: viewmodel View Models · patcher Patch Engine · screen Compose Screens · MorpheAPI.kt Morphe API
Components 23
App Shell
Application entrypoints and DI wiring
- Main Activity · Host activity and app entry UI container
app/src/main/java/app/morphe/manager/MainActivity.kt - App Class · Application lifecycle and startup wiring
app/src/main/java/app/morphe/manager/ManagerApplication.kt
UI
Compose screens, dialogs, and view models
- View Models · Home, patcher, settings, install, and update state orchestration
app/src/main/java/app/morphe/manager/ui/viewmodel - Compose Screens · Home, patcher, and settings navigation surfaces
app/src/main/java/app/morphe/manager/ui/screen - Home Flow · Installed apps, sources, onboarding, and update prompts
app/src/main/java/app/morphe/manager/ui/screen/home - Patcher Flow · Patch selection and progress views for local APK patching
app/src/main/java/app/morphe/manager/ui/screen/patcher - Settings Flow · Appearance, system, advanced, and patch options screens
app/src/main/java/app/morphe/manager/ui/screen/settings
Domain
Repositories, managers, installers, and background workers
- Repositories · App, APK, bundle, selection, and option repositories
app/src/main/java/app/morphe/manager/domain/repository - Managers · Preferences, keystore, icons, and patch-option persistence
app/src/main/java/app/morphe/manager/domain/manager - Installer Layer · Chooses session, root, Shizuku, or external installer paths
app/src/main/java/app/morphe/manager/domain/installer - Domain Workers · Shared worker abstractions and app work coordination
app/src/main/java/app/morphe/manager/domain/worker
Data
Room persistence and platform state wrappers
- App Database · Room database for apps, bundles, options, selections, and migrations
app/src/main/java/app/morphe/manager/data/room/AppDatabase.kt - Room Models · Installed/original apps, bundles, options, selections, and DAOs
app/src/main/java/app/morphe/manager/data/room - Redux State · Redux-like state helpers and cross-screen state shaping
app/src/main/java/app/morphe/manager/data/redux/Redux.kt
Patcher
On-device APK patching engine and runtime
- Patch Engine · Bundle parsing, library resolution, and patch session control
app/src/main/java/app/morphe/manager/patcher - Split APK Flow · Inspects, prepares, merges, and filters split APK inputs
app/src/main/java/app/morphe/manager/patcher/split - Runtime · Coroutine and process runtimes with memory monitoring
app/src/main/java/app/morphe/manager/patcher/runtime - Process IPC · AIDL interfaces for dedicated patcher process execution
app/src/main/java/app/morphe/manager/patcher/runtime/process
Network
Remote API, releases, and DTOs
- Morphe API · HTTP API client and release/update service access
app/src/main/java/app/morphe/manager/network/api/MorpheAPI.kt - Release DTOs · GitHub release and manager/patch release metadata models
app/src/main/java/app/morphe/manager/network/dto
Services
Long-lived privileged and messaging services
- Android Services · Root service and FCM messaging service
app/src/main/java/app/morphe/manager/service
Delivery
Native code, resources, and release automation
- Native Code · Native property override support for device/runtime behavior
app/src/main/cpp/prop_override.cpp - CI / Release · Gradle, GitHub Actions, Crowdin sync, FCM testing, and release scripts
.github/workflows
Connections 25
- Main Activity → Compose Screens: hosts · Activity presents the Compose navigation shell
- App Class → View Models: provides · Application wiring and shared dependencies
- App Class → Android Services: starts · Registers service-level components
- Compose Screens → Home Flow: navigates · Primary home and source management UI
- Compose Screens → Patcher Flow: navigates · Patch execution and progress UI
- Compose Screens → Settings Flow: navigates · Preferences and app configuration UI
- View Models → Repositories: reads/writes · UI state is mediated through repositories
- View Models → Managers: uses · View models delegate preferences and utility concerns
- View Models → Installer Layer: requests install · Install flows are selected through installer strategies
- View Models → Domain Workers: schedules · Update checks and other background work
- Repositories → App Database: persists · Repositories are backed by Room
- Repositories → Room Models: maps · Repository contracts operate on entities and DAOs
- Managers → Room Models: stores prefs · Patch options and user preferences are persisted separately
- Patcher Flow → Patch Engine: drives · Patch UI orchestrates on-device patching sessions
- Patch Engine → Split APK Flow: prepares inputs · Split APKs are inspected, merged, and filtered before patching
- Patch Engine → Runtime: executes in · Patch execution runs in coroutine or dedicated process runtimes
- Runtime → Process IPC: IPC · Dedicated process runtime uses AIDL interfaces
- Patch Engine → Installer Layer: produces installable · Patched output is handed off to installer strategies
- Morphe API → Release DTOs: returns · Remote release and bundle metadata are modeled as DTOs
- View Models → Morphe API: checks updates · Update view model consumes release metadata
- Domain Workers → Morphe API: polls · Background work can query remote update sources
- Android Services → Process IPC: system bridge · Root/system service boundaries are exposed across processes
- Patch Engine → Native Code: depends on · Patching and privileged behavior can rely on native support
- CI / Release → Morphe API: publishes · CI and release automation feed app and update distribution
- CI / Release → Compose Screens: localizes · Crowdin and resource workflows support UI translation delivery