How mer30hamid/v2ray-sub2json-worker works
Project type and purpose
• This is a full-stack Cloudflare Worker application built with SvelteKit.
• Purpose: Provide a web UI for converting V2Ray subscription links or raw configs into a unified JSON format compatible with XRAY-based clients (V2RayN/V2RayNG).
File structure
• Top-level:
• .github/workflows – CI pipelines (build, deploy)
• wrangler.jsonc – Cloudflare Worker configuration
• tree.cjs, zip.cjs – custom build/zipping scripts
• project.inlang – i18n settings, messages/en.json & messages/fa-ir.json
• src/ – SvelteKit application
• src/lib – shared modules
• components (Button, Textarea, SettingsLimit)
• utils (conversion.ts, helpers.ts)
• src/routes – SvelteKit routing
• /convert (+page.svelte): frontend form UI
• /sub2json (+server.ts): API endpoint for doing the conversion
• static/ – static assets
• package*.json, tsconfig.json, vite.config.ts, svelte.config.js – build & type configurations
README
• Confirms this is a Cloudflare Worker that exposes:
• A single‐page form under /convert
• A POST/GET API under /sub2json to do the actual subscription fetch & JSON conversion
• Lists supported protocols, features (load-balancing, unblocking, raw config conversion)
• CI/CD via GitHub Actions to build & deploy to Workers
a. Main components
• Client Browser (User Interface)
• Cloudflare Worker (SvelteKit runtime)
– Frontend routes (/convert)
– Backend/API route (/sub2json)
• Library Modules
– conversion.ts, helpers.ts (business logic for parsing & transforming)
– UI Components
• External V2Ray subscription endpoints (URLs provided by user)
• GitHub Actions (CI/CD) → Wrangler → Cloudflare Workers
b. Relationships & data flows
1. User opens https://<worker>/convert → Worker serves SvelteKit page
2. User enters one or more subscription URLs or raw configs and clicks “Convert & Copy”
3. Frontend issues a fetch to /sub2json with user input
4. Worker’s /sub2json handler:
– Calls conversion utils to fetch each external URL (over HTTP)
– Parses and merges configs, applies load-balancing/unblocking logic
– Returns a JSON payload
5. Frontend receives JSON, displays results and copies to clipboard
6. (Optional) User opens raw JSON via “Open” button
c. Architectural patterns & design principles
• Single Worker hosting both UI (SSR) and API (Edge functions)
• Separation of concerns:
• UI components in src/lib/components
• Business logic in src/lib/utils
• Routing by SvelteKit conventions (routes directory)
• CI/CD pipeline automates build → zip → deploy
d. Key technologies & frameworks
• Cloudflare Workers (Edge runtime)
• SvelteKit (front & server‐side routing)
• TypeScript (type safety)
• GitHub Actions (build & deploy workflows)
• Wrangler (Cloudflare CLI)
Final recommendations
• Every distinct role: UI, API, business logic modules, external systems, and CI/CD
• SvelteKit’s frontend & API under a single Cloudflare Worker boundary
• Detail any important parameters (e.g., supported protocols, load balancing logic) next to the conversion module