# revanced/revanced-patcher architecture

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

- Interactive diagram: https://gitdiagram.com/revanced/revanced-patcher
- Repository: https://github.com/revanced/revanced-patcher

## Overview

1. **Repository purpose and role**
   ReVanced Patcher is a Kotlin library, not an application. Its job is to provide a reusable patching engine for Android APKs, especially Android bytecode and resources. Other ReVanced projects consume it as a dependency, so this repo defines the core patching architecture rather than an end-user workflow.

2. **Top-level structure**
   The repo is centered around a single Kotlin Multiplatform module under `patcher/`, with shared logic in `commonMain` and platform-specific code in `jvmMain` and `androidMain`. The root Gradle build config and version catalog manage dependency resolution, publication, and test/build execution.

3. **Core patching API boundary**
   The main public surface lives in `app.revanced.patcher`. Key concepts are `Patch`, `Option`, `Patching`, `Matching`, and `Fingerprint`. This is the abstraction layer patch authors use to describe what should be modified and how to locate targets inside an app package.

4. **Patch execution contexts**
   The patching model is split by target type. `BytecodePatchContext` handles Dalvik/DEX bytecode mutations, while `ResourcePatchContext` covers Android resource changes. This separation is an important architectural boundary because bytecode and resource patching have different inputs, outputs, and mutation rules.

5. **Bytecode and Smali manipulation layer**
   The repo includes a large set of mutable Dexlib2-backed types under `com.android.tools.smali.dexlib2.mutable` and `...iface.value`. These classes form the low-level mutable model for classes, methods, fields, annotations, and encoded values. This is the layer that actually represents and edits Android bytecode structures before they are written back out.

6. **Matching and fingerprinting subsystem**
   `Fingerprint` and `Matching` provide the discovery mechanism used to identify methods/classes to patch. Instead of hard-coding offsets or names, patches can locate targets through structural patterns. That makes the patching engine resilient to app version changes and is a core architectural feature.

7. **Utility and navigation helpers**
   `MethodNavigator`, `ClassMerger`, `Document`, and the `extensions/` package support higher-level patch authoring and bytecode traversal. These helpers sit between the public patch API and the mutable Dex model, reducing the amount of low-level bytecode handling patch authors need to perform directly.

8. **Proxy and adapter layer**
   The `util/proxy` and `mutableTypes` packages are adaptation layers that map API-facing abstractions to the mutable Dexlib2 model. This suggests the architecture is designed to isolate consumers from implementation details and keep the public API stable even if underlying bytecode representations change.

9. **Common vs platform-specific implementations**
   The `commonMain` source set contains most of the library logic, while `jvmMain` and `androidMain` provide platform-specific replacements for types like `File`, `MutableMap`, and `Patch`. This is a classic multiplatform boundary: shared patching logic is reused everywhere, but filesystem/runtime details are adapted per target environment.

10. **Testing strategy**
   Tests are concentrated in `jvmTest`, which indicates the library’s behavior is validated on the JVM rather than on-device Android runtime. The tests cover matching, patch behavior, extension utilities, options, and smali helpers, so the repository’s confidence boundary is around patch computation and bytecode model operations.

11. **Documentation as part of the architecture**
   The `docs/` directory is substantial and split into setup, patcher intro, patch anatomy, matching, patch structure, and APIs. That suggests the repository is designed around a documented extension model, where the docs are effectively part of the developer-facing architecture for writing patches safely.

12. **Release and distribution pipeline**
   GitHub Actions workflows handle pull request validation, release publishing, and documentation updates. Since the library is meant to be consumed via Gradle coordinates, the CI/release pipeline is part of the delivery architecture: it builds the library, validates changes, and publishes versioned artifacts for downstream ReVanced projects.

Main entry points: [`patcher/build.gradle.kts`](https://github.com/revanced/revanced-patcher/blob/main/patcher/build.gradle.kts) (Patcher module), [`patcher/src/jvmTest/kotlin/app/revanced/patcher`](https://github.com/revanced/revanced-patcher/tree/main/patcher/src/jvmTest/kotlin/app/revanced/patcher) (JVM tests), [`patcher/src/commonMain/kotlin/app/revanced/patcher`](https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/patcher) (Patch API), [`.github/workflows`](https://github.com/revanced/revanced-patcher/blob/main/.github/workflows) (CI & release)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_root["Repository"]
  node_root_build["Gradle build<br/>build system<br/>[build.gradle.kts]"]
  node_settings["Settings"]
  node_patcher_module["Patcher module<br/>kmp library<br/>[build.gradle.kts]"]
end

subgraph group_common["Shared library"]
  node_public_api["Patch API<br/>public surface"]
  node_patch_contexts["Patch contexts<br/>execution model"]
  node_fingerprint_match{{"Fingerprinting<br/>discovery<br/>[Fingerprint.kt]"}}
  node_bytecode_utils["Bytecode helpers<br/>navigation helpers"]
  node_proxy_layer["Proxy layer<br/>adapter layer"]
  node_dex_mutable[("Mutable Dex model<br/>dexlib2 model")]
  node_dex_values[("Value model<br/>dexlib2 values")]
  node_smali_tools["Smali tools<br/>bytecode tooling"]
  node_common_helpers["Common helpers<br/>shared utilities"]
end

subgraph group_platform["Platform code"]
  node_jvm_impl["JVM impl<br/>platform runtime"]
  node_android_impl["Android impl<br/>platform runtime"]
end

subgraph group_quality["Validation and delivery"]
  node_jvm_tests["JVM tests<br/>test suite"]
  node_docs["Docs"]
  node_ci_release(("CI & release<br/>automation<br/>[workflows]"))
end

node_root_build -->|"configures"| node_patcher_module
node_settings -->|"includes"| node_patcher_module
node_patcher_module -->|"exposes"| node_public_api
node_patcher_module -->|"contains"| node_patch_contexts
node_patcher_module -->|"contains"| node_fingerprint_match
node_patcher_module -->|"contains"| node_bytecode_utils
node_patcher_module -->|"contains"| node_proxy_layer
node_patcher_module -->|"uses"| node_dex_mutable
node_patcher_module -->|"uses"| node_dex_values
node_patcher_module -->|"contains"| node_smali_tools
node_patcher_module -->|"contains"| node_common_helpers
node_jvm_impl -->|"implements"| node_patcher_module
node_android_impl -->|"implements"| node_patcher_module
node_jvm_tests -->|"verifies"| node_public_api
node_jvm_tests -->|"verifies"| node_fingerprint_match
node_jvm_tests -->|"verifies"| node_bytecode_utils
node_docs -->|"documents"| node_public_api
node_ci_release -->|"builds"| node_patcher_module
node_ci_release -->|"updates"| node_docs

click node_root_build "https://github.com/revanced/revanced-patcher/blob/main/build.gradle.kts"
click node_settings "https://github.com/revanced/revanced-patcher/blob/main/settings.gradle.kts"
click node_patcher_module "https://github.com/revanced/revanced-patcher/blob/main/patcher/build.gradle.kts"
click node_public_api "https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/patcher"
click node_patch_contexts "https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/patcher/patch"
click node_fingerprint_match "https://github.com/revanced/revanced-patcher/blob/main/patcher/src/commonMain/kotlin/app/revanced/patcher/Fingerprint.kt"
click node_bytecode_utils "https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/patcher/util"
click node_proxy_layer "https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/patcher/util/proxy"
click node_dex_mutable "https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/com/android/tools/smali/dexlib2/mutable"
click node_dex_values "https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/com/android/tools/smali/dexlib2/iface/value"
click node_smali_tools "https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/patcher/util/smali"
click node_common_helpers "https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced"
click node_jvm_impl "https://github.com/revanced/revanced-patcher/tree/main/patcher/src/jvmMain/kotlin/app/revanced"
click node_android_impl "https://github.com/revanced/revanced-patcher/tree/main/patcher/src/androidMain/kotlin/app/revanced"
click node_jvm_tests "https://github.com/revanced/revanced-patcher/tree/main/patcher/src/jvmTest/kotlin/app/revanced/patcher"
click node_docs "https://github.com/revanced/revanced-patcher/tree/main/docs"
click node_ci_release "https://github.com/revanced/revanced-patcher/blob/main/.github/workflows"

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_root_build,node_settings,node_patcher_module toneBlue
class node_public_api,node_patch_contexts,node_fingerprint_match,node_bytecode_utils,node_proxy_layer,node_dex_mutable,node_dex_values,node_smali_tools,node_common_helpers toneAmber
class node_jvm_impl,node_android_impl toneMint
class node_jvm_tests,node_docs,node_ci_release toneRose
```

## Components

### Repository

Build, docs, release, and module orchestration at the repository root.

- [Gradle build](https://github.com/revanced/revanced-patcher/blob/main/build.gradle.kts): build system · Root Gradle configuration and version catalog for dependency and publication management. · `build.gradle.kts`
- [Settings](https://github.com/revanced/revanced-patcher/blob/main/settings.gradle.kts): build settings · Repository-level Gradle settings and module wiring. · `settings.gradle.kts`
- [Patcher module](https://github.com/revanced/revanced-patcher/blob/main/patcher/build.gradle.kts): kmp library · Single Kotlin Multiplatform library module that exposes the patching engine. · `patcher/build.gradle.kts`

### Shared library

Kotlin Multiplatform code shared across runtimes.

- [Patch API](https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/patcher): public surface · Core patching abstractions: Patch, Option, Patching, Matching, and Fingerprint. · `patcher/src/commonMain/kotlin/app/revanced/patcher`
- [Patch contexts](https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/patcher/patch): execution model · Bytecode and resource patch contexts that separate mutation by target type. · `patcher/src/commonMain/kotlin/app/revanced/patcher/patch`
- [Fingerprinting](https://github.com/revanced/revanced-patcher/blob/main/patcher/src/commonMain/kotlin/app/revanced/patcher/Fingerprint.kt): discovery · Structural matching system used to locate app targets without hard-coded offsets. · `patcher/src/commonMain/kotlin/app/revanced/patcher/Fingerprint.kt`
- [Bytecode helpers](https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/patcher/util): navigation helpers · Method navigation, class merging, document handling, and instruction extensions for patch authors. · `patcher/src/commonMain/kotlin/app/revanced/patcher/util`
- [Proxy layer](https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/patcher/util/proxy): adapter layer · Adapts API-facing abstractions to mutable Dexlib2-backed types. · `patcher/src/commonMain/kotlin/app/revanced/patcher/util/proxy`
- [Mutable Dex model](https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/com/android/tools/smali/dexlib2/mutable): dexlib2 model · Mutable class, method, field, annotation, and encoded-value types for Android bytecode editing. · `patcher/src/commonMain/kotlin/app/revanced/com/android/tools/smali/dexlib2/mutable`
- [Value model](https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/com/android/tools/smali/dexlib2/iface/value): dexlib2 values · Mutable encoded-value interfaces and implementations used by the Dex mutation layer. · `patcher/src/commonMain/kotlin/app/revanced/com/android/tools/smali/dexlib2/iface/value`
- [Smali tools](https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced/patcher/util/smali): bytecode tooling · Smali-focused utilities and extensions for inspecting and transforming instructions. · `patcher/src/commonMain/kotlin/app/revanced/patcher/util/smali`
- [Common helpers](https://github.com/revanced/revanced-patcher/tree/main/patcher/src/commonMain/kotlin/app/revanced): shared utilities · Shared multiplatform wrappers such as File and MutableMap abstractions. · `patcher/src/commonMain/kotlin/app/revanced`

### Platform code

Runtime-specific implementations for JVM and Android.

- [JVM impl](https://github.com/revanced/revanced-patcher/tree/main/patcher/src/jvmMain/kotlin/app/revanced): platform runtime · JVM-specific replacements for File, MutableMap, and Patch behavior. · `patcher/src/jvmMain/kotlin/app/revanced`
- [Android impl](https://github.com/revanced/revanced-patcher/tree/main/patcher/src/androidMain/kotlin/app/revanced): platform runtime · Android-specific replacements for File, MutableMap, and Patch behavior. · `patcher/src/androidMain/kotlin/app/revanced`

### Validation and delivery

Tests, documentation, and CI/release workflows.

- [JVM tests](https://github.com/revanced/revanced-patcher/tree/main/patcher/src/jvmTest/kotlin/app/revanced/patcher): test suite · Behavioral tests for matching, patch execution, extensions, options, and smali helpers. · `patcher/src/jvmTest/kotlin/app/revanced/patcher`
- [Docs](https://github.com/revanced/revanced-patcher/tree/main/docs): developer docs · Guide and API documentation for patch authors and library users. · `docs`
- [CI & release](https://github.com/revanced/revanced-patcher/blob/main/.github/workflows): automation · GitHub Actions workflows for validation, release publishing, and documentation updates. · `.github/workflows`

## Connections

- Gradle build → Patcher module: configures · Root Gradle build configures the library module.
- Settings → Patcher module: includes · Settings wire the module into the build.
- Patcher module → Patch API: exposes · The module exports the public patching surface.
- Patcher module → Patch contexts: contains · The module defines execution contexts for patching.
- Patcher module → Fingerprinting: contains · The module provides structural target discovery.
- Patcher module → Bytecode helpers: contains · The module includes helper utilities for patch authors.
- Patcher module → Proxy layer: contains · The module adapts public abstractions to mutable internals.
- Patcher module → Mutable Dex model: uses · Bytecode patching operates on the mutable Dex model.
- Patcher module → Value model: uses · Mutable Dex structures depend on encoded-value definitions.
- Patcher module → Smali tools: contains · The module includes smali-oriented utilities.
- Patcher module → Common helpers: contains · Shared Kotlin helpers live in the common source set.
- JVM impl → Patcher module: implements · JVM-specific source set fulfills shared patcher contracts.
- Android impl → Patcher module: implements · Android-specific source set fulfills shared patcher contracts.
- JVM tests → Patch API: verifies · Tests cover the public patching API.
- JVM tests → Fingerprinting: verifies · Tests validate matching and fingerprint behavior.
- JVM tests → Bytecode helpers: verifies · Tests cover extension and smali helper behavior.
- Docs → Patch API: documents · Documentation explains the patching API and patch anatomy.
- CI & release → Patcher module: builds · Workflows validate and publish the library artifacts.
- CI & release → Docs: updates · A workflow keeps documentation in sync.
