Files
pulse-crm-backend/docs/ER-DIAGRAM.md
Flux_bot 4b7297c199 feat: Datenbank-Schema & ER-Diagramm
📊 Schema (schema.sql):
- organizations (Multi-Tenancy)
- users (mit Rollen)
- contacts (mit DSGVO Felder)
- companies
- pipelines (JSONB stages)
- deals
- activities
- audit_logs (DSGVO)
- refresh_tokens

📈 ER-Diagramm (Mermaid)
🌱 Seed-Daten für Testing

Features:
- UUID Primary Keys
- Soft Delete (deleted_at)
- Auto-updated timestamps
- GIN Index für Tags
- Row-Level Security ready
2026-02-11 10:03:34 +00:00

150 lines
3.5 KiB
Markdown

# Pulse CRM - Entity Relationship Diagram
```mermaid
erDiagram
ORGANIZATIONS ||--o{ USERS : has
ORGANIZATIONS ||--o{ CONTACTS : has
ORGANIZATIONS ||--o{ COMPANIES : has
ORGANIZATIONS ||--o{ PIPELINES : has
ORGANIZATIONS ||--o{ DEALS : has
ORGANIZATIONS ||--o{ ACTIVITIES : has
ORGANIZATIONS ||--o{ AUDIT_LOGS : has
USERS ||--o{ CONTACTS : owns
USERS ||--o{ COMPANIES : owns
USERS ||--o{ DEALS : owns
USERS ||--o{ ACTIVITIES : creates
USERS ||--o{ REFRESH_TOKENS : has
COMPANIES ||--o{ CONTACTS : employs
COMPANIES ||--o{ DEALS : has
CONTACTS ||--o{ DEALS : associated
CONTACTS ||--o{ ACTIVITIES : has
PIPELINES ||--o{ DEALS : contains
DEALS ||--o{ ACTIVITIES : has
ORGANIZATIONS {
uuid id PK
string name
string slug UK
jsonb settings
string subscription_plan
timestamp created_at
}
USERS {
uuid id PK
uuid org_id FK
string email UK
string password_hash
string first_name
string last_name
string role
boolean is_active
timestamp last_login_at
}
CONTACTS {
uuid id PK
uuid org_id FK
uuid company_id FK
uuid owner_id FK
string first_name
string last_name
string email
string phone
string status
boolean gdpr_consent
timestamp deleted_at
}
COMPANIES {
uuid id PK
uuid org_id FK
uuid owner_id FK
string name
string industry
string website
string phone
timestamp deleted_at
}
PIPELINES {
uuid id PK
uuid org_id FK
string name
boolean is_default
jsonb stages
}
DEALS {
uuid id PK
uuid org_id FK
uuid pipeline_id FK
uuid contact_id FK
uuid company_id FK
uuid owner_id FK
string title
decimal value
string stage_id
string status
date expected_close_date
}
ACTIVITIES {
uuid id PK
uuid org_id FK
uuid user_id FK
uuid contact_id FK
uuid deal_id FK
string type
string subject
text description
timestamp due_date
boolean is_completed
}
AUDIT_LOGS {
uuid id PK
uuid org_id FK
uuid user_id FK
string action
string entity_type
uuid entity_id
jsonb changes
inet ip_address
}
REFRESH_TOKENS {
uuid id PK
uuid user_id FK
string token_hash
timestamp expires_at
}
```
## Tabellen-Übersicht
| Tabelle | Beschreibung | Relationships |
|---------|--------------|---------------|
| `organizations` | Mandanten (Multi-Tenancy) | Parent für alle Daten |
| `users` | Benutzer/Team-Mitglieder | Gehört zu Organization |
| `contacts` | Personen/Leads | Gehört zu Organization, optional zu Company |
| `companies` | Firmen | Gehört zu Organization |
| `pipelines` | Sales Pipelines | Gehört zu Organization |
| `deals` | Opportunities | Gehört zu Pipeline, Contact, Company |
| `activities` | Notizen, Calls, Tasks | Gehört zu Contact oder Deal |
| `audit_logs` | DSGVO Audit Trail | Protokolliert alle Änderungen |
| `refresh_tokens` | JWT Refresh Tokens | Gehört zu User |
## Indizes
Alle Tabellen haben Indizes auf:
- `org_id` - Multi-Tenancy Queries
- Foreign Keys
- Häufig gefilterte Felder (status, email, etc.)
- `deleted_at` - Soft Delete Queries