# rehmatworks/gplaydl architecture

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

- Interactive diagram: https://gitdiagram.com/rehmatworks/gplaydl
- Repository: https://github.com/rehmatworks/gplaydl

## Overview

1. **Project shape**
   - This is a Python 3.9+ command-line package named `gplaydl`, not a web service.
   - The architecture is centered on a small set of modules under `gplaydl/`, with packaged static device profile files in `gplaydl/profiles/`.
   - `pyproject.toml`, `requirements.txt`, and `.github/workflows/publish.yml` support packaging and release automation rather than runtime behavior.

2. **Entry points**
   - `gplaydl/__main__.py` is the module entrypoint for `python -m gplaydl`.
   - `gplaydl/cli.py` is the main user-facing orchestration layer: it parses commands like `auth`, `download`, `info`, `search`, and `list-splits`, then dispatches into the lower-level modules.
   - `gplaydl/__init__.py` marks the package and likely exposes version/package metadata.

3. **Command-layer boundary**
   - The CLI is the top boundary between the user and the system.
   - It handles flags such as architecture selection (`arm64`, `armv7`), custom token dispenser URLs, output directories, and feature toggles like `--no-splits` / `--no-extras`.
   - From an architecture perspective, this layer does not own network logic or parsing; it coordinates the auth, metadata, and download subsystems.

4. **Anonymous authentication subsystem**
   - `gplaydl/auth.py` manages anonymous authentication against Aurora Store’s token dispenser.
   - It appears to be responsible for obtaining, caching, clearing, and reusing auth tokens, with separate cached tokens per architecture under the user config directory.
   - Token acquisition is improved by rotating through multiple device profiles, which increases compatibility with the dispenser and Google Play.

5. **Device profile subsystem**
   - `gplaydl/profiles.py` and the `gplaydl/profiles/*.properties` files form a data-driven device profile library.
   - These profiles are static inputs used during authentication; they are not application state.
   - The profile set is an important architectural boundary because it decouples auth behavior from code and allows token rotation without changing logic.

6. **Google Play metadata and protobuf decoding**
   - `gplaydl/api.py` is the main Google Play-facing API client layer.
   - `gplaydl/protobuf.py` indicates that responses are decoded in pure Python rather than via an external `gpapi` dependency.
   - This subsystem is responsible for fetching app details, search results, split metadata, version information, and download authorization details from Google Play’s protobuf-based endpoints.

7. **Download orchestration**
   - `gplaydl/download.py` is the file-transfer layer.
   - It coordinates the actual fetching of APKs from Google Play CDN URLs, likely based on metadata and authorization returned by the API layer.
   - The download pipeline includes base APKs, split APKs, OBB expansion files, and Play Asset Delivery packs, with support for streaming gzip decompression for asset packs.

8. **End-to-end data flow**
   - The typical flow is: CLI command → auth token lookup/acquisition → Google Play metadata lookup → purchase/authorization step → download URL resolution → parallel streaming download.
   - For `download`, the CLI first ensures a valid token exists, then resolves the package/version/architecture, then asks the API layer for the files to fetch, and finally hands those URLs to the downloader.
   - For `info`, `search`, and `list-splits`, the flow stops after metadata/query retrieval and presentation.

9. **External dependencies and service boundaries**
   - The repo depends on two key external services: Aurora Store’s public token dispenser and Google Play services/CDN.
   - Aurora provides anonymous auth tokens; Google Play provides app metadata, purchase authorization, and file delivery.
   - The architecture is deliberately split so that dispenser selection is configurable (`--dispenser`) while Google Play access remains the core downstream dependency.

10. **Output and storage model**
   - Auth tokens are persisted locally in the user config directory and reused automatically, which reduces network chatter and makes the CLI stateful across invocations.
   - Downloaded artifacts are written to a user-selected or default output directory using deterministic filenames that encode package name, version code, and split/asset type.
   - This naming convention is part of the download boundary and is important for downstream install workflows like `adb install-multiple`.

11. **Packaging and release**
   - The repository is packaged for installation via `pip` and also supports execution without installation.
   - The GitHub Actions workflow in `.github/workflows/publish.yml` suggests automated publishing to a package index when releases are made.
   - This release tooling is separate from runtime logic and does not affect the execution path of the CLI itself.

12. **Useful diagram framing**
   - A clear architecture diagram should show: user/terminal at the top, `cli.py` as the orchestrator, `auth.py` plus profile files as the token-acquisition path, `api.py`/`protobuf.py` as the Google Play metadata path, and `download.py` as the file-transfer path.
   - The two external boxes should be Aurora Store token dispenser and Google Play services/CDN, with local token cache as a persistent state node between runs.

Main entry points: [`gplaydl/cli.py`](https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/cli.py) (CLI), [`gplaydl/auth.py`](https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/auth.py) (Auth), [`gplaydl/api.py`](https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/api.py) (API client), [`gplaydl/download.py`](https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/download.py) (Downloader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_user(("User<br/>operator"))
  node_main["__main__<br/>entrypoint<br/>[__main__.py]"]
  node_cli["CLI<br/>orchestrator<br/>[cli.py]"]
  node_init["Package init<br/>package metadata<br/>[__init__.py]"]
  node_auth["Auth<br/>token manager<br/>[auth.py]"]
  node_profiles["Profiles<br/>[profiles.py]"]
  node_api["API client<br/>google play client<br/>[api.py]"]
  node_protobuf["Protobuf<br/>decoder<br/>[protobuf.py]"]
  node_download["Downloader<br/>transfer engine<br/>[download.py]"]
  node_terminal_out["Results<br/>cli output"]
end

subgraph group_storage["State"]
  node_cache[("Token cache<br/>local state")]
  node_profile_files["Profile files<br/>static data"]
end

subgraph group_external["External services"]
  node_dispenser(("Token dispenser<br/>aurora store service"))
  node_googleplay(("Google Play<br/>remote service"))
end

subgraph group_packaging["Packaging"]
  node_publish["Publish workflow<br/>release automation<br/>[publish.yml]"]
  node_build["Packaging<br/>python package<br/>[pyproject.toml]"]
end

node_user -->|"runs"| node_main
node_main -->|"dispatches"| node_cli
node_cli -->|"auth"| node_auth
node_cli -->|"query"| node_api
node_cli -->|"download"| node_download
node_cli -->|"prints"| node_terminal_out
node_auth -->|"rotate"| node_profiles
node_auth -->|"persist"| node_cache
node_auth -->|"request"| node_dispenser
node_profiles -->|"load"| node_profile_files
node_api -->|"decode"| node_protobuf
node_api -->|"fetch"| node_googleplay
node_download -->|"stream"| node_googleplay
node_download -->|"report"| node_terminal_out
node_cli -.->|"package"| node_build
node_build -.->|"release"| node_publish
node_init -.->|"exports"| node_cli

click node_main "https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/__main__.py"
click node_cli "https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/cli.py"
click node_init "https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/__init__.py"
click node_auth "https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/auth.py"
click node_profiles "https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/profiles.py"
click node_api "https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/api.py"
click node_protobuf "https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/protobuf.py"
click node_download "https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/download.py"
click node_profile_files "https://github.com/rehmatworks/gplaydl/tree/main/gplaydl/profiles"
click node_publish "https://github.com/rehmatworks/gplaydl/blob/main/.github/workflows/publish.yml"
click node_build "https://github.com/rehmatworks/gplaydl/blob/main/pyproject.toml"

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_user,node_main,node_cli,node_init,node_auth,node_profiles,node_api,node_protobuf,node_download,node_terminal_out toneBlue
class node_cache,node_profile_files toneAmber
class node_dispenser,node_googleplay toneMint
class node_publish,node_build toneRose
```

## Components

### Runtime

Command-line execution path and core subsystems.

- **User**: operator · Runs the CLI from a terminal.
- [__main__](https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/__main__.py): entrypoint · Module entrypoint for python -m gplaydl. · `gplaydl/__main__.py`
- [CLI](https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/cli.py): orchestrator · Parses commands and coordinates auth, metadata, and download flows. · `gplaydl/cli.py`
- [Package init](https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/__init__.py): package metadata · Package marker and exported metadata. · `gplaydl/__init__.py`
- [Auth](https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/auth.py): token manager · Obtains, caches, clears, and reuses anonymous auth tokens. · `gplaydl/auth.py`
- [Profiles](https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/profiles.py): device profiles · Static device profile library used during auth token rotation. · `gplaydl/profiles.py`
- [API client](https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/api.py): google play client · Fetches metadata, search results, split info, and download authorization. · `gplaydl/api.py`
- [Protobuf](https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/protobuf.py): decoder · Pure-Python decoding of Google Play protobuf responses. · `gplaydl/protobuf.py`
- [Downloader](https://github.com/rehmatworks/gplaydl/blob/main/gplaydl/download.py): transfer engine · Resolves and streams APK, split, OBB, and asset pack downloads. · `gplaydl/download.py`
- **Results**: cli output · Printed info, search results, and download status.

### State

Local persistent cache used across runs.

- **Token cache**: local state · Per-architecture cached auth tokens in the user config directory.
- [Profile files](https://github.com/rehmatworks/gplaydl/tree/main/gplaydl/profiles): static data · Packaged .properties device profiles bundled with the repo. · `gplaydl/profiles`

### External services

Remote boundaries the CLI talks to.

- **Token dispenser**: aurora store service · Public Aurora Store endpoint used to mint anonymous auth tokens.
- **Google Play**: remote service · Metadata, authorization, and CDN file delivery boundary.

### Packaging

Build and release support outside the runtime path.

- [Publish workflow](https://github.com/rehmatworks/gplaydl/blob/main/.github/workflows/publish.yml): release automation · GitHub Actions workflow for package publishing. · `.github/workflows/publish.yml`
- [Packaging](https://github.com/rehmatworks/gplaydl/blob/main/pyproject.toml): python package · Project metadata and dependencies for pip installation. · `pyproject.toml`

## Connections

- User → __main__: runs · Starts the package via python -m gplaydl.
- __main__ → CLI: dispatches · Entrypoint hands control to the command layer.
- CLI → Auth: auth · Ensures a valid anonymous token before protected actions.
- CLI → API client: query · Requests metadata, search, split, and version information.
- CLI → Downloader: download · Hands resolved file targets to the transfer layer.
- CLI → Results: prints · Outputs command results to the terminal.
- Auth → Profiles: rotate · Uses device profiles to improve token acquisition.
- Auth → Token cache: persist · Stores and reuses tokens between runs.
- Auth → Token dispenser: request · Contacts Aurora Store token dispenser.
- Profiles → Profile files: load · Reads bundled profile definitions.
- API client → Protobuf: decode · Parses protobuf-based Google Play responses.
- API client → Google Play: fetch · Calls Google Play metadata and authorization endpoints.
- Downloader → Google Play: stream · Downloads files from Google Play CDN URLs.
- Downloader → Results: report · Reports progress and completion status.
- CLI → Packaging: package · Runtime is packaged as a pip-installable project.
- Packaging → Publish workflow: release · GitHub Actions publishes packaged releases.
- Package init → CLI: exports · Package namespace supports the CLI entry path.
