# Entity relationship diagram

**Audience:** Developers

## Entity Relationship Diagram

The following diagram illustrates the relationships between the core database tables in the application: `accounts`, `taskgroups`, `research_tasks`, and `profiles`.

{% @mermaid/diagram content="erDiagram
ACCOUNTS ||--o{ TASKGROUPS : creates
ACCOUNTS ||--o{ RESEARCH\_TASKS : creates
ACCOUNTS {
uuid id PK "Unique account identifier"
string name "Account name (unique)"
string hashed\_api\_key "Bcrypt hashed API key"
string key\_preview "Preview of API key"
timestamp created\_at
timestamp updated\_at
timestamp deleted\_at "Soft deletion timestamp"
}

```
TASKGROUPS ||--o{ RESEARCH_TASKS : contains
TASKGROUPS {
    string taskgroup_id PK
    string status "Current status (e.g., PENDING, COMPLETED)"
    string profile "Profile name used"
    string webhook_url "Notification URL"
    string webhook_secret "Webhook signature secret"
    text error "Error message if failed"
    timestamp created_at
    timestamp started_at
    timestamp completed_at
    timestamp updated_at
    uuid account_id FK
}

RESEARCH_TASKS {
    string task_id PK "Celery task ID"
    text query "Research query"
    string status "Current status"
    string profile "Profile name used"
    json result "Task result data"
    text error "Error message"
    string webhook_url
    string webhook_secret
    timestamp created_at
    timestamp started_at
    timestamp completed_at
    timestamp updated_at
    string taskgroup_id FK
    uuid account_id FK
}

PROFILES ||--o{ TASKGROUPS : uses
PROFILES ||--o{ RESEARCH_TASKS : uses
PROFILES {
    string name PK "Profile identifier"
    string provider "Provider type"
    json params "Configuration parameters"
    text description
    timestamp updated_at
}" %}
```
