Chatbot RAG Multi-Tenant

Chatbot RAG Multi-Tenant An architecture diagram generated by Archify. Admin User · Dashboard · Architecture component Admin User Dashboard Site Visitors · Client Sites · Architecture component Site Visitors Client Sites Next.js Dashboard · TypeScript :3000 · Architecture component · Hexagonal Next.js Dashboard TypeScript :3000 Hexagonal Embeddable Widget · Shadow DOM + JS · Architecture component · API Key Auth Embeddable Widget Shadow DOM + JS API Key Auth Supabase Auth · JWT · Supabase Platform Supabase Auth JWT Supabase Storage · Document files · Supabase Platform Supabase Storage Document files chat · Deno · Supabase Platform · Edge Function chat Deno Edge Function Supabase Postgres · pgvector + RLS · Supabase Platform · Multi-tenant Supabase Postgres pgvector + RLS Multi-tenant process · Chunking · Supabase Platform · Edge Function process Chunking Edge Function embed · gte-small · Supabase Platform · Edge Function embed gte-small Edge Function OpenAI API · Chat completions · Architecture component OpenAI API Chat completions Supabase Platform Legend Frontend Backend Database Cloud Security External

Multi-tenant Architecture

  • • Projects table isolates tenant data
  • • RLS policies enforce project_id filtering
  • • API keys scoped per project with allowed_origins

RAG Pipeline

  • • Document upload triggers chunking by headings
  • • gte-small embeddings via Supabase.ai.Session
  • • pgvector cosine similarity search
  • • OpenAI completions with context

Security

  • • Dashboard: Supabase Auth + JWT
  • • Widget: Public API key + Origin header validation
  • • RLS on all multi-tenant tables

Hexagonal Architecture

  • • Domain ports abstract Supabase dependencies
  • • Infrastructure adapters implement ports
  • • Composition roots inject per-request dependencies