How work4ai/rebuff works
Project Type and Purpose
• This is a monorepo for Rebuff.ai, a self-hardening prompt-injection detector.
• It provides two SDKs (JavaScript/TypeScript and Python) for client-side integration and a Next.js-based server offering a playground UI, API endpoints, and orchestration of detection logic.
• Key functionality: multi-layered defense (heuristics, LLM-based detection, VectorDB signature matching, canary tokens), user/account management, billing, and logging.
File Structure Analysis
• Top-level directories:
• javascript-sdk – client library with modules for tactics (Heuristic, OpenAI, Vector), API/config, SDK entrypoint, tests, build config.
• python-sdk – analogous client library in Python with rebuff package, detection implementations, SDK class, examples, tests.
• server – Next.js application containing:
– pages/api/** – serverless routes (detect, log, account management, playground docs).
– components/** – React UI for the playground, stats, login, etc.
– lib/** – business logic (openai wrapper, Pinecone/Supabase clients, detect helpers, billing, schema).
– sql_setup/** – Supabase/PostgreSQL tables and functions for accounts, attempts, leakage logs, rate/billing.
– config files (next.config.js, netlify.toml, env, styles).
• Root contains docs, GitHub workflows (CI/CD for building/testing/publishing SDKs), a PlantUML sequence (detection.puml), Makefile.
README Insights
• Emphasizes a four-layer defense pipeline invoked by SDKs or via direct API calls to the Next.js server.
Diagramming Conventions
• From SDK to /api/detect endpoint (label: “POST user prompt”)
• From Server to OpenAI API (label: “LLM analysis request/response”)
• From Server to Pinecone (label: “Vector query/store”)
• From Server to Supabase (label: “SQL function calls: log, billing, stats”)
• Blue for client-side (SDKs, UI)
• Green for server/runtime (API routes, orchestrator)
• Orange for data stores (Supabase, Pinecone)
• Gray for external services (OpenAI)