How samuraigpt/ai-knowledge-base works
KnowBase AI is a self-hosted knowledge-base and RAG chatbot SaaS. Users authenticate, create knowledge bases, add document or Q&A sources, and chat with citations; credit purchases fund training and queries. The graph preserves documented widget/API, URL-ingestion, and billing capabilities, but the sampled source does not expose the full chat or ingestion implementation, so those links are documented rather than inferred from module names.
Main entry points: page.js Studio workspace · prisma.js Prisma client · billing.js Billing service · route.js Chat and citations
Components 23
Workspace experience
- Studio workspace
src/app/page.js - Knowledge gallery
src/app/gallery/page.js - Pricing page
src/app/pricing/page.js - Account navigation
src/components/Navbar.js - Sign-in page
src/app/login/page.js
Knowledge and chat
- Knowledge-base API
src/app/api/kb/route.js - Source training API
src/app/api/kb/[id]/sources/route.js - Chat sessions API
src/app/api/kb/[id]/chat/route.js - Chat and citations
src/app/api/kb/[id]/chat/[chatId]/messages/route.js - RAG and AI engine
- Embed widget and API
src/app
Identity and account
- Auth endpoint
src/app/api/auth/[...nextauth]/route.js - Session and providers
src/lib/auth.js - Custom API key
src/app/api/user/apikey/route.js
Credits and billing
- Checkout endpoints
src/app/api/stripe/checkout/route.js - Stripe webhook
src/app/api/stripe/webhook/route.js - Billing service
src/lib/services/billing.js
Persistence and services
- Credit service
src/lib/services/user.js - Prisma client
src/lib/prisma.js - PostgreSQL data
prisma/schema.prisma - Product configuration
src/lib/config.js
Other components
- Workspace user
- Stripe
Connections 26
- Workspace user → Studio workspace: uses
README.md - Workspace user → Knowledge gallery: browses
README.md - Workspace user → Pricing page: buys credits
README.md - Workspace user → Sign-in page: signs in
README.md - Account navigation → Custom API key: saves key
src/components/Navbar.js - Studio workspace → Knowledge-base API: manages bases
README.md - Studio workspace → Source training API: trains sources
README.md - Studio workspace → Chat sessions API: opens chats
README.md - Studio workspace → Chat and citations: sends queries
README.md - Chat and citations → RAG and AI engine: retrieves and generates
- RAG and AI engine → Chat and citations: returns citations
README.md - Studio workspace → Embed widget and API: exports embeds
README.md - Auth endpoint → Session and providers: loads options
src/app/api/auth/[...nextauth]/route.js - Knowledge-base API → Session and providers: checks session
src/app/api/kb/route.js - Knowledge-base API → Prisma client: reads and writes
src/app/api/kb/route.js - Source training API → Prisma client: reads and writes
src/app/api/kb/[id]/sources/route.js - Source training API → Credit service: deducts credits
src/app/api/kb/[id]/sources/route.js - Chat and citations → Prisma client: loads chat data
src/app/api/kb/[id]/chat/[chatId]/messages/route.js - Checkout endpoints → Billing service: creates session
src/app/api/stripe/checkout/route.js - Stripe webhook → Billing service: handles event
src/app/api/stripe/webhook/route.js - Billing service → Stripe: creates checkout
src/lib/services/billing.js - Billing service → Credit service: adds credits
src/lib/services/billing.js - Credit service → Prisma client: updates balances
src/lib/services/user.js - Session and providers → Prisma client: uses adapter
src/lib/auth.js - Prisma client → PostgreSQL data: persists records
- Billing service → Product configuration: reads plans
src/lib/services/billing.js