ElectricCodeGuy/SupabaseAuthWithSSR

Supabase Auth + AI Stack for Next.js 16 with SSR and React Server Components (RSC), Welcome to a production-ready template combining Supabase SSR authentication with AI capabilities: document chat (RAG), web search, and multiple LLM support. Features include secure file storage, vector search (pgvector), and persistent chat history.

What it solves

This project provides a production-ready starter kit for building AI chat applications using Next.js and Supabase. It moves beyond simple text streaming by integrating a full authentication system, document-based RAG, long-term memory, and detailed token usage tracking, reducing the boilerplate required to ship a professional AI agent interface.

How it works

The application uses the Vercel AI SDK v7 and Anthropic's Claude models. It employs a two-tier prompt caching strategy to reduce input costs and implements a tool-calling architecture where the AI can autonomously trigger server-side functions. These tools are integrated with various services: Exa for web search, Voyage AI for embeddings, and Mistral for PDF OCR. Data is persisted in Supabase, utilizing pgvector for hybrid vector and keyword search (RRF fusion) over uploaded documents.

Who it’s for

Developers looking to build a sophisticated AI chat platform with user accounts, file management, and cost monitoring without starting from scratch.

Highlights

  • Comprehensive AI Tool Suite: Includes document RAG, web search, a versioned artifacts workspace for live document editing, interactive charts, and PDF generation.
  • Production Auth: Full Supabase SSR authentication including magic links, password resets, and Row Level Security (RLS) on all database tables.
  • Granular Usage Tracking: Per-step token usage and cache metadata are stored on messages, powering detailed user and admin cost dashboards.
  • Long-term Memory: A persistent memory system that allows the assistant to remember user facts across different chat sessions.
  • Detailed Vector Tuning: Includes an idempotent SQL setup with an HNSW index for sub-second similarity search and guidance on optimizing index size via halfvec.

Related

  • Project
  • Project
  • Project
  • Project
  • Project