# cmliu/cf-workers-bpsub architecture

> Architecture diagram of the GitHub repository cmliu/cf-workers-bpsub, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cmliu/cf-workers-bpsub
- Repository: https://github.com/cmliu/cf-workers-bpsub

## Overview

#### Purpose and deployment
This is a single Cloudflare Workers service that generates VLESS proxy subscriptions from upstream “BPSUB” node data. Its primary deployment artifact and request handler is `_worker.js`; `wrangler.toml` configures Worker deployment. The project runs on the Cloudflare Workers JavaScript runtime rather than a conventional server.

#### Request entry points
The Worker serves both a browser-oriented landing/configuration experience and API endpoints. Core documented routes are `/` for the UI, `/sub` for generated subscriptions, and `/uuid.json` for raw node data. Route dispatch, query parsing, response construction, and environment-variable access are centralized in `_worker.js`.

Paths: `_worker.js`, `wrangler.toml`

#### Subscription generation pipeline
A `/sub` request combines configured or query-supplied preferred IPs, proxy settings, SOCKS5 options, and node metadata into VLESS links. The response is selected or transformed based on client User-Agent, enabling base64/V2Ray-style output and client-specific forms such as Clash or SingBox.

Paths: `_worker.js`

#### Node and preferred-IP inputs
The Worker fetches or assembles source node information, exposes inspectable node data at `/uuid.json`, and parses preferred-address lists supplied through `ips` or the `ADD` environment variable. Preferred inputs can be literal host/port entries with labels or remote API URLs, establishing an external-fetch boundary before generated links are emitted.

Paths: `_worker.js`, `snippet/ak.js`, `snippet/ca110us.js`

#### Runtime configuration boundary
Cloudflare Worker environment variables provide deployment-specific behavior without source changes: upstream host(s), subscription conversion backend/configuration, default proxy IP, preferred addresses, subscription name, and node remark suffix. Request query parameters can override relevant defaults for an individual subscription request.

Paths: `_worker.js`, `wrangler.toml`

#### External services and transport behavior
The Worker depends on Cloudflare’s edge/CDN runtime and makes outbound requests to configured node hosts, optional preferred-IP APIs, and an optional subscription-conversion service (`SUBAPI` with `SUBCONFIG`). Generated VLESS configurations support TLS and multiple transport variants; protocol-specific implementations or embedded source fragments are represented by the snippet files.

Paths: `_worker.js`, `snippet/gl.js`, `snippet/ca110us.js`, `snippet/t12.js`

#### Alternate packaged proxy host
A separate proxy-host Worker artifact exists under `proxy_host/`, including source and a deployable ZIP. This appears to be an auxiliary proxy-host deployment boundary, distinct from the subscription-generator Worker, likely intended to provide or package proxy-host functionality used by generated configurations.

Paths: `proxy_host/_worker.js`, `proxy_host/proxy_host.zip`

Main entry points: [`_worker.js`](https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js) (Subscription Worker), [`wrangler.toml`](https://github.com/cmliu/cf-workers-bpsub/blob/main/wrangler.toml) (Worker deployment config), [`snippet/gl.js`](https://github.com/cmliu/cf-workers-bpsub/blob/main/snippet/gl.js) (Transport fragments), [`snippet/ak.js`](https://github.com/cmliu/cf-workers-bpsub/blob/main/snippet/ak.js) (Preferred-IP fragments)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_subscription_worker["Subscription Worker"]
  node_wrangler["Worker deployment config<br/>Wrangler config<br/>[wrangler.toml]"]
  node_worker{{"Subscription Worker<br/>Cloudflare Worker<br/>[_worker.js]"}}
  node_landing["Landing UI<br/>route /<br/>[_worker.js]"]
  node_subscription_route["Subscription endpoint<br/>route /sub<br/>[_worker.js]"]
  node_raw_nodes["Raw node endpoint<br/>route /uuid.json<br/>[_worker.js]"]
  node_runtime_env["Runtime environment<br/>Worker bindings<br/>[_worker.js]"]
  node_query_overrides["Query overrides<br/>request parameters<br/>[_worker.js]"]
  node_node_assembly["Node assembly<br/>node source processing<br/>[_worker.js]"]
  node_preferred_ips["Preferred IP parser<br/>address source processing<br/>[_worker.js]"]
  node_vless_builder["VLESS link builder<br/>subscription generation<br/>[_worker.js]"]
  node_client_formatter["Client formatter<br/>response transformation<br/>[_worker.js]"]
end

subgraph group_inputs["Input Sources"]
  node_transport_snippets["Transport fragments<br/>protocol implementations<br/>[gl.js]"]
  node_preferred_ip_snippets["Preferred-IP fragments<br/>address data fragments<br/>[ak.js]"]
end

subgraph group_external["External Services"]
  node_node_hosts[("Configured node hosts<br/>upstream BPSUB")]
  node_preferred_ip_apis["Preferred-IP APIs<br/>remote address sources"]
  node_subapi["Subscription conversion service<br/>SUBAPI"]
  node_edge_runtime{{"Cloudflare edge runtime<br/>execution platform"}}
end

subgraph group_proxy_host["Proxy Host Package"]
  node_proxy_worker{{"Proxy-host Worker<br/>auxiliary Cloudflare Worker<br/>[_worker.js]"}}
  node_proxy_zip["Proxy-host ZIP<br/>deployable package<br/>[proxy_host.zip]"]
end

node_wrangler -->|"deploys and configures"| node_worker
node_edge_runtime -->|"executes"| node_worker
node_worker -->|"serves"| node_landing
node_worker -->|"dispatches"| node_subscription_route
node_worker -->|"dispatches"| node_raw_nodes
node_runtime_env -->|"supplies defaults"| node_worker
node_query_overrides -->|"overrides defaults"| node_subscription_route
node_subscription_route -->|"loads nodes"| node_node_assembly
node_raw_nodes -->|"returns nodes from"| node_node_assembly
node_node_hosts -->|"fetched from"| node_node_assembly
node_subscription_route -->|"resolves addresses"| node_preferred_ips
node_preferred_ip_apis -->|"fetched from"| node_preferred_ips
node_preferred_ip_snippets -->|"provides source data"| node_preferred_ips
node_node_assembly -->|"provides metadata"| node_vless_builder
node_preferred_ips -->|"provides addresses"| node_vless_builder
node_transport_snippets -->|"supports transports"| node_vless_builder
node_vless_builder -->|"produces links"| node_client_formatter
node_client_formatter -.->|"optionally converts through"| node_subapi
node_client_formatter -->|"returns formatted subscription"| node_subscription_route
node_proxy_worker -->|"packaged as"| node_proxy_zip

click node_wrangler "https://github.com/cmliu/cf-workers-bpsub/blob/main/wrangler.toml"
click node_worker "https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js"
click node_landing "https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js"
click node_subscription_route "https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js"
click node_raw_nodes "https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js"
click node_runtime_env "https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js"
click node_query_overrides "https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js"
click node_node_assembly "https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js"
click node_preferred_ips "https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js"
click node_vless_builder "https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js"
click node_client_formatter "https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js"
click node_transport_snippets "https://github.com/cmliu/cf-workers-bpsub/blob/main/snippet/gl.js"
click node_preferred_ip_snippets "https://github.com/cmliu/cf-workers-bpsub/blob/main/snippet/ak.js"
click node_proxy_worker "https://github.com/cmliu/cf-workers-bpsub/blob/main/proxy_host/_worker.js"
click node_proxy_zip "https://github.com/cmliu/cf-workers-bpsub/blob/main/proxy_host/proxy_host.zip"

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_wrangler,node_worker,node_landing,node_subscription_route,node_raw_nodes,node_runtime_env,node_query_overrides,node_node_assembly,node_preferred_ips,node_vless_builder,node_client_formatter toneBlue
class node_transport_snippets,node_preferred_ip_snippets toneAmber
class node_node_hosts,node_preferred_ip_apis,node_subapi,node_edge_runtime toneMint
class node_proxy_worker,node_proxy_zip toneRose
```

## Components

### Subscription Worker

Cloudflare Worker deployment handling UI and subscription requests.

- [Worker deployment config](https://github.com/cmliu/cf-workers-bpsub/blob/main/wrangler.toml): Wrangler config · Defines deployment-time Worker configuration. · `wrangler.toml`
- [Subscription Worker](https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js): Cloudflare Worker · Central request handler, routing, configuration, and response assembly. · `_worker.js`
- [Landing UI](https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js): route / · Browser-oriented configuration experience. · `_worker.js`
- [Subscription endpoint](https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js): route /sub · Builds client-targeted VLESS subscription output. · `_worker.js`
- [Raw node endpoint](https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js): route /uuid.json · Exposes inspectable source node data. · `_worker.js`
- [Runtime environment](https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js): Worker bindings · Provides upstreams, proxy defaults, conversion settings, and naming values. · `_worker.js`
- [Query overrides](https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js): request parameters · Overrides applicable deployment defaults per subscription request. · `_worker.js`
- [Node assembly](https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js): node source processing · Fetches or assembles upstream BPSUB node metadata. · `_worker.js`
- [Preferred IP parser](https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js): address source processing · Parses literal addresses and remote preferred-IP API sources. · `_worker.js`
- [VLESS link builder](https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js): subscription generation · Combines nodes, proxy options, SOCKS5 settings, and transport settings. · `_worker.js`
- [Client formatter](https://github.com/cmliu/cf-workers-bpsub/blob/main/_worker.js): response transformation · Selects base64, V2Ray, Clash, SingBox, or related output by User-Agent. · `_worker.js`

### Input Sources

- [Transport fragments](https://github.com/cmliu/cf-workers-bpsub/blob/main/snippet/gl.js): protocol implementations · Embedded TLS and transport-variant implementation fragments. · `snippet/gl.js`
- [Preferred-IP fragments](https://github.com/cmliu/cf-workers-bpsub/blob/main/snippet/ak.js): address data fragments · `snippet/ak.js`

### External Services

- **Configured node hosts**: upstream BPSUB
- **Preferred-IP APIs**: remote address sources
- **Subscription conversion service**: SUBAPI · Optional conversion backend configured with SUBCONFIG.
- **Cloudflare edge runtime**: execution platform

### Proxy Host Package

Separate auxiliary Worker deployment artifact.

- [Proxy-host Worker](https://github.com/cmliu/cf-workers-bpsub/blob/main/proxy_host/_worker.js): auxiliary Cloudflare Worker · Separate proxy-host deployment source. · `proxy_host/_worker.js`
- [Proxy-host ZIP](https://github.com/cmliu/cf-workers-bpsub/blob/main/proxy_host/proxy_host.zip): deployable package · `proxy_host/proxy_host.zip`

## Connections

- Worker deployment config → Subscription Worker: deploys and configures
- Cloudflare edge runtime → Subscription Worker: executes
- Subscription Worker → Landing UI: serves
- Subscription Worker → Subscription endpoint: dispatches
- Subscription Worker → Raw node endpoint: dispatches
- Runtime environment → Subscription Worker: supplies defaults
- Query overrides → Subscription endpoint: overrides defaults
- Subscription endpoint → Node assembly: loads nodes
- Raw node endpoint → Node assembly: returns nodes from
- Configured node hosts → Node assembly: fetched from
- Subscription endpoint → Preferred IP parser: resolves addresses
- Preferred-IP APIs → Preferred IP parser: fetched from
- Preferred-IP fragments → Preferred IP parser: provides source data
- Node assembly → VLESS link builder: provides metadata
- Preferred IP parser → VLESS link builder: provides addresses
- Transport fragments → VLESS link builder: supports transports
- VLESS link builder → Client formatter: produces links
- Client formatter → Subscription conversion service: optionally converts through
- Client formatter → Subscription endpoint: returns formatted subscription
- Proxy-host Worker → Proxy-host ZIP: packaged as
