How debjoy26/ragbot-widget works
ragbot_widget provides a branded website RAG widget, a visitor-facing API, and a background ingestion worker sharing Supabase. The main workflow runs from an embedded visitor through session/authentication and chat handling to retrieval and an AI response; separately, document-indexing jobs extract, chunk, embed, and store content for retrieval. The graph preserves the documented chat, history, moderation, caching, handoff, and ingestion capabilities. Several route and service implementations were not sampled, so their internal call relationships are omitted rather than inferred.
Main entry points: index-document.ts Document indexing · chat.ts Chat orchestration · widget.ts Widget runtime · app.ts API assembly
Components 28
Visitor widget
- Widget runtime
widget/src/widget.ts - Chat interface
widget/src/ui.ts - Contact card
widget/src/contact-card.ts - Visitor session
widget/src/session.ts - API client
widget/src/api.ts
Visitor API
- API assembly
api/src/app.ts - HTTP server
api/src/server.ts - Session routes
api/src/routes/sessions.ts - Chat routes
api/src/routes/chat.ts - Conversation routes
api/src/routes/conversations.ts - Visitor authentication
api/src/services/auth.ts - Rate and budget limits
api/src/services/limits.ts - Chat orchestration
api/src/services/chat.ts - Knowledge retrieval
api/src/services/retrieval.ts - LLM orchestration
api/src/services/llm.ts - Content moderation
api/src/services/moderation.ts - Chat and retrieval caches
api/src/services/answer-cache.ts
AI and shared contracts
- AI provider adapters
shared/src/providers.ts
Ingestion worker
- Worker process
worker/src/worker.ts - Job runtime
worker/src/runtime.ts - Job handlers
worker/src/handlers.ts - Document indexing
worker/src/jobs/index-document.ts - Text extraction
worker/src/lib/extract.ts - Document chunking
worker/src/lib/chunk.ts - Document storage client
worker/src/lib/storage.ts
Shared data
- Supabase database and storage
Other components
- Website visitor
- AI provider services
Connections 31
- Website visitor → Widget runtime: opens widget
README.md - Widget runtime → Chat interface: renders interface
widget/src/widget.ts - Chat interface → Contact card: renders card
widget/src/ui.ts - Widget runtime → Visitor session: uses session
widget/src/widget.ts - Widget runtime → API client: calls API
widget/src/widget.ts - API client → API assembly: sends requests
README.md - API assembly → HTTP server: builds server
api/src/app.ts - API assembly → Chat routes: registers routes
api/src/app.ts - API assembly → Conversation routes: registers routes
api/src/app.ts - HTTP server → Session routes: registers routes
api/src/server.ts - Session routes → Visitor authentication: uses authentication
api/src/routes/sessions.ts - Session routes → Rate and budget limits: checks limits
api/src/routes/sessions.ts - Chat routes → Chat orchestration: dispatches chat
- Conversation routes → Chat orchestration: loads conversations
- Chat orchestration → Knowledge retrieval: retrieves context
- Chat orchestration → LLM orchestration: generates answer
- Chat orchestration → Content moderation: moderates content
- Chat orchestration → Chat and retrieval caches: uses caches
- LLM orchestration → AI provider services: calls providers
- Visitor authentication → Supabase database and storage: checks sessions
api/src/services/auth.ts - Knowledge retrieval → Supabase database and storage: queries knowledge
api/src/services/retrieval.ts - Worker process → Job runtime: starts runtime
worker/src/worker.ts - Worker process → Job handlers: builds handlers
worker/src/worker.ts - Job handlers → Document indexing: registers handler
worker/src/handlers.ts - Job runtime → Supabase database and storage: claims jobs
worker/src/runtime.ts - Document indexing → Text extraction: extracts text
worker/src/jobs/index-document.ts - Document indexing → Document chunking: chunks document
worker/src/jobs/index-document.ts - Document indexing → Document storage client: reads source files
worker/src/jobs/index-document.ts - Document indexing → Supabase database and storage: writes index
worker/src/jobs/index-document.ts - Document storage client → Supabase database and storage: accesses objects
worker/src/lib/storage.ts - Document indexing → AI provider services: embeds chunks