SupaChat. The AI chat starter for Next.js and Supabase.
A production-ready base for AI chat applications: authentication, document search, tools and cost tracking, wired together and set up with a single SQL file. It is built on the same architecture as Lovguiden, without the Danish legal data.
- 397
- GitHub stars
- 60
- forks
- MIT
- license
Authentication done properly
Supabase SSR auth with sign-up, sign-in, magic links and password reset. Row-level security on every table, column-level grants, and no keys in the browser.
Chat with documents
Uploaded PDFs are read with Mistral OCR, embedded with Voyage and searched with hybrid pgvector and full-text search, merged by reciprocal rank fusion.
Claude with tools
Eight tools the model calls on its own: document search, web search, memory, conversation search, visualisations, PDFs, artifacts and image generation.
Prompt caching
A two-tier Anthropic cache keeps multi-step tool turns at around a tenth of the normal input price.
Local models
An OpenAI-compatible vLLM provider runs open models on own hardware next to Claude.
Usage and cost
Token usage stored per step and rolled up into user and admin dashboards with cache-aware cost estimates.
- 01
Upload
PDF into a private Supabase bucket
- 02
OCR
Text and structure with Mistral OCR
- 03
Embed
Voyage embeddings into pgvector
- 04
Search
HNSW vector and full-text, fused with RRF
- 05
Answer
Claude answers and cites the pages
- 01Clone the repository.
- 02Run database/setup.sql in the Supabase SQL editor. It is idempotent and doubles as the upgrade path.
- 03Create a private storage bucket named userfiles.
- 04Add the API keys to .env.local and start the dev server.
SupaChat was released in October 2023, a month before work on Lovguiden began, and the two share the same architecture. SupaChat is the open, general-purpose part: accounts, chat, tools and document search. Lovguiden adds the Danish legal database, the automated collection from 2,000+ public sources and the MCP server.
Read the Lovguiden case studyThe same foundation, built on company data.
AI assistants over internal documents, contracts or case files, with sources on every answer, can be built on this base and run in the cloud or on own infrastructure.