# tytydraco/ladb architecture

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

- Interactive diagram: https://gitdiagram.com/tytydraco/ladb
- Repository: https://github.com/tytydraco/ladb

## Overview

##### Project type and purpose
- This is a single-module Android application (“app” folder) written in Kotlin, implementing MVVM and packing a full ADB server via JNI for on-device Local ADB over wireless debugging.
- Purpose: let users run ADB shell commands locally (without USB) by leveraging Android’s Wireless ADB Debugging feature.

##### File structure
- Top-level files: build scripts (build.gradle, settings.gradle), gradle wrapper.
- app/src/main/java/com/draco/ladb:
- views: Activities (Main, Bookmarks, Help)
- fragments: HelpPreferenceFragment
- recyclers: adapter for bookmark list
- viewmodels: MainActivityViewModel, BookmarksActivityViewModel (MVVM)
- services: QSTile.kt (Android Quick Settings TileService)
- utils: ADB.kt (wrapper around native ADB operations)
- app/src/main/jniLibs: prebuilt ADB server binaries for arm64, armeabi-v7a, x86, x86_64.
- app/src/main/res: layouts, menus, drawables, XML configs, themes.

##### Key insights from README
- Bundles ADB server inside app libraries.
- Communicates locally via loopback socket using wireless debugging pairing.
- No external backend or cloud dependencies.
- Incompatible with Shizuku; uses standard Android APIs only.

##### Main components
a. UI Layer
- MainActivity, BookmarksActivity, HelpActivity
- RecyclerView + BookmarksRecyclerAdapter
b. ViewModel Layer (MVVM)
- MainActivityViewModel, BookmarksActivityViewModel
c. Service Layer
- QSTile (Android TileService for quick access)
d. Native ADB Server
- JNI libraries (arm64-v8a, armeabi-v7a, x86, x86_64)
e. Utility Layer
- ADB.kt: launches ADB server process, issues shell commands
f. Android OS / Network
- Wireless Debugging subsystem (pairing dialog, loopback TCP/IP)
g. Data stores (optional)
- SharedPreferences or Room (not explicit here, but bookmarks likely in SharedPreferences via ViewModel).

##### Relationships and data flows
- User taps UI → Activity
- Activity binds to ViewModel → invokes methods
- ViewModel calls ADB.kt → starts ADB server process via JNI libs
- ADB server listens on local TCP port → communicates via Android’s network stack
- Responses flow back through ADB.kt → ViewModel → UI updates
- QSTile service can launch pairing/activity flows
- Bookmarks stored/retrieved via ViewModel → persistent storage (SharedPreferences)

##### Architectural patterns / design principles
- MVVM: activities/fragments observe ViewModels
- Separation of concerns: UI vs business logic vs native code
- JNI boundary: native ADB server binary invoked from Kotlin
- Android Jetpack components: ViewModel, Lifecycle

##### Summary
- MVVM separation and JNI boundary.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% App Module
    subgraph "Android App Module"
        direction TB
        subgraph "UI Layer"
            direction TB
            MA["MainActivity"]:::managed
            BA["BookmarksActivity"]:::managed
            HA["HelpActivity"]:::managed
            Adapter["BookmarksRecyclerAdapter"]:::managed
            HelpFrag["HelpPreferenceFragment"]:::managed
        end
        subgraph "ViewModel Layer"
            direction TB
            MAVM["MainActivityViewModel"]:::managed
            BAVM["BookmarksActivityViewModel"]:::managed
        end
        QSTile["QSTile Service"]:::managed
        ADButil["ADB Utility (ADB.kt)"]:::managed
    end

    NativeLibs["JNI Native ADB Binaries"]:::native
    OS["Wireless Debugging (Network Stack)"]:::os
    Storage["SharedPreferences"]:::storage

    %% Connections
    MA -->|"binds to"| MAVM
    BA -->|"binds to"| BAVM
    HelpFrag -->|"embedded in"| HA
    BA -->|"uses"| Adapter

    MAVM -->|"invokes"| ADButil
    BAVM -->|"invokes"| ADButil
    ADButil -->|"launches via JNI"| NativeLibs
    NativeLibs -->|"listens on TCP loopback"| OS
    OS -->|"returns responses"| NativeLibs
    NativeLibs -->|"output"| ADButil
    ADButil -->|"results"| MAVM
    MAVM -->|"updates UI"| MA
    BAVM -->|"updates UI"| BA

    BAVM -->|"stores/retrieves"| Storage

    QSTile -->|"launches pairing UI"| MA

    %% Click Events
    click MA "https://github.com/tytydraco/ladb/blob/main/app/src/main/java/com/draco/ladb/views/MainActivity.kt"
    click BA "https://github.com/tytydraco/ladb/blob/main/app/src/main/java/com/draco/ladb/views/BookmarksActivity.kt"
    click HA "https://github.com/tytydraco/ladb/blob/main/app/src/main/java/com/draco/ladb/views/HelpActivity.kt"
    click Adapter "https://github.com/tytydraco/ladb/blob/main/app/src/main/java/com/draco/ladb/recyclers/BookmarksRecyclerAdapter.kt"
    click HelpFrag "https://github.com/tytydraco/ladb/blob/main/app/src/main/java/com/draco/ladb/fragments/HelpPreferenceFragment.kt"
    click MAVM "https://github.com/tytydraco/ladb/blob/main/app/src/main/java/com/draco/ladb/viewmodels/MainActivityViewModel.kt"
    click BAVM "https://github.com/tytydraco/ladb/blob/main/app/src/main/java/com/draco/ladb/viewmodels/BookmarksActivityViewModel.kt"
    click QSTile "https://github.com/tytydraco/ladb/blob/main/app/src/main/java/com/draco/ladb/services/QSTile.kt"
    click ADButil "https://github.com/tytydraco/ladb/blob/main/app/src/main/java/com/draco/ladb/utils/ADB.kt"
    click NativeLibs "https://github.com/tytydraco/ladb/tree/main/app/src/main/jniLibs/arm64-v8a/"
    click NativeLibs "https://github.com/tytydraco/ladb/tree/main/app/src/main/jniLibs/armeabi-v7a/"
    click NativeLibs "https://github.com/tytydraco/ladb/tree/main/app/src/main/jniLibs/x86/"
    click NativeLibs "https://github.com/tytydraco/ladb/tree/main/app/src/main/jniLibs/x86_64/"

    %% Styles
    classDef managed fill:#e0f7fa,stroke:#0277bd,color:#000
    classDef native fill:#ffe0b2,stroke:#e65100,color:#000
    classDef os fill:#f1f8e9,stroke:#33691e,color:#000
    classDef storage fill:#fff3e0,stroke:#f57c00,color:#000
```
