# topjohnwu/magisk architecture

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

- Interactive diagram: https://gitdiagram.com/topjohnwu/magisk
- Repository: https://github.com/topjohnwu/magisk

## Overview

Magisk is an Android root-management suite. The principal workflow is: a user opens the manager, selects an update or module, the app schedules or starts a download, fetches it from a release source, processes it, and presents progress or completion. The broader product also manages superuser policy, DenyList behavior, module flashing, boot-image patching, and Zygisk injection. The graph combines README capabilities with sampled implementation; several UI-to-native links remain intentionally conservative.

Main entry points: [`app/core/src/main/java/com/topjohnwu/magisk/core/download/DownloadEngine.kt`](https://github.com/topjohnwu/magisk/blob/master/app/core/src/main/java/com/topjohnwu/magisk/core/download/DownloadEngine.kt) (Download Engine), [`app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt`](https://github.com/topjohnwu/magisk/blob/master/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt) (Main Activity), [`native/src/core/su/mod.rs`](https://github.com/topjohnwu/magisk/blob/master/native/src/core/su/mod.rs) (MagiskSU), [`native/src/core/daemon.rs`](https://github.com/topjohnwu/magisk/blob/master/native/src/core/daemon.rs) (Magisk Daemon)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Manager UI"]
  node_main_activity["Main Activity<br/>[MainActivity.kt]"]
  node_main_screen["Main Screen<br/>[MainScreen.kt]"]
  node_module_screen["Module Screen<br/>[ModuleScreen.kt]"]
  node_superuser_screen["Superuser Screen<br/>[SuperuserScreen.kt]"]
  node_install_dialog["Install Dialog"]
end

subgraph group_services["App Services"]
  node_download_engine["Download Engine<br/>[DownloadEngine.kt]"]
  node_job_service["Job Service<br/>[JobService.kt]"]
  node_download_processor["Download Processor"]
  node_network_service["Network Service<br/>[NetworkService.kt]"]
  node_magisk_db[("Policy Database<br/>[MagiskDB.kt]")]
end

subgraph group_native["Native Runtime"]
  node_magisk_daemon["Magisk Daemon<br/>[daemon.rs]"]
  node_magisk_su["MagiskSU<br/>[mod.rs]"]
  node_deny_list["DenyList<br/>[deny.hpp]"]
  node_zygisk["Zygisk<br/>[mod.rs]"]
end

subgraph group_boot["Boot Modules"]
  node_flash_zip["Flash Zip<br/>[FlashZip.kt]"]
  node_magisk_boot["MagiskBoot<br/>[lib.rs]"]
end

subgraph group_packaging["APK Loading"]
  node_stub_loader["Stub Loader<br/>[DynLoad.java]"]
end

node_android_user(("Android User"))
node_android_apps(("Android Apps"))
node_android_os(("Android OS"))
node_github(("Release Sources"))
node_boot_image["Boot Image"]

node_android_user -->|"opens"| node_main_activity
node_main_activity -->|"renders"| node_main_screen
node_android_user -->|"confirms install"| node_install_dialog
node_install_dialog -->|"starts download"| node_download_engine
node_android_os -->|"dispatches jobs"| node_job_service
node_job_service -->|"starts download"| node_download_engine
node_download_engine -->|"fetches file"| node_network_service
node_network_service -.->|"requests releases"| node_github
node_download_engine -->|"processes stream"| node_download_processor
node_download_engine -->|"updates notifications"| node_android_os
node_android_user -->|"manages modules"| node_module_screen
node_module_screen -->|"starts flashing"| node_flash_zip
node_flash_zip -->|"patches images"| node_magisk_boot
node_magisk_boot -->|"unpacks repacks"| node_boot_image
node_android_apps -->|"requests root"| node_magisk_su
node_magisk_su -->|"reads policies"| node_magisk_db
node_superuser_screen -->|"manages policies"| node_magisk_db
node_magisk_daemon -->|"serves requests"| node_magisk_su
node_magisk_daemon -->|"enforces hiding"| node_deny_list
node_zygisk -->|"injects code"| node_android_apps
node_stub_loader -.->|"loads app"| node_main_activity

click node_main_activity "https://github.com/topjohnwu/magisk/blob/master/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt"
click node_main_screen "https://github.com/topjohnwu/magisk/blob/master/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainScreen.kt"
click node_module_screen "https://github.com/topjohnwu/magisk/blob/master/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleScreen.kt"
click node_superuser_screen "https://github.com/topjohnwu/magisk/blob/master/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserScreen.kt"
click node_install_dialog "https://github.com/topjohnwu/magisk/blob/master/app/apk-legacy/src/main/java/com/topjohnwu/magisk/dialog/ManagerInstallDialog.kt"
click node_download_engine "https://github.com/topjohnwu/magisk/blob/master/app/core/src/main/java/com/topjohnwu/magisk/core/download/DownloadEngine.kt"
click node_job_service "https://github.com/topjohnwu/magisk/blob/master/app/core/src/main/java/com/topjohnwu/magisk/core/JobService.kt"
click node_download_processor "https://github.com/topjohnwu/magisk/blob/master/app/core/src/main/java/com/topjohnwu/magisk/core/download/DownloadProcessor.kt"
click node_network_service "https://github.com/topjohnwu/magisk/blob/master/app/core/src/main/java/com/topjohnwu/magisk/core/repository/NetworkService.kt"
click node_magisk_db "https://github.com/topjohnwu/magisk/blob/master/app/core/src/main/java/com/topjohnwu/magisk/core/data/magiskdb/MagiskDB.kt"
click node_magisk_daemon "https://github.com/topjohnwu/magisk/blob/master/native/src/core/daemon.rs"
click node_magisk_su "https://github.com/topjohnwu/magisk/blob/master/native/src/core/su/mod.rs"
click node_deny_list "https://github.com/topjohnwu/magisk/blob/master/native/src/core/deny/deny.hpp"
click node_zygisk "https://github.com/topjohnwu/magisk/blob/master/native/src/core/zygisk/mod.rs"
click node_flash_zip "https://github.com/topjohnwu/magisk/blob/master/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/FlashZip.kt"
click node_magisk_boot "https://github.com/topjohnwu/magisk/blob/master/native/src/boot/lib.rs"
click node_stub_loader "https://github.com/topjohnwu/magisk/blob/master/app/stub/src/main/java/com/topjohnwu/magisk/DynLoad.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_activity,node_main_screen,node_module_screen,node_superuser_screen,node_install_dialog,node_android_user toneBlue
class node_download_engine,node_job_service,node_download_processor,node_network_service,node_magisk_db toneAmber
class node_magisk_daemon,node_magisk_su,node_deny_list,node_zygisk toneMint
class node_flash_zip,node_magisk_boot toneRose
class node_stub_loader,node_android_apps,node_android_os,node_github,node_boot_image toneIndigo
```

## Components

### Manager UI

- [Main Activity](https://github.com/topjohnwu/magisk/blob/master/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt): `app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt`
- [Main Screen](https://github.com/topjohnwu/magisk/blob/master/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainScreen.kt): `app/apk/src/main/java/com/topjohnwu/magisk/ui/MainScreen.kt`
- [Module Screen](https://github.com/topjohnwu/magisk/blob/master/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleScreen.kt): `app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleScreen.kt`
- [Superuser Screen](https://github.com/topjohnwu/magisk/blob/master/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserScreen.kt): `app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserScreen.kt`
- [Install Dialog](https://github.com/topjohnwu/magisk/blob/master/app/apk-legacy/src/main/java/com/topjohnwu/magisk/dialog/ManagerInstallDialog.kt): `app/apk-legacy/src/main/java/com/topjohnwu/magisk/dialog/ManagerInstallDialog.kt`

### App Services

- [Download Engine](https://github.com/topjohnwu/magisk/blob/master/app/core/src/main/java/com/topjohnwu/magisk/core/download/DownloadEngine.kt): `app/core/src/main/java/com/topjohnwu/magisk/core/download/DownloadEngine.kt`
- [Job Service](https://github.com/topjohnwu/magisk/blob/master/app/core/src/main/java/com/topjohnwu/magisk/core/JobService.kt): `app/core/src/main/java/com/topjohnwu/magisk/core/JobService.kt`
- [Download Processor](https://github.com/topjohnwu/magisk/blob/master/app/core/src/main/java/com/topjohnwu/magisk/core/download/DownloadProcessor.kt): `app/core/src/main/java/com/topjohnwu/magisk/core/download/DownloadProcessor.kt`
- [Network Service](https://github.com/topjohnwu/magisk/blob/master/app/core/src/main/java/com/topjohnwu/magisk/core/repository/NetworkService.kt): `app/core/src/main/java/com/topjohnwu/magisk/core/repository/NetworkService.kt`
- [Policy Database](https://github.com/topjohnwu/magisk/blob/master/app/core/src/main/java/com/topjohnwu/magisk/core/data/magiskdb/MagiskDB.kt): `app/core/src/main/java/com/topjohnwu/magisk/core/data/magiskdb/MagiskDB.kt`

### Native Runtime

- [Magisk Daemon](https://github.com/topjohnwu/magisk/blob/master/native/src/core/daemon.rs): `native/src/core/daemon.rs`
- [MagiskSU](https://github.com/topjohnwu/magisk/blob/master/native/src/core/su/mod.rs): `native/src/core/su/mod.rs`
- [DenyList](https://github.com/topjohnwu/magisk/blob/master/native/src/core/deny/deny.hpp): `native/src/core/deny/deny.hpp`
- [Zygisk](https://github.com/topjohnwu/magisk/blob/master/native/src/core/zygisk/mod.rs): `native/src/core/zygisk/mod.rs`

### Boot Modules

- [Flash Zip](https://github.com/topjohnwu/magisk/blob/master/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/FlashZip.kt): `app/core/src/main/java/com/topjohnwu/magisk/core/tasks/FlashZip.kt`
- [MagiskBoot](https://github.com/topjohnwu/magisk/blob/master/native/src/boot/lib.rs): `native/src/boot/lib.rs`

### APK Loading

- [Stub Loader](https://github.com/topjohnwu/magisk/blob/master/app/stub/src/main/java/com/topjohnwu/magisk/DynLoad.java): `app/stub/src/main/java/com/topjohnwu/magisk/DynLoad.java`

### Other components

- **Android User**
- **Android Apps**
- **Android OS**
- **Release Sources**
- **Boot Image**

## Connections

- Android User → Main Activity: opens
- Main Activity → Main Screen: renders
- Android User → Install Dialog: confirms install
- Install Dialog → Download Engine: starts download
- Android OS → Job Service: dispatches jobs
- Job Service → Download Engine: starts download
- Download Engine → Network Service: fetches file
- Network Service → Release Sources: requests releases
- Download Engine → Download Processor: processes stream
- Download Engine → Android OS: updates notifications
- Android User → Module Screen: manages modules
- Module Screen → Flash Zip: starts flashing
- Flash Zip → MagiskBoot: patches images
- MagiskBoot → Boot Image: unpacks repacks
- Android Apps → MagiskSU: requests root
- MagiskSU → Policy Database: reads policies
- Superuser Screen → Policy Database: manages policies
- Magisk Daemon → MagiskSU: serves requests
- Magisk Daemon → DenyList: enforces hiding
- Zygisk → Android Apps: injects code
- Stub Loader → Main Activity: loads app
