# tiann/adb_root architecture

> Architecture diagram of the GitHub repository tiann/adb_root, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tiann/adb_root
- Repository: https://github.com/tiann/adb_root

## Overview

##### Project Type and Purpose
- The project is a Magisk module that enables adb root access on production Android builds.
- Its core functionality centers around modifying the standard Android adb behavior by integrating an adbd helper binary built using Android NDK (C++ code in adbd_helper/jni) and packaged as a Magisk module (magisk_module directory).

##### Main Components to Illustrate
a. Build Component:
- “build.sh” Script: Kick-starts the build process.
- GitHub Actions: Under .github/workflows, it triggers an automated build (ndk-build.yml) for cross-compiling native code.
- Android NDK Build Environment: Involved in building the native code by processing Android.mk, Application.mk, lib.cpp, and main.cpp from the adbd_helper folder.
b. adbd_helper:
- Code for the native binary is stored under adbd_helper/jni.
- It compiles into the adbd binary, which is later deployed by the module.
c. Magisk Module:
- The magisk_module directory contains all files required by Magisk to install the module.
- Key files include module.prop (module metadata), updater-script (installation logic), customize.sh, service.sh, sepolicy.rule, etc.
- The “system” directory under magisk_module houses the replacement or new binaries and configuration, such as the adbd binary under system/apex.
d. Deployment and Integration Environment:
- Magisk framework on Android devices: Acts as the container environment in which this module operates.
- Interaction with Android’s system layer: How the new adbd binary is integrated into a production build device.

##### Relationships and Interactions
- The build component (build.sh, GitHub workflows, NDK build scripts) compiles adbd_helper’s native code.
- The resultant binary from adbd_helper is then integrated within the structure of the Magisk module.
- The Magisk module (with its updater-script and configuration files) installs the modified adbd binary and any required configurations (like sepolicy changes) into the Android system.
- At runtime, on an Android device with Magisk installed, this newly deployed adbd binary allows adb root access.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project is divided clearly between the compilation of native components (adbd_helper) and the packaging/deployment mechanism (magisk_module).
- Modular Design: Each directory holds distinct responsibilities – native code vs. deployment scripts.
- Automation: Use of CI/CD workflows (.github/workflows) ensures automated building and testing.

- Use clear labels for each component, such as “Build Script (build.sh)”, “GitHub Workflow (ndk-build.yml)”, “Native Code (adbd_helper/jni)”, “Magisk Module Configuration (module.prop, updater-script)”, and “Deployed adbd binary”.
- From the build components (build.sh and GitHub workflows) to the compilation process (Android NDK building the adbd_helper code).
- From the NDK build stage to the Magisk Module packaging stage.
- From the packaged Magisk module to the target “Android Device” environment.
- External systems (like GitHub CI/CD and the Magisk framework on the device) to emphasize overall integration.

##### Final Advice
- Don’t hesitate to break down the Magisk module into subcomponents (e.g., updater-script, service.sh, sepolicy.rule) if needed to show how the integration with Android is achieved.
- Remember to focus on clarity, flow, and the separation of responsibilities across components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build Pipeline
    subgraph "Build Pipeline"
        BS["Build Script (build.sh)"]:::build
        GH["GitHub Workflow (ndk-build.yml)"]:::build
    end

    %% Native Code Compilation
    subgraph "Native Code Compilation"
        NC["Native Code (adbd_helper/jni)"]:::native
    end

    %% Module Packaging
    subgraph "Module Packaging"
        MM["Magisk Module Packaging"]:::module
    end

    %% Deployment Environment
    subgraph "Deployment"
        AD["Android Device (Magisk Framework)"]:::deployment
    end

    %% Connections
    BS -->|"triggers"| NC
    GH -->|"triggers"| NC
    NC -->|"integrates"| MM
    MM -->|"installs"| AD

    %% Click Events
    click BS "https://github.com/tiann/adb_root/blob/main/build.sh"
    click GH "https://github.com/tiann/adb_root/blob/main/.github/workflows/ndk-build.yml"
    click NC "https://github.com/tiann/adb_root/tree/main/adbd_helper/jni"
    click MM "https://github.com/tiann/adb_root/tree/main/magisk_module"

    %% Styles
    classDef build fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef native fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef module fill:#cce5ff,stroke:#003399,stroke-width:2px;
    classDef deployment fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
