How sittiponghaus/speedtest works
Project type and purpose
• This is a small full-stack web application whose frontend is built with Astro (static-site generation + client hydration using React/TSX) and Tailwind CSS, and whose backend consists of two serverless endpoints (download & upload) implemented as Cloudflare Workers. Its purpose is to measure network speed from the user’s browser and display the results in real time.
File structure
• Top-level config files:
• astro.config.mjs (Astro build & deploy settings)
• tailwind.config.ts, global.css (styling pipeline)
• tsconfig.json, package.json, pnpm-lock.yaml (TypeScript & dependency management)
• Public assets:
• public/assets/fonts/inter.css (static fonts)
• Frontend source (ASTRO + React components):
• src/pages/index.astro (entry page, imports layout + components)
• src/components/layout.astro (page shell)
• src/components/speed/* (UI building blocks: card, indicator, text)
• src/container/speedtest.container.tsx (component orchestration & business logic)
• src/lib/*:
– math.ts (throughput calculations)
– utils.ts (general helpers)
– xhr.ts (XHR wrapper to call your API endpoints)
• Serverless API endpoints (Cloudflare Workers):
• src/pages/api/speed-test/download.ts
• src/pages/api/speed-test/upload.ts
Key insights from the README
• “Exploring Cloudflare Workers using Astro and React.”
• Live demo at https://speedtest.sittipong.com/
Main components to capture
a. Client Browser (User Agent)
b. Static Asset CDN (Astro-generated HTML/CSS/JS & public assets)
c. React + Astro Frontend:
• Page Shell (layout.astro)
• Speed UI Components (card, indicator, text)
• Container Layer (speedtest.container.tsx)
d. Utility Library (math.ts, utils.ts, xhr.ts)
e. Serverless Backend (Cloudflare Workers):
• Download endpoint
• Upload endpoint
f. External Services (e.g., Cloudflare Pages or other host/CDN)
Relationships & data flow
• 1 → 2: Browser requests static page & assets from CDN
• 2 → 3: Astro serves index.astro, hydrates React components
• 3 → 4: On speed-test start, container calls xhr.ts
• 4 → 5: xhr.ts issues HTTP requests to /api/speed-test/download and /upload
• 5 → 4: Workers respond with chunks or results
• 4 → 3: Container computes throughput via math.ts, updates UI components
• 3 → 1: Browser renders updated speed indicator
Architectural patterns & design principles
• Static-site generation + client hydration (Astro)
• Component decomposition (UI atoms & container pattern)
• Separation of concerns: UI vs. business logic vs. network I/O vs. calculation
• Serverless micro-endpoints for compute-on-demand
• Type safety (TypeScript)
Detail
• Every folder’s responsibility (components vs. container vs. lib)
• Both download & upload paths separately
• Where Tailwind and global.css fit (styling pipeline)
• Build step (Astro → static/bundled JS)