# b3hnamr/autozcoder architecture

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

- Interactive diagram: https://gitdiagram.com/b3hnamr/autozcoder
- Repository: https://github.com/b3hnamr/autozcoder

## Overview

AutoZCoder is a self-hosted ZCode gateway with an optional account generator and Cloudflare mail worker. The main workflow is client request → compatible API endpoint → shared chat service → account selection and ZCode transport → response; operators also manage accounts and inspect usage through the dashboard. Account generation is a separate optional workflow, with CAPTCHA tooling and proxy support. The README and source index establish the product branches, but several routes and integrations were not excerpted, so uncertain connections are omitted.

Main entry points: [`generator/main.py`](https://github.com/b3hnamr/autozcoder/blob/master/generator/main.py) (Account generator), [`zcode_gateway/app.py`](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/app.py) (HTTP application), [`zcode_gateway/service.py`](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/service.py) (Chat service), [`zcode_gateway/pool.py`](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/pool.py) (Account pool)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Client APIs"]
  node_openai["OpenAI API<br/>[api_openai.py]"]
  node_anthropic["Anthropic API<br/>[api_anthropic.py]"]
end

subgraph group_routing["Request Routing"]
  node_service["Chat service<br/>[service.py]"]
  node_registry["Model registry<br/>[registry.py]"]
  node_upstream["ZCode transport<br/>[upstream.py]"]
end

subgraph group_accounts["Account Management"]
  node_pool["Account pool<br/>[pool.py]"]
  node_account_files[("Account files<br/>[accounts_dir.py]")]
  node_account_import["Account import<br/>[zcode_accounts.py]"]
end

subgraph group_ops["Operations"]
  node_dashboard["Web dashboard<br/>[api_dash.py]"]
  node_admin["Admin API<br/>[api_admin.py]"]
  node_app["HTTP application<br/>[app.py]"]
  node_config["Configuration<br/>[config.py]"]
end

subgraph group_generation["Account Generation"]
  node_generator_ui["Generator controls<br/>[generator.py]"]
  node_generator["Account generator<br/>[main.py]"]
  node_plan_check["Plan checker<br/>[plan_check.py]"]
  node_invite_claim["Invite claims<br/>[invite_claim.py]"]
  node_proxy_pool["Proxy pool<br/>[proxy_pool.py]"]
  node_captcha["CAPTCHA minting<br/>[captcha.ts]"]
  node_mail_worker["Cloudflare mail worker<br/>[index.js]"]
end

node_client(("API client"))
node_zcode(("ZCode API"))
node_operator(("Operator"))

node_client -->|"sends request"| node_openai
node_client -->|"sends request"| node_anthropic
node_openai -->|"handles request"| node_service
node_anthropic -->|"handles request"| node_service
node_service -->|"resolves model"| node_registry
node_service -->|"selects account"| node_pool
node_service -->|"sends completion"| node_upstream
node_upstream -->|"calls upstream"| node_zcode
node_pool -->|"loads accounts"| node_account_files
node_pool -->|"uses credentials"| node_account_import
node_operator -->|"manages pool"| node_dashboard
node_operator -.->|"administers gateway"| node_admin
node_app -->|"registers routes"| node_openai
node_app -->|"registers routes"| node_anthropic
node_app -->|"registers routes"| node_dashboard
node_app -->|"registers routes"| node_admin
node_app -->|"loads settings"| node_config
node_operator -->|"starts generation"| node_generator_ui
node_generator_ui -->|"drives generator"| node_generator
node_generator -->|"checks plans"| node_plan_check
node_generator -->|"claims invite"| node_invite_claim
node_generator -->|"uses proxies"| node_proxy_pool
node_generator -.->|"solves CAPTCHA"| node_captcha
node_generator -.->|"uses mail service"| node_mail_worker

click node_openai "https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/api_openai.py"
click node_anthropic "https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/api_anthropic.py"
click node_service "https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/service.py"
click node_registry "https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/registry.py"
click node_pool "https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/pool.py"
click node_upstream "https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/upstream.py"
click node_account_files "https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/accounts_dir.py"
click node_account_import "https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/zcode_accounts.py"
click node_dashboard "https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/api_dash.py"
click node_admin "https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/api_admin.py"
click node_app "https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/app.py"
click node_config "https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/config.py"
click node_generator_ui "https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/generator.py"
click node_generator "https://github.com/b3hnamr/autozcoder/blob/master/generator/main.py"
click node_plan_check "https://github.com/b3hnamr/autozcoder/blob/master/generator/plan_check.py"
click node_invite_claim "https://github.com/b3hnamr/autozcoder/blob/master/generator/invite_claim.py"
click node_proxy_pool "https://github.com/b3hnamr/autozcoder/blob/master/generator/proxy_pool.py"
click node_captcha "https://github.com/b3hnamr/autozcoder/blob/master/tools/captcha-mint/captcha.ts"
click node_mail_worker "https://github.com/b3hnamr/autozcoder/blob/master/mail-worker/src/index.js"

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_openai,node_anthropic,node_client toneBlue
class node_service,node_registry,node_upstream toneAmber
class node_pool,node_account_files,node_account_import,node_zcode toneMint
class node_dashboard,node_admin,node_app,node_config toneRose
class node_generator_ui,node_generator,node_plan_check,node_invite_claim,node_proxy_pool,node_captcha,node_mail_worker,node_operator toneIndigo
```

## Components

### Client APIs

- [OpenAI API](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/api_openai.py): `zcode_gateway/api_openai.py`
- [Anthropic API](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/api_anthropic.py): `zcode_gateway/api_anthropic.py`

### Request Routing

- [Chat service](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/service.py): `zcode_gateway/service.py`
- [Model registry](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/registry.py): `zcode_gateway/registry.py`
- [ZCode transport](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/upstream.py): `zcode_gateway/upstream.py`

### Account Management

- [Account pool](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/pool.py): `zcode_gateway/pool.py`
- [Account files](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/accounts_dir.py): `zcode_gateway/accounts_dir.py`
- [Account import](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/zcode_accounts.py): `zcode_gateway/zcode_accounts.py`

### Operations

- [Web dashboard](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/api_dash.py): `zcode_gateway/api_dash.py`
- [Admin API](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/api_admin.py): `zcode_gateway/api_admin.py`
- [HTTP application](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/app.py): `zcode_gateway/app.py`
- [Configuration](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/config.py): `zcode_gateway/config.py`

### Account Generation

- [Generator controls](https://github.com/b3hnamr/autozcoder/blob/master/zcode_gateway/generator.py): `zcode_gateway/generator.py`
- [Account generator](https://github.com/b3hnamr/autozcoder/blob/master/generator/main.py): `generator/main.py`
- [Plan checker](https://github.com/b3hnamr/autozcoder/blob/master/generator/plan_check.py): `generator/plan_check.py`
- [Invite claims](https://github.com/b3hnamr/autozcoder/blob/master/generator/invite_claim.py): `generator/invite_claim.py`
- [Proxy pool](https://github.com/b3hnamr/autozcoder/blob/master/generator/proxy_pool.py): `generator/proxy_pool.py`
- [CAPTCHA minting](https://github.com/b3hnamr/autozcoder/blob/master/tools/captcha-mint/captcha.ts): `tools/captcha-mint/captcha.ts`
- [Cloudflare mail worker](https://github.com/b3hnamr/autozcoder/blob/master/mail-worker/src/index.js): `mail-worker/src/index.js`

### Other components

- **API client**
- **ZCode API**
- **Operator**

## Connections

- API client → OpenAI API: sends request
- API client → Anthropic API: sends request
- OpenAI API → Chat service: handles request (evidence: `zcode_gateway/app.py`)
- Anthropic API → Chat service: handles request (evidence: `zcode_gateway/app.py`)
- Chat service → Model registry: resolves model (evidence: `zcode_gateway/service.py`)
- Chat service → Account pool: selects account (evidence: `zcode_gateway/service.py`)
- Chat service → ZCode transport: sends completion (evidence: `zcode_gateway/service.py`)
- ZCode transport → ZCode API: calls upstream
- Account pool → Account files: loads accounts (evidence: `zcode_gateway/pool.py`)
- Account pool → Account import: uses credentials (evidence: `zcode_gateway/pool.py`)
- Operator → Web dashboard: manages pool
- Operator → Admin API: administers gateway
- HTTP application → OpenAI API: registers routes (evidence: `zcode_gateway/app.py`)
- HTTP application → Anthropic API: registers routes (evidence: `zcode_gateway/app.py`)
- HTTP application → Web dashboard: registers routes (evidence: `zcode_gateway/app.py`)
- HTTP application → Admin API: registers routes (evidence: `zcode_gateway/app.py`)
- HTTP application → Configuration: loads settings (evidence: `zcode_gateway/app.py`)
- Operator → Generator controls: starts generation
- Generator controls → Account generator: drives generator
- Account generator → Plan checker: checks plans (evidence: `generator/main.py`)
- Account generator → Invite claims: claims invite (evidence: `generator/main.py`)
- Account generator → Proxy pool: uses proxies (evidence: `generator/main.py`)
- Account generator → CAPTCHA minting: solves CAPTCHA
- Account generator → Cloudflare mail worker: uses mail service
