# Data model

> The sypnia_mail schema: domains, templates, e-mails, events, suppressions, webhooks and inbound.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://mail.docs.sypnia.com/architecture/data-model/

For agents: sypnia_mail schema: domains (dkim_tokens, state, warmup_day), templates + template_versions (locale, subject, html, text), emails (from, to, subject, template, tags jsonb, status, scheduled_at, ses_message_id, idempotency_key, body_ref; partitioned by month; bodies in storage deleted at retention), email_events, suppressions (unique project_id+address, reason, source_email_id), webhooks + webhook_deliveries, inbound_rules + inbound_messages (raw_ref, verdicts), keys (scopes, hash).

| Table                                  | Holds                        | Key columns                                                                                                                                        |
| -------------------------------------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `domains`                              | sending domains of a project | `project_id`, `name`, `dkim_tokens`, `state`, `verified_at`, `warmup_day`                                                                          |
| `templates`                            | a template                   | `project_id`, `name`, `default_locale`, `published_version`                                                                                        |
| `template_versions`                    | each saved version           | `template_id`, `version`, `locale`, `subject`, `html`, `text`, `created_by`                                                                        |
| `emails`                               | each e-mail                  | `id`, `project_id`, `from`, `to`, `subject`, `template`, `tags` (jsonb), `status`, `scheduled_at`, `ses_message_id`, `idempotency_key`, `body_ref` |
| `email_events`                         | each event                   | `email_id`, `type`, `at`, `detail` (jsonb)                                                                                                         |
| `suppressions`                         | addresses not sent to        | `project_id`, `address` (lower-cased), `reason`, `source_email_id`, `created_at`                                                                   |
| `webhooks` and `webhook_deliveries`    | endpoints and each attempt   | `url`, `events[]`, `secret_hash`, `paused_at`; `event_id`, `attempt`, `status`                                                                     |
| `inbound_rules` and `inbound_messages` | rules and received messages  | `match`, `action`, `target`; `raw_ref`, `from`, `to`, `rule_id`, `verdicts`                                                                        |
| `keys`                                 | API and SMTP keys            | `project_id`, `name`, `scopes[]`, `hash`, `last_used_at`                                                                                           |

`emails` is partitioned by month; bodies (`body_ref`) are objects in storage, deleted at the end of the plan's retention. `suppressions` has a unique index on `(project_id, address)` and is checked on every send.
