How cloudflare/worker-speedtest-template works
What this project is (type + purpose)
This is a Cloudflare Workers edge-service (serverless “single binary” web service) that provides a minimal HTTP API for client-side speed testing. Clients measure:
• Download bandwidth/latency by requesting /down?bytes=N (worker returns N bytes)
• Upload bandwidth/latency by POSTing to /up (worker reads/discards body, responds when fully received)
The README explicitly frames it as a worker used by a browser client leveraging the Performance Timing API; so the system boundary includes (a) the browser measurement logic and (b) the edge worker endpoints. There’s no database and typically no persistent state.
What the file tree says about architecture
Top-level highlights:
• wrangler.toml: Cloudflare Workers deployment configuration (account, routes, compatibility date, etc.)
• index.js: likely the built/entry worker script used for deployment or distribution
• src/: the source modules composing the worker
• src/index.js: main entrypoint wiring the router to the fetch handler
• src/router.js: HTTP routing (maps paths/methods to handlers)
• src/down.js: implementation for download endpoint
• src/up.js: implementation for upload endpoint
• src/test.js: ad-hoc or unit test utilities (not a runtime component)
• package.json: build/test/dev tooling and dependencies (also “Dev/Build” lane)
Download
• Browser → (HTTPS GET) → Cloudflare Worker /down?bytes=N
• Worker router → down handler → returns N-byte binary response
• Browser measures: RTT, TTFB, download duration, throughput
Upload
• Browser → (HTTPS POST body) → Cloudflare Worker /up
• Worker router → up handler → reads/consumes full body → returns response
• Browser measures: upload duration, throughput
• Dev → Wrangler publish → Cloudflare Workers platform
• GitHub Actions → Semgrep scan → results (no runtime impact)
Architectural patterns/principles present
• Single edge service with route-based handlers (router pattern)
• Stateless request processing (no persistence)
• Streaming I/O for upload consumption (typical Workers pattern)
• Separation of concerns at module level:
• routing isolated in router.js
• endpoint logic isolated in down.js and up.js
• entrypoint glues them together in src/index.js
Shows: Browser ↔ Cloudflare Worker, plus CI/CD lanes.
Since there’s only one “container” (the Worker), go one level deeper and show components inside the Worker (router + handlers).
Use nested boundaries:
• Outer boundary: “Internet”
• Boundary: “Cloudflare Edge Network”
• Component: fetch handler (src/index.js)
• Component: Router (src/router.js)
• Component: Down handler (src/down.js)
• Component: Up handler (src/up.js)
Step 4 — Add deployment/config as a separate lane (not mixed into runtime)
• “Developer machine” → Wrangler → “Workers platform”
• “GitHub repo” → GitHub Actions (Semgrep)
• src/index.js → “fetch handler / entrypoint”
• src/router.js → “route matcher + dispatch”
• src/down.js → “GET /down implementation (size=bytes)”
• src/up.js → “POST /up implementation (consume body)”
Optionally:
• index.js → “bundled/compiled entry (distribution)”
• wrangler.toml → “deployment config”
• .github/workflows/semgrep.yml → “static analysis workflow”
What *not* to include (avoid inaccuracies)
• Databases, KV, Durable Objects, R2, Queues (not present in tree/README)
• An “API Gateway” separate from Workers (Workers *is* the edge ingress here)