> ## Documentation Index
> Fetch the complete documentation index at: https://docs.events-52grad.de/llms.txt
> Use this file to discover all available pages before exploring further.

# Supabase

> Datenbankstruktur und Storage-Konfiguration.

## E-Mail-Tabellen

Das Datenbankschema wurde von Weiss Global entworfen. Hier die Übersicht der E-Mail-relevanten Tabellen:

### `email_accounts`

Konfiguration der angebundenen E-Mail-Konten.

| Spalte              | Typ     | Beschreibung                              |
| ------------------- | ------- | ----------------------------------------- |
| id                  | uuid    | Primary Key                               |
| email\_address      | text    | E-Mail-Adresse                            |
| display\_name       | text    | Anzeigename                               |
| imap\_host          | text    | IMAP-Server                               |
| imap\_port          | integer | IMAP-Port (993)                           |
| smtp\_host          | text    | SMTP-Server                               |
| smtp\_port          | integer | SMTP-Port (465)                           |
| encrypted\_password | text    | Passwort (Platzhalter, echtes PW in .env) |
| is\_active          | boolean | Aktiv/Inaktiv                             |

**Account-ID für `team@events-52grad.de`:** `0bd9c6b2-9ef2-4c9e-8066-a922e7c02a7c`

### `emails`

Alle ein- und ausgehenden E-Mails.

| Spalte           | Typ         | Beschreibung                           |
| ---------------- | ----------- | -------------------------------------- |
| id               | uuid        | Primary Key                            |
| account\_id      | uuid        | FK → email\_accounts                   |
| message\_id      | text        | RFC Message-ID                         |
| in\_reply\_to    | text        | Parent Message-ID (Threading)          |
| references       | array       | Gesamte Reference-Kette                |
| thread\_id       | uuid        | FK → email\_threads                    |
| folder           | text        | IMAP-Ordner (INBOX, Gesendete Objekte) |
| direction        | text        | `inbound` oder `outbound`              |
| uid              | bigint      | IMAP UID                               |
| from\_address    | jsonb       | `{name, address}`                      |
| to\_addresses    | jsonb       | `[{name, address}, ...]`               |
| cc\_addresses    | jsonb       | `[{name, address}, ...]`               |
| bcc\_addresses   | jsonb       | `[{name, address}, ...]`               |
| subject          | text        | Betreff                                |
| text\_body       | text        | Plain-Text-Body                        |
| html\_body       | text        | HTML-Body                              |
| date             | timestamptz | Sende-/Empfangsdatum                   |
| has\_attachments | boolean     | Hat Anhänge?                           |
| flags            | array       | IMAP-Flags (\Seen, \Flagged etc.)      |
| headers\_raw     | jsonb       | Alle Header als Key-Value              |
| size\_bytes      | integer     | Größe in Bytes                         |
| is\_read         | boolean     | Gelesen?                               |
| is\_starred      | boolean     | Markiert?                              |
| is\_archived     | boolean     | Archiviert (soft-delete)?              |
| customer\_id     | uuid        | FK → customers                         |
| company\_id      | uuid        | FK → companies                         |
| synced\_at       | timestamptz | Zeitpunkt der Synchronisation          |

### `email_threads`

Gruppierung zusammengehöriger E-Mails.

| Spalte                 | Typ         | Beschreibung                       |
| ---------------------- | ----------- | ---------------------------------- |
| id                     | uuid        | Primary Key                        |
| account\_id            | uuid        | FK → email\_accounts               |
| thread\_key            | text        | Erste Message-ID im Thread         |
| subject                | text        | Bereinigter Betreff (ohne Re:/AW:) |
| last\_message\_at      | timestamptz | Letzte Nachricht im Thread         |
| message\_count         | integer     | Anzahl Nachrichten                 |
| participant\_addresses | array       | Alle beteiligten E-Mail-Adressen   |
| is\_unread             | boolean     | Ungelesene Nachrichten?            |

### `email_attachments`

Datei-Anhänge.

| Spalte        | Typ     | Beschreibung                 |
| ------------- | ------- | ---------------------------- |
| id            | uuid    | Primary Key                  |
| email\_id     | uuid    | FK → emails                  |
| filename      | text    | Dateiname                    |
| content\_type | text    | MIME-Type                    |
| size\_bytes   | integer | Größe in Bytes               |
| storage\_path | text    | Pfad in Supabase Storage     |
| content\_id   | text    | Content-ID für Inline-Bilder |
| is\_inline    | boolean | Inline-Anhang?               |
| checksum      | text    | Prüfsumme                    |

### `email_sync_state`

Synchronisationsstatus pro Ordner.

| Spalte           | Typ         | Beschreibung                |
| ---------------- | ----------- | --------------------------- |
| id               | uuid        | Primary Key                 |
| account\_id      | uuid        | FK → email\_accounts        |
| folder\_name     | text        | IMAP-Ordnername             |
| uid\_validity    | bigint      | IMAP UID Validity           |
| last\_uid        | bigint      | Zuletzt synchronisierte UID |
| sync\_status     | text        | `idle`, `syncing`, `error`  |
| error\_message   | text        | Letzte Fehlermeldung        |
| last\_synced\_at | timestamptz | Letzter erfolgreicher Sync  |

## Storage

Anhänge werden in Supabase Storage gespeichert:

* **Bucket:** `email-attachments` (privat)
* **Pfadstruktur:** `{account_id}/{email_id}/{filename}`
* **Max. Dateigröße:** 10 MB
