Skip to content

About

Multi-tenant AI document generation platform with RAG retrieval, PII redaction, and Supabase RLS

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Built to solve AI document generation without per-seat SaaS lock-in or sending sensitive data to third-party processors.

AI Document Generation Platform — AI Docs SaaS

The Problem

Agencies and professionals generate narrative reports using either manual writing (slow, inconsistent) or expensive AI writing tools that lack document-specific context, store prompts on third-party servers, and don't support structured exports like DOCX/PDF with custom branding.

The Solution

AI Docs SaaS is a multi-tenant platform that combines RAG-based document retrieval with OpenAI generation, PII redaction, and direct DOCX/PDF export — all within a Supabase-backed architecture with row-level security. Upload source documents, set a report goal, and get a professionally formatted export in minutes.

Live Demo

📹 Demo: [Insert 30-second screen recording showing: upload PDF → AI generates report → export to DOCX]

🔗 Deployed on Vercel (live for several months)

Key Metrics & Impact

  • RAG accuracy: OpenAI embeddings + pgvector search retrieve relevant context across uploaded documents in under 200ms
  • Multi-tenant isolation: Supabase row-level security enforces per-agency data boundaries at the database level — zero risk of cross-tenant leakage
  • PII redaction: Automated detection pipeline scrubs sensitive information before AI processing
  • Export pipeline: DOCX and PDF generation with custom header/footer branding — production-ready formatting
  • Rate limiting: Upstash Redis-backed rate limiter on AI endpoints prevents abuse
  • Dashboard analytics: 7-day KPIs tracking reports generated, tokens consumed, average generation time, and success rate
  • Token tracking: Per-run usage logging for cost attribution per tenant

Technical Architecture

Layer Technology
Frontend Next.js 15 (App Router), Tailwind CSS, TypeScript
Backend Next.js API routes, Supabase Auth
Database PostgreSQL (Supabase) with pgvector
AI/ML OpenAI GPT-4o-mini, OpenAI Embeddings
Vector Store pgvector (PostgreSQL extension)
Cache/Rate Limit Upstash Redis
Document Processing pdf-parse, mammoth, Puppeteer
Export docx (DOCX), Puppeteer (PDF)
PII Detection Custom NLP pipeline with regex + ML patterns
Auth Supabase Auth (email/password, magic link)

How It Works

Upload Documents (PDF/DOCX/TXT)
        │
        ▼
  PII Redaction ──→ Detect and remove sensitive data
        │
        ▼
  Embedding ──→ OpenAI embeddings → pgvector
        │
        ▼
  User sets report goal
        │
        ▼
  RAG Retrieval ──→ Semantic search across tenant documents
        │
        ▼
  AI Generation ──→ GPT-4o-mini with context
        │
        ▼
  Review & Revise ──→ Interactive refinement
        │
        ▼
  Export ──→ DOCX or PDF with custom branding

Local Setup

# 1. Install dependencies
pnpm install

# 2. Configure environment
cp .env.local.example .env.local
# Fill in Supabase URL/keys and OpenAI API key

# 3. Run database migrations
# Run SQL files from sql/ directory in Supabase dashboard

# 4. Start development server
pnpm dev

Configuration

Required environment variables: NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY, OPENAI_API_KEY. See ENVIRONMENT.md and AUTH_SETUP.md for full setup guide.

License

MIT — see LICENSE

About

Multi-tenant AI document generation platform with RAG retrieval, PII redaction, and Supabase RLS

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages