The database isn’t just there for auth. It stores chats, generations, purchases, credits, recordings, documents, embeddings, and more. It’s the backbone of every app in the repo.
The Mental Model
Here’s how to think about the data layer:- Better Auth owns the auth tables and browser session flow
- PostgreSQL + Drizzle own the application data layer
- Supabase PostgreSQL is the recommended managed host
Schema Workflow
Table Families
Auth & Profiles
Auth & Profiles
Schema files:
lib/db/schema/auth.ts, lib/db/schema/profiles.tsHandles:- Better Auth users, sessions, accounts, and verifications
- User profile data
- Credit tracking
- Connecting app-owned records to the authenticated user ID
Generations
Generations
Schema file:
lib/db/schema/generations.tsHandles:- Outputs from AI apps (images, videos, audio, structured data)
- Input/output payloads
- Reusable generation history across multiple apps
Chat
Chat
Schema file:
lib/db/schema/chat.tsHandles:- Chat conversations
- Messages within conversations
- Chat document versioning
PDF & RAG
PDF & RAG
Schema file:
lib/db/schema/pdf.tsHandles:- Uploaded PDFs
- Embeddings (via
pgvector) - Document-to-chat links
- Similarity search functions
Audio Notes
Audio Notes
Schema file:
lib/db/schema/audio.tsHandles:- Recordings
- Transcripts
- AI-generated summaries
Purchases
Purchases
Schema file:
lib/db/schema/purchases.tsHandles:- Purchase records
- Provider metadata
- Credit packs and plan purchases
Important Database Behaviors
Ownership Checks
Most user-owned data access is enforced through authenticated server helpers plus user-scoped queries inside thelib/db/* modules. Records are filtered or updated by the current user ID — not by database-vendor-specific auth helpers.
Credits
Credit logic isn’t just a frontend number. The repo uses transactional update queries and ownership checks in the database layer to keep credit changes safe.Vector Search
The PDF system usespgvector plus retrieval functions so the chat app can do document-aware answers with citations. The extension setup and retrieval function live in focused custom Drizzle migrations.
Important details about
pgvector:- It’s enabled at the database level, not per-table
- Once the extension exists, any table can define
vector(...)columns - Your database host still needs to support the extension
Good First Files to Read
lib/db/schema/auth.tslib/db/schema/profiles.tslib/db/schema/generations.tslib/db/schema/chat.tslib/db/schema/pdf.tslib/db/schema/audio.tslib/db/schema/purchases.tsdrizzle/0000_better_auth_baseline.sqldrizzle/0001_rag_functions.sql
When customizing the product, understanding these table families helps you avoid a common mistake: bolting new features onto random existing tables instead of working with the repo’s actual data model.
Better Auth + PostgreSQL
Learn how auth and persistence fit together in the default setup.
Vector RAG
Learn how embeddings and retrieval use the database.

