AAnvio
Database

Entity-Relationship Diagram

The complete PostgreSQL schema for Anvio's optional Level 3 database layer, diagrammed from packages/db/src/schema.ts.

3 min read

This schema is Level 3+ only. Anvio's default (Level 1) storage is the filesystem — workspace/sessions/*.jsonl, workspace/memory/, YAML/Markdown agent definitions. PostgreSQL via Drizzle ORM only comes into play when you opt into multi-user production storage. See Progressive Enhancement and ADR: PostgreSQL + Drizzle.

The diagram below is built directly from packages/db/src/schema.ts — every table, column, type, and foreign key here matches that file line for line. There are 9 tables.

Rendering diagram…

Note on notation: personas has no foreign keys pointing to or from it in the current schema — it's a standalone catalog table (no join table to agents yet). This matches packages/db/src/schema.ts exactly; it is not an omission in the diagram.

Reading the diagram

  • users → sessions (one-to-many): every session belongs to exactly one user (sessions.user_id NOT NULL REFERENCES users.id ON DELETE CASCADE). Deleting a user deletes their sessions.
  • users → memory_entries (one-to-many): every memory entry belongs to a user (ON DELETE CASCADE), independent of session lifecycle.
  • agents → sessions (one-to-many): a session runs a specific agent (sessions.agent_id NOT NULL REFERENCES agents.id, no cascade — agents aren't expected to be deleted while sessions reference them).
  • agents ↔ skills (many-to-many via agent_skills): a join table with a composite primary key (agent_id, skill_id), both columns ON DELETE CASCADE.
  • sessions → session_messages (one-to-many): the conversation transcript, ON DELETE CASCADE.
  • sessions → memory_entries (one-to-many, nullable FK): a memory entry can optionally reference the session it was captured in (ON DELETE SET NULL — deleting the session keeps the memory, just detaches it).
  • sessions → tool_executions (one-to-many): audit log of every tool call within a session, ON DELETE CASCADE.
  • personas: standalone; not yet linked by foreign key to agents or sessions in this schema version.

Source of truth

Every fact on this page traces back to one file: packages/db/src/schema.ts. If you need to verify a column name, type, or constraint, read that file directly rather than trusting a generated diagram — schemas drift, and this file is regenerated whenever the Drizzle schema changes.

// packages/db/src/schema.ts (imports)
import {
  pgTable, uuid, varchar, text, jsonb, timestamp, integer, primaryKey,
} from 'drizzle-orm/pg-core';
Edit on GitHub

Last updated on

On this page