Systems

Email

One structured system for form submissions and all email, with swappable providers.

Email

Purpose

Email is one structured system for form submissions and all outbound mail. Providers are swappable (for example AhaSend or Resend) so a project does not rewrite product code when the vendor changes. Usage is attributed to a project so Ziteox can meter sends.

Current state

PieceStatus
Project outbound metering (tags + webhooks → events)Live (AhaSend primary; Resend webhook path exists)
Unified event normalisationLive in portal Edge Functions
Admin outreach send via ResendLive in admin code
Form-submission intake as a Forge interfacePlanned — no dedicated form-submission service code found today; tags docs mention contact-form deliveries as a send type
Email Notification Service (agency renewals / internal alerts)Planned — host Railway; provider candidates AhaSend, Resend, SendGrid, Postmark; repo notification-service or email-service

What exists in code today

Usage ingestion (client Supabase Edge Functions)

  • Register send attribution (message id → project): portal: ziteox-client/supabase/functions/email-register-send/index.ts
  • AhaSend webhook → email.events: portal: ziteox-client/supabase/functions/email-webhook-ahasend/index.ts
  • Resend webhook → email.events: portal: ziteox-client/supabase/functions/email-webhook-resend/index.ts
  • Provider → unified event shape: portal: ziteox-client/supabase/functions/_shared/normalize-email-event.ts
  • Send-time tag helpers: portal: ziteox-client/supabase/functions/_shared/build-email-tags.ts
  • Quota / usage sync dispatcher (includes email-related metering ops): portal: ziteox-client/supabase/functions/sync-quota-usage/index.ts

Admin

  • Outreach send through Resend: portal: ziteox-admin/src/lib/outreach-send-email.ts (depends on resend in admin package.json)
  • Same tag convention: portal: ziteox-admin/src/lib/build-email-tags.ts
  • Agent setup prompt for project tags: portal: ziteox-admin/src/lib/email-setup-prompt.ts
  • Quota sync provider handlers: portal: ziteox-admin/src/lib/quota-sync-providers.ts

Provider roles (from notes + code)

  • AhaSend — primary live provider for project outbound metering; Standard Webhooks into Edge Functions
  • Resend — admin dependency for outreach; Edge webhook function exists (wire RESEND_WEBHOOK_SECRET when actively used)

Target shape (planned Forge system)

One interface with provider adapters:

  1. Send — outbound mail with project tags
  2. Form submission — structured intake that becomes a send (planned; not a separate live service today)
  3. Events / webhooks — provider webhooks normalised into one event model (already started as normalize-email-event)

Adding a provider means a mapper + a thin webhook verifier — schema stays the same (see comment in normalize-email-event).

Interfaces

KindWhat
TagsEvery outbound send attaches project_id and env (production or staging) via buildEmailTags
AhaSend tagsString tags: project_id:…, env:… (webhooks omit tags → also call email-register-send)
Resend tagsName/value tag pairs; webhooks echo tags
Edge Functionsemail-register-send, email-webhook-ahasend, email-webhook-resend, sync-quota-usage
Webhook URLs (pattern)https://PROJECT_REF.supabase.co/functions/v1/email-webhook-ahasend and …/email-webhook-resend

Env var names only (never values):

EMAIL_ATTRIBUTION_SECRET, AHASEND_WEBHOOK_SECRET, RESEND_WEBHOOK_SECRET, RESEND_API_KEY, plus injected SUPABASE_URL / SUPABASE_SERVICE_ROLE_KEY on Edge Functions. Sync-related names used by quota sync include SYNC_CRON_SECRET, SECRETS_KEK, and vendor keys as configured in admin — not Forge.

Project env vars stay in the admin portal, not in Forge.

Open questions

  • When does form-submission intake become a real shared interface (vs project-local contact forms that only tag sends)?
  • Which provider is default for the planned Email Notification Service (AhaSend, Resend, SendGrid, Postmark)?
  • How much of today’s Edge Function surface becomes a documented Forge package vs stays portal-internal?
  • Repo name for the notification service (notification-service vs email-service)?

Also listed on Open questions.

  • Systems
  • Loom: Ziteox Forge — Email system · Email Notification Service - Ziteox Internal System · AhaSend · Resend · Ziteox Forge — Env vars boundary