One structured system for form submissions and all email, with swappable providers.
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
| Piece | Status |
|---|---|
| Project outbound metering (tags + webhooks → events) | Live (AhaSend primary; Resend webhook path exists) |
| Unified event normalisation | Live in portal Edge Functions |
| Admin outreach send via Resend | Live in admin code |
| Form-submission intake as a Forge interface | Planned — 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 onresendin adminpackage.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_SECRETwhen actively used)
Target shape (planned Forge system)
One interface with provider adapters:
- Send — outbound mail with project tags
- Form submission — structured intake that becomes a send (planned; not a separate live service today)
- 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
| Kind | What |
|---|---|
| Tags | Every outbound send attaches project_id and env (production or staging) via buildEmailTags |
| AhaSend tags | String tags: project_id:…, env:… (webhooks omit tags → also call email-register-send) |
| Resend tags | Name/value tag pairs; webhooks echo tags |
| Edge Functions | email-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-servicevsemail-service)?
Also listed on Open questions.
Related
- Systems
- Loom: Ziteox Forge — Email system · Email Notification Service - Ziteox Internal System · AhaSend · Resend · Ziteox Forge — Env vars boundary