Qadra Database ERD

42 tables across 8 domains. Each diagram renders independently.

Core: Tenants & Users

erDiagram
    tenants {
        UUID id PK
        TEXT name
        TEXT slug
        JSONB settings
    }
    users {
        UUID id PK
        UUID tenant_id FK
        TEXT email
        TEXT name
        TEXT role
        BOOLEAN is_super_admin
        BOOLEAN email_verified
    }
    user_tenants {
        UUID user_id PK
        UUID tenant_id PK
        TEXT role
        BOOLEAN is_default
    }
    api_keys {
        UUID id PK
        UUID tenant_id FK
        TEXT key_hash
        TEXT name
    }
    refresh_tokens {
        UUID id PK
        UUID user_id FK
        TEXT token_hash
    }
    email_verification_tokens {
        UUID id PK
        UUID user_id FK
        TEXT token
    }
    team_invites {
        UUID id PK
        UUID tenant_id FK
        UUID invited_by FK
        TEXT email
        TEXT token
    }
    files {
        UUID id PK
        UUID tenant_id FK
        UUID uploaded_by FK
        TEXT object_key
        TEXT purpose
    }
    email_templates {
        UUID id PK
        UUID tenant_id FK
        TEXT slug
        TEXT subject
    }
    notification_logs {
        UUID id PK
        UUID tenant_id FK
        TEXT channel
        TEXT recipient
        TEXT status
    }

    tenants ||--o{ users : has
    tenants ||--o{ user_tenants : members
    users ||--o{ user_tenants : belongs_to
    tenants ||--o{ api_keys : has
    users ||--o{ refresh_tokens : has
    users ||--o{ email_verification_tokens : has
    tenants ||--o{ team_invites : has
    users ||--o{ team_invites : invited_by
    tenants ||--o{ files : has
    users ||--o{ files : uploaded_by
    tenants ||--o{ email_templates : has
    tenants ||--o{ notification_logs : has

Agents, Pipelines & Workloads

erDiagram
    agents {
        UUID id PK
        UUID tenant_id FK
        TEXT name
        TEXT display_name
        TEXT system_prompt
        TEXT control_type
        BOOLEAN is_active
    }
    pipelines {
        UUID id PK
        UUID tenant_id FK
        TEXT name
        JSONB stages
        JSONB draft_stages
    }
    workloads {
        UUID id PK
        UUID tenant_id FK
        UUID pipeline_id FK
        TEXT title
        TEXT status
        TEXT current_stage
        JSONB stage_results
        JSONB pipeline_snapshot
    }
    tasks {
        UUID id PK
        UUID workload_id FK
        UUID agent_id FK
        TEXT stage
        TEXT status
        INTEGER progress
        JSONB output
    }
    artifacts {
        UUID id PK
        UUID workload_id FK
        UUID task_id FK
        UUID agent_id FK
        UUID template_id FK
        TEXT name
        TEXT artifact_type
    }
    usage_records {
        UUID id PK
        UUID tenant_id FK
        UUID workload_id FK
        UUID task_id FK
        UUID agent_id FK
        TEXT operation_type
        INTEGER tokens_in
        INTEGER tokens_out
    }
    artifact_templates {
        UUID id PK
        UUID tenant_id FK
        TEXT name
        TEXT output_format
        UUID renderer_id FK
    }

    pipelines ||--o{ workloads : uses
    workloads ||--o{ tasks : has
    agents ||--o{ tasks : assigned_to
    workloads ||--o{ artifacts : produces
    tasks ||--o{ artifacts : produces
    agents ||--o{ artifacts : created_by
    artifact_templates ||--o{ artifacts : template_for
    workloads ||--o{ usage_records : tracks

Knowledge Graph (SPO)

erDiagram
    spo_nodes {
        UUID id PK
        UUID tenant_id FK
        TEXT value
        TEXT node_type
        VECTOR embedding
        JSONB content
        FLOAT confidence
    }
    spo_triples {
        UUID id PK
        UUID tenant_id FK
        UUID subject_id FK
        UUID predicate_id FK
        UUID object_id FK
        FLOAT confidence
        TEXT asserter
        TEXT assertion_type
    }
    entity_aliases {
        UUID id PK
        UUID tenant_id FK
        TEXT surface_form
        UUID canonical_node_id FK
        TEXT entity_type
    }
    documents {
        UUID id PK
        UUID tenant_id FK
        TEXT title
        TEXT content
        TEXT ingestion_status
        JSONB ingestion_result
        UUID proposed_by FK
        UUID approved_by FK
        TIMESTAMPTZ approved_at
        UUID rejected_by FK
    }
    document_triples {
        UUID document_id PK
        UUID triple_id PK
        FLOAT confidence
        TEXT excerpt
    }
    document_chunks {
        UUID document_id PK
        UUID chunk_id PK
        INTEGER chunk_index
        INTEGER start_offset
    }

    spo_nodes ||--o{ spo_triples : subject
    spo_nodes ||--o{ spo_triples : predicate
    spo_nodes ||--o{ spo_triples : object
    spo_nodes ||--o{ entity_aliases : canonical
    documents ||--o{ document_triples : extracted
    spo_triples ||--o{ document_triples : from
    documents ||--o{ document_chunks : chunked

Attribution (KG-SMILE)

erDiagram
    attribution_sessions {
        UUID id PK
        UUID tenant_id FK
        UUID workload_id FK
        TEXT query
        BOOLEAN competence_passed
        FLOAT spo_coverage
        BOOLEAN verification_passed
        FLOAT fidelity
        FLOAT faithfulness
        FLOAT stability
    }
    triple_attributions {
        UUID id PK
        UUID session_id FK
        UUID triple_id FK
        FLOAT attribution_score
        FLOAT weight
    }
    perturbation_results {
        UUID id PK
        UUID session_id FK
        FLOAT graph_similarity
        FLOAT response_similarity
    }
    spo_component_groups {
        UUID id PK
        UUID session_id FK
        TEXT group_name
    }
    conflict_events {
        UUID id PK
        UUID tenant_id FK
        TEXT new_subject
        TEXT new_predicate
        TEXT new_object
        UUID existing_triple_id FK
        TEXT severity
        TEXT reason
    }

    attribution_sessions ||--o{ triple_attributions : has
    attribution_sessions ||--o{ perturbation_results : has
    attribution_sessions ||--o{ spo_component_groups : has

Flows & Conversations

erDiagram
    agent_flows {
        UUID id PK
        UUID tenant_id FK
        TEXT name
        JSONB flow_data
        INTEGER node_count
        UUID created_by FK
        BOOLEAN is_active
    }
    flow_executions {
        UUID id PK
        UUID tenant_id FK
        UUID flow_id FK
        JSONB flow_snapshot
        TEXT status
        JSONB state
        JSONB node_states
        UUID triggered_by FK
    }
    conversations {
        UUID id PK
        UUID tenant_id FK
        UUID user_id FK
        TEXT title
    }
    conversation_messages {
        UUID id PK
        UUID conversation_id FK
        UUID agent_id FK
        UUID flow_execution_id FK
        TEXT role
        TEXT content
    }

    agent_flows ||--o{ flow_executions : runs
    conversations ||--o{ conversation_messages : has
    flow_executions ||--o{ conversation_messages : produced_by

BALLS Graphs

erDiagram
    graphs {
        UUID id PK
        UUID tenant_id FK
        TEXT name
        JSONB metadata
    }
    vertices {
        UUID id PK
        UUID graph_id FK
        FLOAT x
        FLOAT y
        FLOAT z
        TEXT label
        FLOAT curvature
    }
    edges {
        UUID id PK
        UUID graph_id FK
        UUID source_id FK
        UUID target_id FK
        FLOAT weight
        FLOAT curvature
    }

    graphs ||--o{ vertices : has
    graphs ||--o{ edges : has
    vertices ||--o{ edges : source
    vertices ||--o{ edges : target

Plugins & Renderers

erDiagram
    plugins {
        UUID id PK
        UUID tenant_id FK
        TEXT plugin_type
        TEXT name
        INTEGER version
        TEXT code
        BOOLEAN is_active
        BOOLEAN is_global
    }
    renderers {
        UUID id PK
        UUID tenant_id FK
        TEXT name
        INTEGER version
        TEXT output_format
        TEXT code
        BOOLEAN is_active
        BOOLEAN is_global
    }
    memory {
        UUID id PK
        UUID tenant_id FK
        TEXT key
        JSONB value
        VECTOR embedding
    }
    sessions {
        UUID id PK
        UUID tenant_id FK
        TEXT session_type
    }
    usage {
        UUID id PK
        UUID tenant_id FK
        UUID agent_id FK
        UUID session_id FK
        INTEGER tokens_in
        INTEGER tokens_out
    }

    sessions ||--o{ usage : during