# bmax121/apatch architecture

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

- Interactive diagram: https://gitdiagram.com/bmax121/apatch
- Repository: https://github.com/bmax121/apatch

## Overview

APatch is an Android kernel-based root and system-patching product. Users manage root access, kernel modules (KPM), Magisk-like modules (APM), and patch installation through the Android app; the app also exposes a WebView interface. A privileged Rust command-line runtime handles boot events, module operations, and system tools. The README documents KernelPatch as the kernel core. Several app and runtime subsystems are represented from the tree and README because their implementations were not excerpted; edges are limited to documented or indexed relationships.

Main entry points: [`apd/src/cli.rs`](https://github.com/bmax121/apatch/blob/main/apd/src/cli.rs) (Command dispatcher), [`app/src/main/java/me/bmax/apatch/ui/MainActivity.kt`](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/MainActivity.kt) (App navigation), [`app/src/main/java/me/bmax/apatch/ui/viewmodel/SuperUserViewModel.kt`](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/viewmodel/SuperUserViewModel.kt) (Root access UI), [`apd/src/module.rs`](https://github.com/bmax121/apatch/blob/main/apd/src/module.rs) (Module operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Android app"]
  node_main["App navigation<br/>[MainActivity.kt]"]
  node_suview["Root access UI"]
  node_patchui["Patch installation"]
  node_patchvm["Patch operations"]
  node_kpmui["KPM management<br/>[KPM.kt]"]
  node_apmui["APM management<br/>[APM.kt]"]
  node_online["Module discovery<br/>[Online.kt]"]
  node_webui["Module WebUI<br/>[WebUIActivity.kt]"]
  node_webfiles["Web file handler"]
  node_natives["Native interface<br/>[Natives.kt]"]
  node_cliapp["App CLI bridge<br/>[APatchCli.kt]"]
end

subgraph group_privileged["Privileged runtime"]
  node_daemon["APatch daemon<br/>[apd.rs]"]
  node_commands["Command dispatcher<br/>[cli.rs]"]
  node_boot["Boot event stages<br/>[event.rs]"]
end

subgraph group_modules["Module management"]
  node_moduleops["Module operations<br/>[module.rs]"]
  node_moduleconfig["Module configuration<br/>[module_config.rs]"]
  node_kpmruntime["Kernel module support<br/>[insmod.rs]"]
  node_metamodule["Metamodule support<br/>[metamodule.rs]"]
end

subgraph group_system["System integration"]
  node_suops["Superuser operations<br/>[supercall.rs]"]
  node_resetprop["Property tooling<br/>[resetprop.rs]"]
  node_policy["SELinux policy<br/>[sepolicy.rs]"]
  node_kernelpatch{{"KernelPatch core"}}
  node_rootservice["Root package service<br/>[RootServices.java]"]
end

node_user(("Device user"))

node_user -->|"uses"| node_main
node_main -->|"uses"| node_suview
node_patchui -->|"delegates"| node_patchvm
node_suview -->|"calls"| node_natives
node_suview -->|"uses"| node_cliapp
node_suview -->|"queries packages"| node_rootservice
node_webui -->|"serves files"| node_webfiles
node_cliapp -.->|"invokes runtime"| node_daemon
node_daemon -->|"runs"| node_commands
node_commands -->|"dispatches"| node_boot
node_commands -->|"dispatches"| node_moduleops
node_commands -->|"dispatches"| node_moduleconfig
node_commands -->|"dispatches"| node_kpmruntime
node_commands -.->|"dispatches"| node_metamodule
node_commands -->|"dispatches"| node_suops
node_commands -->|"dispatches"| node_resetprop
node_commands -->|"dispatches"| node_policy
node_boot -->|"runs stages"| node_moduleops
node_moduleops -->|"reads config"| node_moduleconfig
node_moduleops -->|"loads policy"| node_policy
node_kpmruntime -.->|"supports kernel modules"| node_kernelpatch
node_main -.->|"navigates"| node_patchui
node_main -.->|"navigates"| node_kpmui
node_main -.->|"navigates"| node_apmui
node_main -.->|"navigates"| node_online

click node_main "https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/MainActivity.kt"
click node_suview "https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/viewmodel/SuperUserViewModel.kt"
click node_patchui "https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/screen/InstallModeSelect.kt"
click node_patchvm "https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/viewmodel/PatchesViewModel.kt"
click node_kpmui "https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/screen/KPM.kt"
click node_apmui "https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/screen/APM.kt"
click node_online "https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/screen/Online.kt"
click node_webui "https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/WebUIActivity.kt"
click node_webfiles "https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/webui/SuFilePathHandler.java"
click node_natives "https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/Natives.kt"
click node_cliapp "https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/util/APatchCli.kt"
click node_daemon "https://github.com/bmax121/apatch/blob/main/apd/src/apd.rs"
click node_commands "https://github.com/bmax121/apatch/blob/main/apd/src/cli.rs"
click node_boot "https://github.com/bmax121/apatch/blob/main/apd/src/event.rs"
click node_moduleops "https://github.com/bmax121/apatch/blob/main/apd/src/module.rs"
click node_moduleconfig "https://github.com/bmax121/apatch/blob/main/apd/src/module_config.rs"
click node_kpmruntime "https://github.com/bmax121/apatch/blob/main/apd/src/insmod.rs"
click node_metamodule "https://github.com/bmax121/apatch/blob/main/apd/src/metamodule.rs"
click node_suops "https://github.com/bmax121/apatch/blob/main/apd/src/supercall.rs"
click node_resetprop "https://github.com/bmax121/apatch/blob/main/apd/src/resetprop.rs"
click node_policy "https://github.com/bmax121/apatch/blob/main/apd/src/sepolicy.rs"
click node_rootservice "https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/services/RootServices.java"

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_main,node_suview,node_patchui,node_patchvm,node_kpmui,node_apmui,node_online,node_webui,node_webfiles,node_natives,node_cliapp,node_user toneBlue
class node_daemon,node_commands,node_boot toneAmber
class node_moduleops,node_moduleconfig,node_kpmruntime,node_metamodule toneMint
class node_suops,node_resetprop,node_policy,node_kernelpatch,node_rootservice toneRose
```

## Components

### Android app

- [App navigation](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/MainActivity.kt): `app/src/main/java/me/bmax/apatch/ui/MainActivity.kt`
- [Root access UI](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/viewmodel/SuperUserViewModel.kt): `app/src/main/java/me/bmax/apatch/ui/viewmodel/SuperUserViewModel.kt`
- [Patch installation](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/screen/InstallModeSelect.kt): `app/src/main/java/me/bmax/apatch/ui/screen/InstallModeSelect.kt`
- [Patch operations](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/viewmodel/PatchesViewModel.kt): `app/src/main/java/me/bmax/apatch/ui/viewmodel/PatchesViewModel.kt`
- [KPM management](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/screen/KPM.kt): `app/src/main/java/me/bmax/apatch/ui/screen/KPM.kt`
- [APM management](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/screen/APM.kt): `app/src/main/java/me/bmax/apatch/ui/screen/APM.kt`
- [Module discovery](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/screen/Online.kt): `app/src/main/java/me/bmax/apatch/ui/screen/Online.kt`
- [Module WebUI](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/WebUIActivity.kt): `app/src/main/java/me/bmax/apatch/ui/WebUIActivity.kt`
- [Web file handler](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/ui/webui/SuFilePathHandler.java): `app/src/main/java/me/bmax/apatch/ui/webui/SuFilePathHandler.java`
- [Native interface](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/Natives.kt): `app/src/main/java/me/bmax/apatch/Natives.kt`
- [App CLI bridge](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/util/APatchCli.kt): `app/src/main/java/me/bmax/apatch/util/APatchCli.kt`

### Privileged runtime

- [APatch daemon](https://github.com/bmax121/apatch/blob/main/apd/src/apd.rs): `apd/src/apd.rs`
- [Command dispatcher](https://github.com/bmax121/apatch/blob/main/apd/src/cli.rs): `apd/src/cli.rs`
- [Boot event stages](https://github.com/bmax121/apatch/blob/main/apd/src/event.rs): `apd/src/event.rs`

### Module management

- [Module operations](https://github.com/bmax121/apatch/blob/main/apd/src/module.rs): `apd/src/module.rs`
- [Module configuration](https://github.com/bmax121/apatch/blob/main/apd/src/module_config.rs): `apd/src/module_config.rs`
- [Kernel module support](https://github.com/bmax121/apatch/blob/main/apd/src/insmod.rs): `apd/src/insmod.rs`
- [Metamodule support](https://github.com/bmax121/apatch/blob/main/apd/src/metamodule.rs): `apd/src/metamodule.rs`

### System integration

- [Superuser operations](https://github.com/bmax121/apatch/blob/main/apd/src/supercall.rs): `apd/src/supercall.rs`
- [Property tooling](https://github.com/bmax121/apatch/blob/main/apd/src/resetprop.rs): `apd/src/resetprop.rs`
- [SELinux policy](https://github.com/bmax121/apatch/blob/main/apd/src/sepolicy.rs): `apd/src/sepolicy.rs`
- **KernelPatch core**
- [Root package service](https://github.com/bmax121/apatch/blob/main/app/src/main/java/me/bmax/apatch/services/RootServices.java): `app/src/main/java/me/bmax/apatch/services/RootServices.java`

### Other components

- **Device user**

## Connections

- Device user → App navigation: uses (evidence: `README.md`)
- App navigation → Root access UI: uses (evidence: `app/src/main/java/me/bmax/apatch/ui/MainActivity.kt`)
- Patch installation → Patch operations: delegates (evidence: `app/src/main/java/me/bmax/apatch/ui/screen/InstallModeSelect.kt`)
- Root access UI → Native interface: calls (evidence: `app/src/main/java/me/bmax/apatch/ui/viewmodel/SuperUserViewModel.kt`)
- Root access UI → App CLI bridge: uses (evidence: `app/src/main/java/me/bmax/apatch/ui/viewmodel/SuperUserViewModel.kt`)
- Root access UI → Root package service: queries packages (evidence: `app/src/main/java/me/bmax/apatch/ui/viewmodel/SuperUserViewModel.kt`)
- Module WebUI → Web file handler: serves files (evidence: `app/src/main/java/me/bmax/apatch/ui/WebUIActivity.kt`)
- App CLI bridge → APatch daemon: invokes runtime
- APatch daemon → Command dispatcher: runs (evidence: `apd/src/main.rs`)
- Command dispatcher → Boot event stages: dispatches (evidence: `apd/src/cli.rs`)
- Command dispatcher → Module operations: dispatches (evidence: `apd/src/cli.rs`)
- Command dispatcher → Module configuration: dispatches (evidence: `apd/src/cli.rs`)
- Command dispatcher → Kernel module support: dispatches (evidence: `apd/src/cli.rs`)
- Command dispatcher → Metamodule support: dispatches
- Command dispatcher → Superuser operations: dispatches (evidence: `apd/src/cli.rs`)
- Command dispatcher → Property tooling: dispatches (evidence: `apd/src/cli.rs`)
- Command dispatcher → SELinux policy: dispatches (evidence: `apd/src/cli.rs`)
- Boot event stages → Module operations: runs stages (evidence: `apd/src/event.rs`)
- Module operations → Module configuration: reads config (evidence: `apd/src/module.rs`)
- Module operations → SELinux policy: loads policy (evidence: `apd/src/module.rs`)
- Kernel module support → KernelPatch core: supports kernel modules (evidence: `README.md`)
- App navigation → Patch installation: navigates
- App navigation → KPM management: navigates
- App navigation → APM management: navigates
- App navigation → Module discovery: navigates
