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
C:\dev\knowledge\architecture\lifecycle-email-system.md— FULL architecture spec with database schema, sequence definitions, skip conditions, template list, cron design, and migration planC:\dev\CLAUDE.md— cross-project rules, especially Supabase safety, git workflowC:\dev\churchwiseai-web\CLAUDE.md— project-specific rulesC:\dev\PRICING.md— plan names and prices (needed for email content)C:\dev\knowledge\acceptance\starter-chat.md— Starter touchpoints for email contentC:\dev\knowledge\acceptance\pro-suite-chat.md— Pro/Suite touchpoints for email content
Implementation order
Phase 1: Infrastructure
- Create
lifecycle_emails_senttable (migration SQL) - Create
src/lib/lifecycle-emails.ts— sequence definitions, skip conditions, send-and-log function - Create
src/app/api/cron/lifecycle-emails/route.ts— daily cron job - Add cron schedule to
vercel.json - Test with demo church — manually trigger cron, verify dedup works
Phase 2: Onboarding Sequences (Starter, Pro, Suite Chat)
- Create shared email layout
_layout.tsx(Sacred Gold #D4AF37, Navy #1B365D, Cream #FEFCF8) - Create welcome email templates per plan (enhance existing welcome email)
- Create AI Starter Kit email template
- Create day 2, 5, 7 nudge templates
- Create trial-ending templates (day 13)
- Create first-month check-in template
- Enhance Stripe webhook to fire immediate emails (welcome + kit) and create sequence
- Test full onboarding sequence with demo church
Phase 3: Replace MailerLite Automations
- Create newsletter welcome sequence templates
- Create 7-day AI Ministry Course templates (7 emails)
- Create Starter Kit buyer nurture templates
- Create cross-promo templates (4 sequences)
- Create win-back sequence templates
- Create payment failed + cancellation templates
- Wire up non-church sequence triggers (newsletter signup, kit purchase, cross-promo events)
- Test each sequence
Phase 4: Migration
- Verify all sequences working with test subscribers
- Disable MailerLite automations one by one
- Add lifecycle email health check to WatchTower daily audit
- 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(UUID00000000-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_senttable has correct entries - Test skip conditions by adding/removing church data
- Test dedup by running cron multiple times — same email should never send twice