Platform (swapps-worker)

The Platform worker (repository swapps-worker) is the serverless backend API for the Swapps platform. It runs on Cloudflare Workers with the Hono framework and serves the public website and the conversational lead funnel: it captures and classifies leads, syncs them to the CRM, drives AI-powered prototype generation, sends transactional email, exposes the blog/content API, and powers the in-page sales chat.

It is a single Worker (swapps-worker.swapps.workers.dev) that fronts a set of external services, persists everything in Cloudflare KV, and offloads long-running work to Durable Objects and a cron trigger.

Role in the platform

flowchart LR Website["Website / swapps-client
(browser)"] -->|HTTPS / JSON / SSE| Worker subgraph CF["Cloudflare"] Worker["swapps-worker
(Hono API)"] KV[("KV: CACHE")] PQ["PrototypeQueue
(Durable Object)"] CEQ["ConfirmationEmailQueue
(Durable Object)"] Cron["Cron trigger
(hourly)"] Worker --> KV Worker --> PQ Worker --> CEQ Cron --> PQ end Worker -->|leads / notes| Pipedrive["Pipedrive CRM"] Worker -->|email| Mailgun["Mailgun"] Worker -->|prototype gen| V0["V0 SDK"] Worker -->|notifications| ClickUp["ClickUp"] Worker -->|classification| LiteLLM["LiteLLM proxy"] Worker -->|chat agent| Agno["Agno agents"] Worker -->|blog content| WordPress["WordPress REST API"] Worker -->|performance| PageSpeed["Google PageSpeed"] Worker -->|bot check| reCAPTCHA["Google reCAPTCHA"]

Tech stack

Category Technology
Runtime Cloudflare Workers
Framework Hono ^4.6.0
Language TypeScript ~5.8.3
Storage Cloudflare KV (CACHE binding)
Background jobs Durable Objects (SQLite-backed) + cron trigger
Bundler esbuild ^0.25.9 (via scripts/build.js)
CLI / deploy Wrangler ^4.32.0
Testing Vitest ^3.2.4
Linting ESLint ^9.33.0
Prototype generation v0-sdk ^0.15.3
Email Mailgun API
CRM Pipedrive API
Notifications ClickUp API
Lead classification LiteLLM proxy (Gemini model)
Sales chat agent Agno agents (WebSocket streaming)

Key highlights

  • Clean Architecture with strict inward dependency rules (domain / application / infrastructure / presentation). See Architecture.
  • AI prototype generation via the V0 SDK, with live progress over Server-Sent Events and reliable background polling in a Durable Object. See Key flows.
  • LLM lead classification (lead / spam / vendor) on every submission, with toggleable filtering.
  • Conversational sales chat streamed from Agno over a WebSocket, re-streamed to the browser as SSE.
  • Dual-bucket rate limiting (per IP and per email) for prototype generation, stored in KV with monthly quotas.
  • CRM + email orchestration: leads sync to Pipedrive and route to service-specific email templates (diagnostic, strategic advice, dedicated team, technology strategy, process automation, prototype).
  • Content API that proxies and caches the WordPress REST API for the blog.
  • Safety-net cron that re-enqueues orphaned/stuck prototype jobs.

Documentation map

  • Architecture — layers, dependency rules, project structure, Durable Objects, request lifecycle.
  • API reference — every route grouped by area.
  • Integrations — Pipedrive, Mailgun, V0, ClickUp, LiteLLM, Agno, WordPress, PageSpeed, reCAPTCHA.
  • Key flows — lead creation, prototype streaming + DO processing, sales chat, blog delivery.
  • Development — local dev, build, tests, config, rate limiting, caching, scheduled jobs, security, deployment.