# wsa-installer/twrp-for-wsa architecture

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

- Interactive diagram: https://gitdiagram.com/wsa-installer/twrp-for-wsa
- Repository: https://github.com/wsa-installer/twrp-for-wsa

## Overview

TWRP for WSA injects recovery files into a WSA initrd, then uses a boot-time dispatcher and a persistent flag to choose between recovery and normal Android. The principal workflow is documented in the README; the sampled Python excerpts show initrd management, WSA detection, ADB, and GUI components, but omit much of the CLI wiring. The boot branch is directly supported by init.c. The graph therefore leaves uncertain Python call links out.

Main entry points: [`src/twrp.py`](https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py) (InitrdManager), [`init.c`](https://github.com/wsa-installer/twrp-for-wsa/blob/main/init.c) (Boot dispatcher), [`info.json`](https://github.com/wsa-installer/twrp-for-wsa/blob/main/info.json) (info.json flags)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_patching["Initrd Patching"]
  node_initrd["InitrdManager<br/>[twrp.py]"]
  node_cpio["CPIO operations<br/>[twrp.py]"]
  node_rollback["Original initrd backup<br/>[twrp.py]"]
end

subgraph group_boot["Boot Selection"]
  node_dispatcher["Boot dispatcher<br/>[init.c]"]
  node_metadata["info.json flags<br/>[info.json]"]
end

subgraph group_management["WSA Management"]
  node_cli["CLI application<br/>[twrp.py]"]
  node_detector["WSA detection<br/>[twrp.py]"]
  node_gui["Recovery GUI<br/>[twrp.py]"]
end

subgraph group_access["Recovery Access"]
  node_twrp["TWRP recovery"]
  node_adbmanager["ADBManager<br/>[twrp.py]"]
end

node_operator(("Operator"))
node_wsa[("WSA installation")]
node_archive["TWRP archive"]
node_kernel["WSA kernel"]
node_android["Android init"]
node_adbclient(("ADB client"))
node_adbdevice["ADB recovery device"]

node_operator -->|"runs commands"| node_cli
node_cli -->|"checks WSA"| node_detector
node_cli -->|"requests injection"| node_initrd
node_archive -->|"provides patch files"| node_initrd
node_initrd -->|"patches archive"| node_cpio
node_cpio -->|"rewrites initrd"| node_wsa
node_initrd -->|"preserves original"| node_rollback
node_cli -->|"sets boot flag"| node_initrd
node_initrd -->|"updates flag"| node_metadata
node_kernel -->|"starts init"| node_dispatcher
node_dispatcher -->|"reads flag"| node_metadata
node_dispatcher -->|"executes recovery"| node_twrp
node_dispatcher -->|"executes normal init"| node_android
node_adbclient -->|"issues commands"| node_adbmanager
node_adbmanager -->|"runs ADB commands"| node_adbdevice
node_twrp -->|"exposes recovery"| node_adbdevice
node_cli -->|"launches interface"| node_gui

click node_cli "https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py"
click node_detector "https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py"
click node_initrd "https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py"
click node_cpio "https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py"
click node_dispatcher "https://github.com/wsa-installer/twrp-for-wsa/blob/main/init.c"
click node_metadata "https://github.com/wsa-installer/twrp-for-wsa/blob/main/info.json"
click node_adbmanager "https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py"
click node_gui "https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py"
click node_rollback "https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py"

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_initrd,node_cpio,node_rollback,node_adbclient toneBlue
class node_dispatcher,node_metadata,node_wsa toneAmber
class node_cli,node_detector,node_gui toneMint
class node_twrp,node_adbmanager toneRose
class node_operator,node_archive,node_kernel,node_android,node_adbdevice toneIndigo
```

## Components

### Initrd Patching

- [InitrdManager](https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py): `src/twrp.py`
- [CPIO operations](https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py): `src/twrp.py`
- [Original initrd backup](https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py): `src/twrp.py`

### Boot Selection

- [Boot dispatcher](https://github.com/wsa-installer/twrp-for-wsa/blob/main/init.c): `init.c`
- [info.json flags](https://github.com/wsa-installer/twrp-for-wsa/blob/main/info.json): `info.json`

### WSA Management

- [CLI application](https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py): `src/twrp.py`
- [WSA detection](https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py): `src/twrp.py`
- [Recovery GUI](https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py): `src/twrp.py`

### Recovery Access

- **TWRP recovery**
- [ADBManager](https://github.com/wsa-installer/twrp-for-wsa/blob/main/src/twrp.py): `src/twrp.py`

### Other components

- **Operator**
- **WSA installation**
- **TWRP archive**
- **WSA kernel**
- **Android init**
- **ADB client**
- **ADB recovery device**

## Connections

- Operator → CLI application: runs commands
- CLI application → WSA detection: checks WSA
- CLI application → InitrdManager: requests injection
- TWRP archive → InitrdManager: provides patch files
- InitrdManager → CPIO operations: patches archive
- CPIO operations → WSA installation: rewrites initrd
- InitrdManager → Original initrd backup: preserves original
- CLI application → InitrdManager: sets boot flag
- InitrdManager → info.json flags: updates flag
- WSA kernel → Boot dispatcher: starts init
- Boot dispatcher → info.json flags: reads flag
- Boot dispatcher → TWRP recovery: executes recovery
- Boot dispatcher → Android init: executes normal init
- ADB client → ADBManager: issues commands
- ADBManager → ADB recovery device: runs ADB commands
- TWRP recovery → ADB recovery device: exposes recovery
- CLI application → Recovery GUI: launches interface
