erDiagram
    users {
        uuid id PK
        varchar username UK
        varchar email UK
        varchar display_name
        text avatar_url
        boolean is_active
        timestamp last_seen
        varchar role
        varchar status
        integer reputation_score
        boolean is_banned
        boolean is_muted
        timestamp created_at
        timestamp updated_at
    }

    conversations {
        uuid id PK
        varchar name
        text description
        varchar conversation_type
        boolean is_private
        uuid created_by FK
        timestamp created_at
        timestamp updated_at
    }

    conversation_members {
        uuid conversation_id PK,FK
        uuid user_id PK,FK
        varchar role
        timestamp joined_at
    }

    messages {
        uuid id PK
        uuid conversation_id FK
        uuid sender_id FK
        text content
        varchar message_type
        uuid parent_message_id FK
        uuid reply_to_id FK
        boolean is_pinned
        boolean is_deleted
        boolean is_edited
        timestamp edited_at
        jsonb metadata
        varchar status
        timestamp created_at
        timestamp updated_at
    }

    rooms {
        integer id PK
        varchar name UK
        varchar display_name
        text description
        integer creator_id FK
        boolean is_private
        integer max_members
        timestamp created_at
        timestamp updated_at
    }

    room_members {
        integer id PK
        integer room_id FK
        integer user_id FK
        varchar role
        timestamp joined_at
        timestamp last_read_at
    }

    message_reactions {
        integer id PK
        integer message_id FK
        integer user_id FK
        varchar reaction_type
        timestamp created_at
    }

    user_blocks {
        integer id PK
        integer blocker_id FK
        integer blocked_id FK
        varchar reason
        timestamp created_at
    }

    sanctions {
        integer id PK
        integer user_id FK
        integer moderator_id FK
        varchar sanction_type
        varchar reason
        text message
        timestamp expires_at
        boolean is_active
        timestamp created_at
    }

    notifications {
        integer id PK
        integer user_id FK
        varchar type
        varchar title
        text content
        jsonb metadata
        boolean is_read
        timestamp created_at
        timestamp read_at
    }

    user_sessions {
        integer id PK
        integer user_id FK
        varchar session_token UK
        varchar device_info
        inet ip_address
        timestamp last_activity
        timestamp expires_at
        timestamp created_at
        boolean is_active
    }

    audit_logs {
        integer id PK
        integer user_id FK
        varchar action
        varchar resource_type
        varchar resource_id
        jsonb details
        inet ip_address
        text user_agent
        timestamp created_at
    }

    %% Relations
    users ||--o{ conversations : "creates"
    users ||--o{ conversation_members : "participates"
    conversations ||--o{ conversation_members : "has"
    conversations ||--o{ messages : "contains"
    users ||--o{ messages : "sends"
    messages ||--o{ messages : "replies_to"
    messages ||--o{ message_reactions : "receives"
    users ||--o{ message_reactions : "reacts"
    users ||--o{ user_blocks : "blocks"
    users ||--o{ user_blocks : "blocked_by"
    users ||--o{ sanctions : "receives"
    users ||--o{ sanctions : "moderates"
    users ||--o{ rooms : "creates"
    users ||--o{ room_members : "joins"
    rooms ||--o{ room_members : "has"
    users ||--o{ notifications : "receives"
    users ||--o{ user_sessions : "has"
    users ||--o{ audit_logs : "performs"
