---
name: cloudflare-lead-capture
description: Scaffold Cloudflare Pages or Workers lead-capture systems (Pages Functions OR Astro SSR API routes) with D1 contacts, web forms, Resend email templates, unsubscribe links, Turnstile checks, exports, and a small admin UI when a project needs repeatable email database infrastructure.
license: MIT
tags: [cloudflare, d1, resend, email, lead-capture, forms, turnstile, autovault, commerce]
agents: [claude-code, codex, autojack]
category: cloudflare
metadata:
version: "1.4.0"
capabilities:
network: true
filesystem: readwrite
tools: [Bash, Node, Read, Edit]
requires-secrets: []
resources:
- path: bin/setup
type: file
- path: bin/scaffold
type: file
- path: bin/doctor
type: file
- path: templates/project/schema/lead-capture.sql
type: file
- path: templates/project/functions/lib/lead-capture/http.js
type: file
- path: templates/project/functions/lib/lead-capture/tokens.js
type: file
- path: templates/project/functions/lib/lead-capture/turnstile.js
type: file
- path: templates/project/functions/lib/lead-capture/email.js
type: file
- path: templates/project/functions/api/signup.js
type: file
- path: templates/project/functions/api/lead.js
type: file
- path: templates/project/functions/unsubscribe.js
type: file
- path: templates/project/functions/admin/lead-capture.js
type: file
- path: templates/project/functions/admin/lead-capture/templates.js
type: file
- path: templates/project/functions/admin/lead-capture/test-email.js
type: file
- path: templates/project/lead-capture-admin.html
type: file
- path: templates/project/snippets/lead-form.html
type: file
- path: templates/project/README.lead-capture.md
type: file
- path: templates/project/wrangler.toml
type: file
- path: templates/project/wrangler.lead-capture.jsonc
type: file
- path: templates/astro-ssr/src/pages/api/contact.ts
type: file
- path: templates/astro-ssr/src/components/ContactForm.astro
type: file
- path: templates/astro-ssr/README.astro-ssr.md
type: file
bin:
setup:
command: bin/setup
description: Configure Cloudflare D1 and Pages secrets for lead capture without exposing secret values to the agent.
requires-tty: true
scaffold:
command: bin/scaffold
description: Generate the lead-capture layer in the current project. Auto-detects Pages Functions vs Astro SSR (Astro + @astrojs/cloudflare); force with --mode pages|astro-ssr. astro-ssr emits the shared D1 schema + an Astro API route (src/pages/api/contact.ts) + a ContactForm component; pages emits Functions, admin UI, and form snippets.
requires-tty: false
doctor:
command: bin/doctor
description: Verify local lead-capture project files, Wrangler config, and expected secret names.
requires-tty: false
---
# Cloudflare Lead Capture
## When To Use
Use this skill when a user wants a repeatable Cloudflare-based email database, waitlist, contact form, capture form, web lead form, or small lead-management backend. It is designed for Cloudflare Pages Functions or Workers with D1 as the system of record and Resend for outbound email.
Use the separate `cloudflare-commerce-deploy` skill for deployment, DNS, custom domains, or other Cloudflare operator work. This skill owns only the lead-capture and email-template layer.
For projects with separate preview and production environments, see the **Per-Environment Pages Env Vars** section in `cloudflare-commerce-deploy` for how to set `RESEND_API_KEY`, `ADMIN_TOKEN`, and `TURNSTILE_SECRET_KEY` differently per environment. `wrangler pages secret put` only writes to production; preview-environment secrets require the project-level PATCH endpoint.
## Two project shapes
**Decide which shape the project is before scaffolding — they wire endpoints and bindings differently:**
- **Cloudflare Pages** (static site + `functions/`): use the `bin/scaffold` templates below. Endpoints are Pages Functions (`functions/api/*.js`); bindings arrive as the handler's `env` argument; secrets via `wrangler pages secret put`.
- **Astro SSR on Workers** (`output: 'server'`, `@astrojs/cloudflare`, `wrangler deploy` — e.g. an EmDash/Astro site, see `cloudflare-emdash-cms-deploy`): there is **no `functions/` directory**. Hand-write the same patterns as Astro API routes (next section). The scaffold's `schema/` and `lib/` files are still useful references.
## Astro SSR (Workers) variant
**Scaffold it:** `autovault skill scaffold cloudflare-lead-capture -- --mode=astro-ssr` (auto-detected for Astro + `@astrojs/cloudflare` projects; binding defaults to `DB`). It emits the shared `schema/lead-capture.sql` + `src/pages/api/contact.ts` (writes to `contacts`/`submissions` so the admin UI/exports see these leads; lead-never-lost; honeypot) + `src/components/ContactForm.astro` (fetch enhancement with a no-JS `?sent=1` fallback). Then apply the schema, set `RESEND_API_KEY` (Worker secret) + `NOTIFY_FROM`/`NOTIFY_TO` vars, render `