Flow 1 — website lead
The marketing site’s contact form calls thesubmit_website_lead RPC (anon-callable,
defended by a honeypot field and a per-email rate limit) → row in
codex.website_leads.
Flow 2 — demo-call booking (Cal.com)
cal-webhook receives BOOKING_CREATED only (other Cal.com triggers are noise,
not lead signals) and inserts directly into website_leads with
interest='design_partner' and source = the Cal.com event-type slug.
- Auth is Cal.com’s own HMAC-SHA256 over the raw body (header
x-cal-signature-256) — not Svix. Secret:CAL_WEBHOOK_SECRET. - It reads
organisation,role,team_sizefrom custom booking questions matched by identifier — the Cal.com event type’s questions must be named exactlyorganisation,role,team_size. Unanswered questions become NULL and never fail the insert. - It bypasses the RPC’s honeypot/rate-limit on purpose: those defenses exist for the anon-callable surface; this is a signature-verified server-to-server source.
Flow 3 — the email nurture pipeline
Design facts that answer most questions:clerk-to-resendis a second, separate Clerk webhook endpoint with its own signing secret (CLERK_TO_RESEND_SIGNING_SECRET). Deliberate isolation: a Resend outage must never retry-storm the identity-sync webhook (clerk-webhook), which is load-bearing for RLS and entitlements.clerk-to-resendnever writescodex.*— read-only Supabase access, only to resolve domain-owner emails for org-level billing events.- Sequencing lives entirely in Resend Automations (built in the Resend dashboard,
not in this repo). The first event
resend-webhookhears about a send is usually the first it has ever heard of it, hence lazy upserts throughout. email_eventshas no unique constraint and no dedup by design — Resend retries and multiple opens/clicks are legitimate.
Testing the pipeline safely
pnpm test:emails (script scripts/test-email-events.ts) has two modes:
Resend environment as-built
Full inventory of every template, automation, custom event, segment and webhook in
the live Resend account — including automation step graphs and four open gaps.

