Loading repository data…
Loading repository data…
ElectricCodeGuy / repository
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.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
Claude-powered chat with document RAG, a versioned artifacts workspace, long-term memory, interactive charts, PDF generation and per-token cost dashboards — on top of a complete Supabase SSR authentication system. Clone it, run one SQL file, ship.
Quickstart · Tour · Tool Suite · Architecture · Database Setup · Changelog
One prompt → two web searches → a document written into the artifacts workspace, then revised to version 2. Every step cached, persisted and cost-tracked.
https://github.com/user-attachments/assets/e9fa6007-6c68-4ce1-9c9c-7f00b902e859
A real prompt running live — web search, charts, document search and more, in one turn.
Most chat templates stop at "streaming text in a box." This one is the full production stack — the same architecture that powers Lovguiden.dk, a Danish legal-AI platform running RAG over millions of documents:
| 🔐 Real auth, done right — Supabase SSR with signup, signin, magic links, password reset, email templates and RLS on every table. No client-side key exposure. | 🧠 Eight AI tools — document RAG, web search, artifacts, memory, conversation search, charts, PDFs. The AI decides when to use them; you get typed UI components for each. | 💰 Every token accounted for — per-step usage stored on the message itself, rolled up into user and admin dashboards with cache-aware cost estimates. |
| ⚡ Prompt caching that actually works — a two-tier Anthropic cache setup (static system + tools block, moving conversation breakpoint) serves multi-step tool turns at ~10% of normal input price. | 📄 Documents in, answers out — upload a PDF and it's OCR'd (Mistral), embedded (Voyage), and searchable via hybrid vector + keyword RRF search. Fully autonomous — no file pickers. | 🗄️ One SQL file — the entire schema (tables, RLS, triggers, storage policies, search functions, model seed) is a single idempotent setup.sql. Re-run it to upgrade. |
git clone https://github.com/ElectricCodeGuy/SupabaseAuthWithSSR.git
cd SupabaseAuthWithSSR
npm install
cp .env.local.example .env.local # fill in the keys below
npm run dev
database/setup.sql. That's the whole schema; it's safe to re-run.userfiles (Storage → Create Bucket). The RLS policies are already in setup.sql..env.local:| Variable | Service | Used for |
|---|---|---|
SUPABASE_URL / SUPABASE_ANON_KEY / SUPABASE_SERVICE_ROLE_KEY | Supabase | Auth, database, storage |
ANTHROPIC_API_KEY | Anthropic | Chat, chat titles, document metadata |
MISTRAL_API_KEY | Mistral | PDF OCR (mistral-ocr-latest) |
VOYAGE_API_KEY | Voyage | Document embeddings (voyage-4-large) |
EXA_API_KEY | Exa | Web search |
http://localhost:3000/signup with a real email and click the confirmation link./admin:UPDATE public.users SET is_admin = true WHERE email = 'you@example.com';
Upgrading an existing install? Just re-run database/setup.sql — it is idempotent (IF NOT EXISTS / CREATE OR REPLACE throughout), so it adds only what's new in v5: user_memories, users.is_admin, the message_parts.usage JSON column, chat_sessions.settings, the hybrid match_documents function, and the Anthropic model catalog (Sonnet 5, Opus 4.8, Fable 5 with official API pricing).
One prompt can fan out into web searches, document lookups, chart rendering, PDF creation and artifact writing — all in a single assistant turn (the hero screenshot above shows exactly that). Each tool call renders as its own card with expandable reasoning, and every step is persisted incrementally, so the full trace survives a reload. Chats title themselves (a fast Haiku call after the first exchange), and the model you pick is stored on the conversation, so each chat keeps its own model.
Ask for a document and it opens in a side panel next to the chat, streaming in live as the AI writes. Every create/update is automatically a version — with a version browser, copy, and Markdown download. There are no extra tables behind this: each version is the stored tool call. On desktop the panel pushes the chat aside; on mobile it's a slide-over.
The AI renders bar, line, area and pie charts with a colorblind-safe palette, tooltips, legends and a data-table fallback. Below, it researched SaaS churn benchmarks on the web, checked the user's documents for internal numbers, charted the spread — then wrote the same analysis into a polished PDF report and saved it to the user's files:
The createPDF tool renders style-templated documents (report/memo/letter/contract — cover page, table of contents, callouts, tables) with @react-pdf/renderer. The built-in file manager previews any PDF, and uploads are OCR'd, embedded and indexed for RAG automatically:
Long-term memory. Tell the assistant to remember something and it persists across all chats — injected into every system prompt. View, add, edit and delete memories in the AI settings modal.
Database-driven model selection. Models live in the ai_models table with pricing metadata — the picker shows a plain-language description and an approximate cost per answer. Ships with Sonnet 5 (default), Opus 4.8 and Fable 5.
Every generation step (each tool call is its own step) stores its token usage and cache metadata as JSON on the message itself. The /usage page turns that into range-filtered KPIs with period-over-period deltas, tokens per day, cache hit rate over time, and cost by model:
Because usage is attributed per step, spend breaks down by tool and by conversation — and any assistant message expands into its individual steps, each with its own model, tools, token counts and cache hit rate:
Users with is_admin = true get the organization view: org-wide totals and daily volume, top users by cost, cost by model, and a user management table (rename, grant/revoke admin) with per-user usage. Every mutation re-verifies the caller is an admin server-side before touching the service-role client:
Conversation management. Search, rename, favorite, share or delete any conversation — favorites pin to the sidebar, history groups by day.
A profile page with real data. Identity, role, default model, 30-day spend, memories and recent activity — one server round-trip.
Even signed-out visitors get a designed experience instead of a broken shell — locked nav items, a blurred preview of the chat rail behind a sign-in card, and honest CTAs:
Every tool follows the same pattern — a server-side definition in app/api/chat/tools/, registration in the chat route + tooltypes.ts (typed UI parts via InferUITools), and a dedicated React component that renders the call in the chat. Tool calls persist as message_parts rows, so the full trace (inputs, outputs, errors) survives a reload.
| Tool | What it does | Extra infra |
|---|---|---|
searchUserDocument | RAG over uploaded PDFs: list the newest documents, find one by name, read a page range or full content, or run a hybrid vector + keyword search (RRF fusion) | pgvector + Voyage embeddings |
websiteSearchTool | Exa web search — the AI's query goes straight to Exa (no intermediate LLM round-trip), returning full text plus query-relevant highlights | Exa API key |
saveMemory | Long-term memory: save / list / delete facts the user asks to remember; injected into every system prompt | user_memories table |
conversationSearch | Keyword search across all the user's past chats, with snippets and links | none (reuses chat tables) |
createChart | Interactive bar/line/area/pie charts rendered with Recharts from a Zod-validated spec | none |
createPDF | One-shot polished PDFs — templates, cover page, TOC, callouts, tables, images — uploaded to Storage and previewable in the file manager | @react-pdf/renderer + bundled Inter fonts |
createArtifact / updateArtifact | The document workspace: complete Markdown documents streamed live into a side panel, with version history | none (versions ARE the stored tool calls) |
How the artifacts panel works: the document content travels in the tool input, so the panel gets live typewriter streaming for free from the SDK's input-streaming states, and every create/update is automatically a persisted version. On desktop the panel is an in-flow flex sibling that pushes the chat aside (width animates 0 ↔ 45%); on mobile it's a slide-over. It auto-opens on new versions, remembers when you dismissed it, and lets you pin and browse older versions.
How the caching works: the system prompt is split into a static block (instructions + tool definitions) with an Anthropic cacheControl breakpoint, and a dynamic block (date, memories, artifact state) that stays out of the cache. Each generation step re-places a moving breakpoint on the last message, so in a 10-step tool turn, steps 2–10 read the whole conversatio