# uphyca/stetho-realm architecture

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

- Interactive diagram: https://gitdiagram.com/uphyca/stetho-realm
- Repository: https://github.com/uphyca/stetho-realm

## Overview

#### Purpose and Integration Entry Point
Stetho-Realm is an Android library that replaces Stetho’s SQLite-backed database inspection with Realm database inspection. Host apps initialize Realm, then install the library’s `InspectorModulesProvider` into Stetho’s WebKit inspector pipeline. Primary public integration surface: `stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmInspectorModulesProvider.java`.

#### Runtime and Dependencies
The library runs inside an Android application process and is packaged as an AAR. Its material external boundaries are:
- **Realm**: embedded object database; Realm files and schema/data are read by the adapter.
- **Facebook Stetho**: Chrome DevTools/WebKit inspection transport and database-domain APIs.
- **Android filesystem/context**: used to locate Realm database files, including an optional caller-supplied folder.
Build/publishing are Gradle-based: `build.gradle`, `stetho_realm/build.gradle`, and `deploy.gradle`.

#### Inspector Module Composition
`RealmInspectorModulesProvider` is the composition root. Its builder accepts inspection policies—base Stetho provider, Realm file folder/name pattern, encryption keys, metadata-table visibility, record limit, and sort direction—then appends the Realm inspector module to the selected base provider. This is the key boundary that lets applications preserve or customize other Stetho modules.
Paths:
- `stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmInspectorModulesProvider.java`
- `stetho_realm/src/main/AndroidManifest.xml`

#### Realm File Discovery
`RealmFilesProvider` abstracts discovery of inspectable Realm files. It mediates filesystem selection before database inspection, applying the configured folder and filename pattern rather than exposing arbitrary application files. The discovered file set feeds peer/database construction.
Paths:
- `stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmFilesProvider.java`
- `stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmInspectorModulesProvider.java`

#### Stetho Database-Domain Bridge
`RealmPeerManager` is the Stetho-facing control layer: it participates in DevTools peer/session lifecycle and exposes the Realm-backed database domain to connected inspector clients. It coordinates available databases and routes schema/data inspection requests into the Realm adapter instead of SQLite handling.
Paths:
- `stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmPeerManager.java`
- `stetho_realm/src/main/java/com/uphyca/stetho_realm/Database.java`

#### Realm-to-Inspector Data Adaptation
The top-level `Database` represents a Realm database in the inspector-facing model; the delegate implementation encapsulates Realm-specific schema/table/record access and conversion. This separation isolates Stetho protocol abstractions from Realm APIs and supports configured encryption, metadata inclusion, ordering, and limits. The README indicates inspection is read-oriented; update/delete are explicitly not implemented.
Paths:
- `stetho_realm/src/main/java/com/uphyca/stetho_realm/Database.java`
- `stetho_realm/src/main/java/com/uphyca/stetho_realm/delegate/Database.java`

#### Delivery Model
The repository includes a checked-in Maven-style artifact repository with released AARs and POMs, intended for consumption from GitHub-hosted `maven-repo`. Publication emits the Android library to that directory.
Paths:
- `maven-repo/com/uphyca/stetho_realm/maven-metadata.xml`
- `maven-repo/com/uphyca/stetho_realm/2.1.0/stetho_realm-2.1.0.aar`
- `deploy.gradle`

Main entry points: [`stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmInspectorModulesProvider.java`](https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmInspectorModulesProvider.java) (RealmInspectorModulesProvider), [`stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmPeerManager.java`](https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmPeerManager.java) (RealmPeerManager), [`stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmFilesProvider.java`](https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmFilesProvider.java) (RealmFilesProvider), [`stetho_realm/src/main/java/com/uphyca/stetho_realm/Database.java`](https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/Database.java) (Inspector Database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Host Runtime"]
  node_host_app["Android host app<br/>consumer"]
  node_realm[("Realm<br/>embedded database")]
  node_stetho["Facebook Stetho<br/>DevTools transport"]
  node_filesystem[("Android filesystem<br/>storage boundary")]
end

subgraph group_library["Stetho-Realm Library"]
  node_provider["RealmInspectorModulesProvider<br/>composition root"]
  node_manifest["Android manifest<br/>Android library metadata"]
  node_files_provider["RealmFilesProvider<br/>file discovery"]
  node_peer_manager["RealmPeerManager<br/>Stetho domain bridge"]
  node_inspector_database["Inspector Database<br/>protocol model<br/>[Database.java]"]
  node_realm_delegate["Realm database delegate<br/>Realm adapter<br/>[Database.java]"]
end

subgraph group_delivery["Build &amp; Delivery"]
  node_gradle_build["Gradle Android build<br/>build pipeline<br/>[build.gradle]"]
  node_publication["Publication script<br/>publishing pipeline<br/>[deploy.gradle]"]
  node_maven_repo[("Checked-in Maven repo<br/>artifact repository<br/>[maven-metadata.xml]")]
  node_released_aar["Released AAR 2.1.0<br/>Android artifact"]
end

node_host_app -->|"initializes"| node_realm
node_host_app -->|"installs"| node_provider
node_provider -->|"extends base modules"| node_stetho
node_provider -->|"configures discovery"| node_files_provider
node_provider -->|"adds Realm module"| node_peer_manager
node_manifest -.->|"packages"| node_provider
node_files_provider -->|"locates selected files"| node_filesystem
node_files_provider -->|"supplies databases"| node_peer_manager
node_stetho -->|"peer and request lifecycle"| node_peer_manager
node_peer_manager -->|"exposes"| node_inspector_database
node_inspector_database -->|"delegates reads"| node_realm_delegate
node_realm_delegate -->|"reads schema and records"| node_realm
node_gradle_build -->|"produces library for publishing"| node_publication
node_publication -->|"publishes"| node_maven_repo
node_maven_repo -->|"contains"| node_released_aar
node_released_aar -.->|"consumed as dependency"| node_host_app

click node_provider "https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmInspectorModulesProvider.java"
click node_manifest "https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/AndroidManifest.xml"
click node_files_provider "https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmFilesProvider.java"
click node_peer_manager "https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmPeerManager.java"
click node_inspector_database "https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/Database.java"
click node_realm_delegate "https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/delegate/Database.java"
click node_gradle_build "https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/build.gradle"
click node_publication "https://github.com/uphyca/stetho-realm/blob/master/deploy.gradle"
click node_maven_repo "https://github.com/uphyca/stetho-realm/blob/master/maven-repo/com/uphyca/stetho_realm/maven-metadata.xml"
click node_released_aar "https://github.com/uphyca/stetho-realm/blob/master/maven-repo/com/uphyca/stetho_realm/2.1.0/stetho_realm-2.1.0.aar"

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_host_app,node_realm,node_stetho,node_filesystem toneBlue
class node_provider,node_manifest,node_files_provider,node_peer_manager,node_inspector_database,node_realm_delegate toneAmber
class node_gradle_build,node_publication,node_maven_repo,node_released_aar toneMint
```

## Components

### Host Runtime

- **Android host app**: consumer · Initializes Realm and installs the provider.
- **Realm**: embedded database · Provides Realm files, schema, and records.
- **Facebook Stetho**: DevTools transport · Supplies WebKit inspector modules and database APIs.
- **Android filesystem**: storage boundary · Hosts inspectable Realm files.

### Stetho-Realm Library

- [RealmInspectorModulesProvider](https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmInspectorModulesProvider.java): composition root · Builds policies and appends Realm inspection to a base Stetho provider. · `stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmInspectorModulesProvider.java`
- [Android manifest](https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/AndroidManifest.xml): Android library metadata · `stetho_realm/src/main/AndroidManifest.xml`
- [RealmFilesProvider](https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmFilesProvider.java): file discovery · Selects Realm files by configured folder and name pattern. · `stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmFilesProvider.java`
- [RealmPeerManager](https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmPeerManager.java): Stetho domain bridge · Manages DevTools peers and routes database inspection requests. · `stetho_realm/src/main/java/com/uphyca/stetho_realm/RealmPeerManager.java`
- [Inspector Database](https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/Database.java): protocol model · Represents a Realm database in Stetho's inspector-facing model. · `stetho_realm/src/main/java/com/uphyca/stetho_realm/Database.java`
- [Realm database delegate](https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/src/main/java/com/uphyca/stetho_realm/delegate/Database.java): Realm adapter · Reads schema and records with encryption, metadata, sort, and limit policies. · `stetho_realm/src/main/java/com/uphyca/stetho_realm/delegate/Database.java`

### Build & Delivery

- [Gradle Android build](https://github.com/uphyca/stetho-realm/blob/master/stetho_realm/build.gradle): build pipeline · Packages the library as an AAR. · `stetho_realm/build.gradle`
- [Publication script](https://github.com/uphyca/stetho-realm/blob/master/deploy.gradle): publishing pipeline · Publishes the Android library into the checked-in Maven repository. · `deploy.gradle`
- [Checked-in Maven repo](https://github.com/uphyca/stetho-realm/blob/master/maven-repo/com/uphyca/stetho_realm/maven-metadata.xml): artifact repository · Contains released AARs, POMs, and Maven metadata. · `maven-repo/com/uphyca/stetho_realm/maven-metadata.xml`
- [Released AAR 2.1.0](https://github.com/uphyca/stetho-realm/blob/master/maven-repo/com/uphyca/stetho_realm/2.1.0/stetho_realm-2.1.0.aar): Android artifact · `maven-repo/com/uphyca/stetho_realm/2.1.0/stetho_realm-2.1.0.aar`

## Connections

- Android host app → Realm: initializes
- Android host app → RealmInspectorModulesProvider: installs
- RealmInspectorModulesProvider → Facebook Stetho: extends base modules
- RealmInspectorModulesProvider → RealmFilesProvider: configures discovery
- RealmInspectorModulesProvider → RealmPeerManager: adds Realm module
- Android manifest → RealmInspectorModulesProvider: packages
- RealmFilesProvider → Android filesystem: locates selected files
- RealmFilesProvider → RealmPeerManager: supplies databases
- Facebook Stetho → RealmPeerManager: peer and request lifecycle
- RealmPeerManager → Inspector Database: exposes
- Inspector Database → Realm database delegate: delegates reads
- Realm database delegate → Realm: reads schema and records
- Gradle Android build → Publication script: produces library for publishing
- Publication script → Checked-in Maven repo: publishes
- Checked-in Maven repo → Released AAR 2.1.0: contains
- Released AAR 2.1.0 → Android host app: consumed as dependency
