# pjpv/zcode-switch architecture

> Architecture diagram of the GitHub repository pjpv/zcode-switch, 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/pjpv/zcode-switch
- Repository: https://github.com/pjpv/zcode-switch

## Overview

Z·SWITCH is a Tauri desktop account manager for switching ZCode login identities while preserving shared project and session data. The main workflow runs from the account UI through Tauri commands to local account storage and live-login switching; separate branches cover OAuth account addition, quota and activity claims, encrypted bundles, settings, and CLI automation. The README documents tray and startup behavior, but their detailed wiring was not sampled; subsystem paths below use supported enclosing source files where implementation details are unavailable.

Main entry points: [`src-tauri/src/lib.rs`](https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/lib.rs) (Tauri commands), [`src/captcha.js`](https://github.com/pjpv/zcode-switch/blob/main/src/captcha.js) (Captcha window), [`src/main.js`](https://github.com/pjpv/zcode-switch/blob/main/src/main.js) (Account window), [`src-tauri/src/oauth.rs`](https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/oauth.rs) (OAuth flows)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Desktop interface"]
  node_mainui["Account window<br/>[main.js]"]
  node_settingsui["Settings window<br/>[settings.js]"]
  node_captcha_ui["Captcha window<br/>[captcha.js]"]
  node_ui_helpers["UI dialogs<br/>[ui.js]"]
end

subgraph group_core["Application services"]
  node_commands["Tauri commands<br/>[lib.rs]"]
  node_cli["CLI automation<br/>[cli.rs]"]
  node_oauth["OAuth flows<br/>[oauth.rs]"]
  node_quota["Quota queries<br/>[quota.rs]"]
  node_claims["Activity claims<br/>[claim.rs]"]
  node_probe["Process detection<br/>[probe.rs]"]
  node_cipher["Bundle encryption<br/>[cipher.rs]"]
end

subgraph group_data["Local account data"]
  node_store[("Account store<br/>[store.rs]")]
  node_settings[("App settings<br/>[store.rs]")]
end

subgraph group_remote["Provider services"]
  node_provider["ZCode services"]
  node_captcha_service["Captcha provider"]
end

node_person(("User"))
node_zcode["ZCode application"]

node_person -->|"manages accounts"| node_mainui
node_mainui -->|"invokes commands"| node_commands
node_settingsui -->|"invokes commands"| node_commands
node_captcha_ui -->|"submits challenge"| node_commands
node_ui_helpers -->|"finalizes bundles"| node_commands
node_commands -->|"reads and writes"| node_store
node_commands -->|"loads settings"| node_settings
node_commands -->|"checks process"| node_probe
node_commands -->|"switches identity"| node_zcode
node_commands -->|"starts login"| node_oauth
node_oauth -->|"authenticates"| node_provider
node_commands -->|"queries balances"| node_quota
node_quota -->|"fetches quota"| node_provider
node_commands -->|"manages claims"| node_claims
node_claims -->|"checks activities"| node_provider
node_commands -->|"opens challenge"| node_captcha_ui
node_captcha_ui -.->|"loads verification"| node_captcha_service
node_commands -->|"encrypts bundles"| node_cipher
node_cli -->|"runs operations"| node_commands

click node_mainui "https://github.com/pjpv/zcode-switch/blob/main/src/main.js"
click node_settingsui "https://github.com/pjpv/zcode-switch/blob/main/src/settings.js"
click node_captcha_ui "https://github.com/pjpv/zcode-switch/blob/main/src/captcha.js"
click node_ui_helpers "https://github.com/pjpv/zcode-switch/blob/main/src/ui.js"
click node_commands "https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/lib.rs"
click node_cli "https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/cli.rs"
click node_oauth "https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/oauth.rs"
click node_quota "https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/quota.rs"
click node_claims "https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/claim.rs"
click node_probe "https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/probe.rs"
click node_cipher "https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/cipher.rs"
click node_store "https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/store.rs"
click node_settings "https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/store.rs"

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_mainui,node_settingsui,node_captcha_ui,node_ui_helpers,node_person toneBlue
class node_commands,node_cli,node_oauth,node_quota,node_claims,node_probe,node_cipher toneAmber
class node_store,node_settings toneMint
class node_provider,node_captcha_service toneRose
class node_zcode toneIndigo
```

## Components

### Desktop interface

- [Account window](https://github.com/pjpv/zcode-switch/blob/main/src/main.js): `src/main.js`
- [Settings window](https://github.com/pjpv/zcode-switch/blob/main/src/settings.js): `src/settings.js`
- [Captcha window](https://github.com/pjpv/zcode-switch/blob/main/src/captcha.js): `src/captcha.js`
- [UI dialogs](https://github.com/pjpv/zcode-switch/blob/main/src/ui.js): `src/ui.js`

### Application services

- [Tauri commands](https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/lib.rs): `src-tauri/src/lib.rs`
- [CLI automation](https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/cli.rs): `src-tauri/src/cli.rs`
- [OAuth flows](https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/oauth.rs): `src-tauri/src/oauth.rs`
- [Quota queries](https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/quota.rs): `src-tauri/src/quota.rs`
- [Activity claims](https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/claim.rs): `src-tauri/src/claim.rs`
- [Process detection](https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/probe.rs): `src-tauri/src/probe.rs`
- [Bundle encryption](https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/cipher.rs): `src-tauri/src/cipher.rs`

### Local account data

- [Account store](https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/store.rs): `src-tauri/src/store.rs`
- [App settings](https://github.com/pjpv/zcode-switch/blob/main/src-tauri/src/store.rs): `src-tauri/src/store.rs`

### Provider services

- **ZCode services**
- **Captcha provider**

### Other components

- **User**
- **ZCode application**

## Connections

- User → Account window: manages accounts
- Account window → Tauri commands: invokes commands
- Settings window → Tauri commands: invokes commands
- Captcha window → Tauri commands: submits challenge
- UI dialogs → Tauri commands: finalizes bundles
- Tauri commands → Account store: reads and writes
- Tauri commands → App settings: loads settings
- Tauri commands → Process detection: checks process
- Tauri commands → ZCode application: switches identity
- Tauri commands → OAuth flows: starts login
- OAuth flows → ZCode services: authenticates
- Tauri commands → Quota queries: queries balances
- Quota queries → ZCode services: fetches quota
- Tauri commands → Activity claims: manages claims
- Activity claims → ZCode services: checks activities
- Tauri commands → Captcha window: opens challenge
- Captcha window → Captcha provider: loads verification
- Tauri commands → Bundle encryption: encrypts bundles
- CLI automation → Tauri commands: runs operations
