# iamr0s/dhizuku architecture

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

- Interactive diagram: https://gitdiagram.com/iamr0s/dhizuku
- Repository: https://github.com/iamr0s/dhizuku

## Overview

##### Main Components
- App Module (UI & Logic): This contains the Android application itself. Break it down into:
– UI Layer: Activities, pages, and themes (packages like ui.activity, ui.page, ui/theme).
– Data Layer: Data models (both “common” and “settings”), Room database integration (evident from the “room” subdirectories, dao, entity, repository implementations) and util classes.
– Service/Server Layer: Components that handle background tasks or system events (e.g., BootCompleteReceiver, DhizukuDAReceiver, MyDhizukuService, RunningService).
– Dependency Injection (DI): Modules for initializing app-wide dependencies (look at di/init, di/preferences_module, etc.).
- Hidden API Module: A separate module that mimics Android’s internal (hidden) APIs. It contains lower-level classes (ActivityThread, ContextImpl, IDevicePolicyManager, etc.) to facilitate privileged operations.
- Build & Configuration Components: Though not “functional” components, the existence of Gradle scripts, build configuration files, and keystore files imply structured build/deployment pipelines.

##### Relationships and Interactions
- The UI layer communicates with ViewModels (appearing in various ui/page sub-packages) using the MVVM pattern. ViewModels in turn interact with the data layer (repositories in data/settings/repo and DAO classes under data/settings/model/room/dao).
- The DI layer (under di/*) is responsible for instantiating and wiring together the UI controllers, ViewModels, data repositories, and other utilities to promote clean dependency management.
- The Service/Server layer (under server/*) listens to system events (via receivers like BootCompleteReceiver) and manages background operations, leveraging components in the hidden-api module where necessary.
- The Hidden API module is invoked when needing to access Android internals (e.g., DeviceOwner APIs) that are not public. It serves as the low-level abstraction layer for bypassing some of the typical restrictions.

##### Architectural Patterns & Principles
- MVVM Pattern: Seen via separation into UI pages, view states, view data, and view models.
- Repository & DAO Pattern: For managing data persistence (e.g., Room database related packages).
- Dependency Injection: The use of DI modules indicates reliance on DI frameworks (or a custom DI setup).
- Layered Architecture: Clear separation between UI, business logic, local data storage, and system-level calls (via the hidden API).

##### Relevant Technologies and Frameworks
- Android SDK: Given the AndroidManifest.xml and resource directories.
- Room Database: Based on the “room” folder structure for data storage.
- Gradle Kotlin DSL: As shown by build.gradle.kts and related Gradle configurations.
- Possibly a DI framework (either Dagger, Koin, or a custom implementation indicated by the “di” packages).
- Custom handling of hidden APIs: Provided by the “hidden-api” module.

##### Elements
– “App Module” with subdivisions: UI, Data Layer, Service Layer, DI Container.
– “Hidden API Module” for low-level Android system interactions.
- Connection with brief descriptions (e.g., “sends event”, “fetches data”, “initializes service”).

- Don’t overcomplicate by including every single utility class; focus on the architectural layers and their interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "App Module"
        subgraph "UI Layer"
            UIComponents["UI Components\n(Activities, Pages, Themes)"]:::ui
            ViewModelLayer["ViewModel Layer\n(MVVM Pattern)"]:::ui
        end
        subgraph "Data Layer"
            DataManagement["Data Management\n(Models, Repositories, DAOs & Room)"]:::data
        end
        subgraph "Service Layer"
            BackgroundServices["Background Services\n(Receivers & Services)"]:::service
        end
        subgraph "DI Container"
            DependencyInjection["Dependency Injection\n(DI Modules & Init)"]:::di
        end
    end

    HiddenAPI["Hidden API Module\n(Android Internals)"]:::hidden

    %% Relationships within App Module
    UIComponents -->|"triggers"| ViewModelLayer
    ViewModelLayer -->|"fetches data"| DataManagement
    DependencyInjection -->|"injects into"| UIComponents
    DependencyInjection -->|"injects into"| DataManagement
    DependencyInjection -->|"injects into"| BackgroundServices
    BackgroundServices -->|"updates"| UIComponents
    BackgroundServices -->|"persists data"| DataManagement
    BackgroundServices -->|"calls"| HiddenAPI

    %% Click Events
    click UIComponents "https://github.com/iamr0s/dhizuku/tree/main/app/src/main/java/com/rosan/dhizuku/ui"
    click DataManagement "https://github.com/iamr0s/dhizuku/tree/main/app/src/main/java/com/rosan/dhizuku/data"
    click BackgroundServices "https://github.com/iamr0s/dhizuku/tree/main/app/src/main/java/com/rosan/dhizuku/server"
    click DependencyInjection "https://github.com/iamr0s/dhizuku/tree/main/app/src/main/java/com/rosan/dhizuku/di"
    click HiddenAPI "https://github.com/iamr0s/dhizuku/tree/main/hidden-api"

    %% Styling classes
    classDef ui fill:#fdd,stroke:#333,stroke-width:2px;
    classDef data fill:#dfd,stroke:#333,stroke-width:2px;
    classDef service fill:#ffd,stroke:#333,stroke-width:2px;
    classDef di fill:#ddf,stroke:#333,stroke-width:2px;
    classDef hidden fill:#fdf,stroke:#333,stroke-width:2px;
```
