How byjoey/cfnew works
1. This repository is a Cloudflare edge application, not a traditional server app.
Its core runtime is a Cloudflare Worker/Pages deployment configured by wrangler.toml, with the worker acting as both a control plane and a traffic relay.
2. The project has two equivalent source variants: 明文源吗 and the obfuscated 少年你相信光吗.
The README says they implement the same logic, so the architecture is the same regardless of which file is deployed.
3. The main external entrypoint is a UUID-based or custom-path HTTP surface.
That single edge endpoint serves several roles: a graphical admin UI, subscription generation, client auto-detection, and REST API management.
4. Configuration is split between immutable deployment settings and mutable runtime state.
Immutable defaults come from environment variables in Worker/Pages, while mutable settings are stored in Cloudflare KV bound as C.
The README emphasizes that KV changes take effect immediately without redeploying.
5. The control plane centers on the browser UI.
An operator opens the configured path, edits protocol and routing settings, toggles features like ECH/ALPN/proxy selection, and saves them back to KV.
Local browser state is also used for UI preferences such as language and visual effects.
6. There is a small management API layered onto the same path namespace.
Under /api/preferred-ips, the worker accepts GET/POST/DELETE to query, add, or clear preferred IPs.
This API is gated by an explicit ae flag and is meant for dynamic IP list management without code changes.
7. The data plane is the tunnel/proxy path.
The worker accepts VLESS, Trojan, and xhttp connections, then forwards traffic through Cloudflare edge logic toward selected ProxyIP targets or an optional SOCKS5 fallback.
Path parameters can override connection-level routing such as p, wk, rm, and s, with p and wk treated as mutually exclusive.
8. Subscription generation is a major subsystem.
The worker directly produces Clash, Stash, Sing-box, Surge, Loon, Quantumult X, V2Ray, Shadowrocket, Nekoray, and V2RayNG outputs.
According to the README, it no longer depends on an external sub-converter; rule sets are assembled inside the Worker, with remote rule sources used only where those client formats require them.
9. Preferred IP selection is another distinct subsystem.
It can use manually configured endpoints, default GitHub-derived lists, or custom source URLs, then filter by region, latency, and top-N selection.
This logic feeds both the proxy/tunnel path and the generated subscription nodes.
10. ECH support adds a runtime dependency on external DNS-over-HTTPS endpoints.
On refresh, the worker fetches ECH configuration from DoH providers, preferring Google DNS and falling back to Cloudflare DNS, then injects the resulting config into generated TLS-capable clients.
11. The repository includes CI/CD support through GitHub Actions.
.github/workflows/test.yml suggests validation/testing, and .github/workflows/obfuscate.yml supports producing the obfuscated variant.
So the repo’s build pipeline is oriented around packaging and publishing edge code, not compiling a multi-service backend.
12. The important architectural boundary is Cloudflare itself.
All request handling, configuration storage, and most caching happen at the edge; there is no separate database, app server, or message queue in the repo.
External dependencies are limited to KV storage, SOCKS5/proxy endpoints, DoH services, and rule/subscription source URLs.
13. For an architecture diagram, the key flow is: client browser or VPN client → Cloudflare Worker endpoint → KV/env/config resolution → either UI/subscription response or tunneling/proxy forwarding.
A separate side flow is GitHub Actions producing or validating the obfuscated/plaintext deployable code.
Main entry points: 明文源吗 Plain source · wrangler.toml Wrangler · 少年你相信光吗 Obfuscated source · test.yml GitHub Actions
Components 17
Edge runtime
Cloudflare Worker/Pages deployment and request handling
- Wrangler · Cloudflare edge deployment settings and bindings
wrangler.toml - Plain source · Readable implementation of the edge app
明文源吗 - Obfuscated source · Equivalent obfuscated implementation used for publishing
少年你相信光吗
Control plane
Browser UI and runtime configuration management
- Admin UI · Edge-served configuration UI for operators
- Runtime KV · Cloudflare KV-backed settings that take effect immediately
- Env defaults · Immutable worker/Pages environment settings
- IP API · GET/POST/DELETE surface for preferred IP management
Data plane
Protocol handling, routing, and proxy forwarding
- Tunnel relay · Accepts client connections and forwards traffic at the edge
- Protocols · VLESS, Trojan, and xhttp handling
- Route rules · Path parameters and flags that steer connection behavior
- Preferred IPs · Manual, default, or custom IP sources with filtering and top-N selection
- SOCKS5 · Optional downstream proxy used when selected
- ECH fetcher · Refreshes ECH config from DoH providers for TLS-capable clients
- DoH providers · External DNS-over-HTTPS endpoints used for ECH retrieval
Subscriptions
Client profile generation and format-specific outputs
- Subscription engine · Builds subscriptions for multiple client formats inside the worker
CI/CD
Workflow automation for validation and obfuscation
- GitHub Actions · Workflow automation for validation and release packaging
.github/workflows/test.yml - Obfuscate · Produces the obfuscated deployable source variant
.github/workflows/obfuscate.yml
Connections 20
- Wrangler → Plain source: deploys · Worker runtime is configured to run the readable source
- Wrangler → Obfuscated source: deploys · Workflow can publish the obfuscated equivalent
- Wrangler → Env defaults: binds · Deployment environment supplies immutable defaults
- Plain source → Admin UI: serves · Same edge endpoint exposes the browser control surface
- Plain source → IP API: exposes · The worker mounts the preferred IP management API
- Plain source → Subscription engine: generates · Client subscriptions are produced directly in the worker
- Plain source → Tunnel relay: handles · Tunnel/proxy traffic is accepted on the same endpoint
- Plain source → ECH fetcher: refreshes · Runtime can fetch and inject ECH config
- Admin UI → Runtime KV: writes · Operator changes are persisted to KV
- IP API → Runtime KV: reads/writes · Preferred IP state is managed dynamically without redeploying
- Runtime KV → Preferred IPs: feeds · Mutable runtime settings drive IP selection
- Env defaults → Route rules: defaults · Immutable settings provide baseline routing behavior
- Tunnel relay → Protocols: terminates · VLESS, Trojan, and xhttp connections are parsed here
- Protocols → Route rules: applies · Connection overrides such as p, wk, rm, and s steer routing
- Route rules → Preferred IPs: selects · Chosen targets determine which edge IPs or proxies are used
- Preferred IPs → SOCKS5: falls back · Optional SOCKS5 proxy can be used as an alternate path
- Subscription engine → Preferred IPs: uses · Generated client nodes incorporate selected preferred IPs
- ECH fetcher → DoH providers: queries · ECH config is retrieved from external DoH services
- GitHub Actions → Plain source: validates · Testing workflow targets the worker codebase
- Obfuscate → Obfuscated source: builds · Obfuscation workflow produces the publishable obfuscated variant