Skip to main content

Handoff: Build Lifecycle Email System

What to do

Build a complete email lifecycle system that replaces all 8 existing MailerLite automations and adds new onboarding/trial sequences. Everything is agent-managed — the founder never touches MailerLite.

Read these first

  1. C:\dev\knowledge\architecture\lifecycle-email-system.md — FULL architecture spec with database schema, sequence definitions, skip conditions, template list, cron design, and migration plan
  2. C:\dev\CLAUDE.md — cross-project rules, especially Supabase safety, git workflow
  3. C:\dev\churchwiseai-web\CLAUDE.md — project-specific rules
  4. C:\dev\PRICING.md — plan names and prices (needed for email content)
  5. C:\dev\knowledge\acceptance\starter-chat.md — Starter touchpoints for email content
  6. C:\dev\knowledge\acceptance\pro-suite-chat.md — Pro/Suite touchpoints for email content

Implementation order

Phase 1: Infrastructure

  1. Create lifecycle_emails_sent table (migration SQL)
  2. Create src/lib/lifecycle-emails.ts — sequence definitions, skip conditions, send-and-log function
  3. Create src/app/api/cron/lifecycle-emails/route.ts — daily cron job
  4. Add cron schedule to vercel.json
  5. Test with demo church — manually trigger cron, verify dedup works

Phase 2: Onboarding Sequences (Starter, Pro, Suite Chat)

  1. Create shared email layout _layout.tsx (Sacred Gold #D4AF37, Navy #1B365D, Cream #FEFCF8)
  2. Create welcome email templates per plan (enhance existing welcome email)
  3. Create AI Starter Kit email template
  4. Create day 2, 5, 7 nudge templates
  5. Create trial-ending templates (day 13)
  6. Create first-month check-in template
  7. Enhance Stripe webhook to fire immediate emails (welcome + kit) and create sequence
  8. Test full onboarding sequence with demo church

Phase 3: Replace MailerLite Automations

  1. Create newsletter welcome sequence templates
  2. Create 7-day AI Ministry Course templates (7 emails)
  3. Create Starter Kit buyer nurture templates
  4. Create cross-promo templates (4 sequences)
  5. Create win-back sequence templates
  6. Create payment failed + cancellation templates
  7. Wire up non-church sequence triggers (newsletter signup, kit purchase, cross-promo events)
  8. Test each sequence

Phase 4: Migration

  1. Verify all sequences working with test subscribers
  2. Disable MailerLite automations one by one
  3. Add lifecycle email health check to WatchTower daily audit
  4. Monitor for 1 week

Key decisions already made

  • Resend for sending, NOT MailerLite — MailerLite API can't create automations
  • No sequence engine — just a sent log with UNIQUE(church_id, email_key) constraint
  • Stateless cron — computes what's due from activated_at, checks sent log, idempotent
  • Smart skip conditions — checks Supabase before sending (has_hours, has_faqs, etc.)
  • React Email templates — same pattern as existing welcome email
  • MailerLite stays for: newsletter subscriber mgmt + Care broadcasts only

Email compliance & settings

For all marketing/nurture emails (NOT transactional like welcome or payment failed):

  • Include preheader text (hidden, shows in inbox preview)
  • CSS must be inlined (React Email handles this)
  • Include unsubscribe link in footer (CAN-SPAM)
  • Include preferences link → /admin/[token]?tab=settings&sub=notifications
  • If ever sending through MailerLite (Care broadcasts): enable auto-preheader, auto-CSS-inline, auto-footer, and preferences link in MailerLite template settings

MailerLite automations to disable (9 total — see architecture doc for full table)

8 active + 1 paused/incomplete ("CWA Trial Nurture" from 2025-11-15 — never finished, exactly what our onboarding sequences replace). Disable each one AFTER its replacement sequence is verified.

Template design rules

  • Match ChurchWiseAI brand: Sacred Gold, Navy, Cream, Playfair Display headings, Inter body
  • Every email has: church name personalization, dashboard link, unsubscribe (for marketing emails)
  • Plan-specific content: different features highlighted per tier
  • Conditional content: has_website vs no_website for Pro/Suite welcome emails
  • Tone: warm, pastoral, not corporate. "We're rooting for your church" energy.
  • Keep emails short — pastors are busy. 3-4 paragraphs max.

Testing approach

  • Use demo church churchwiseai-demo (UUID 00000000-0000-4000-a000-000000000001)
  • DO NOT write junk data to production — use only the demo church
  • Manually trigger cron via GET request with Vercel cron auth header
  • Check Resend dashboard for delivery confirmation
  • Verify lifecycle_emails_sent table has correct entries
  • Test skip conditions by adding/removing church data
  • Test dedup by running cron multiple times — same email should never send twice