How digibranders/oye-chats-platform works
Purpose and Entry Points
OyeChats is a multi-tenant SaaS platform for creating website-embedded, RAG-backed chatbots with live human handoff, lead qualification, and subscription billing. Its deployable surfaces are:
• FastAPI API, REST/SSE/WebSocket: api/app/main.py
• Embeddable widget loader and React application: widget/src/loader.js, widget/src/app-entry.jsx
• Authenticated customer/operator dashboard SPA: app/src/main.jsx, app/src/app/App.tsx
API Composition and Tenant Boundary
api/app/main.py wires middleware and root-mounted route modules. Route handlers establish request/auth/public-widget boundaries, then delegate business logic to services; persistence is centralized through SQLAlchemy models, repository, and sessions.
• Public conversational and widget configuration APIs: api/app/api/chat_routes.py, api/app/api/bot_routes.py
• Authenticated workspace/admin APIs: api/app/api/auth.py, api/app/api/client_routes.py
• Data boundary: api/app/db/models.py, api/app/db/repository.py, api/app/db/session.py
PostgreSQL plus pgvector is the durable system of record; migrations define evolving tenancy, bots, sessions, documents, subscriptions, invoices, credits, and operational state.
Knowledge Acquisition and RAG
Knowledge enters through uploads or crawls, then moves through extraction, cleaning, chunking, embedding, optional enrichment, and durable indexing. Crawling is independently orchestrated and can discover URLs, track progress/state, and recrawl.
• Pipeline stages: api/app/ingestion/pipeline.py, api/app/ingestion/extraction.py, api/app/ingestion/embedder.py
• Crawl boundary: api/app/services/crawl_orchestrator.py, api/app/services/crawler_service.py
• Retrieval/answer context: api/app/services/rag_service.py, api/app/services/reranker.py, api/app/services/relevance_gate.py
The runtime uses OpenAI embeddings and pgvector/vector-plus-keyword retrieval, with guards around relevance, grounding, quotas, and tenant isolation.
Visitor Chat and Live Handoff
The widget loads from a single host-page script, mounts an isolated root, lazy-loads its UI, and calls the API using its bot key. Chat routes stream AI replies over SSE; live-chat traffic uses WebSockets and shared coordination/backplane services.
• Embed/bootstrap and UI state: widget/src/loader.js, widget/src/widget-controller.js, widget/src/lib/chatModeMachine.js
• Chat execution: api/app/api/chat_routes.py, api/app/services/llm_service.py, api/app/services/session_state_machine.py
• Operator handoff: api/app/api/ws_routes.py, api/app/services/live_chat_service.py, api/app/services/live_chat_routing_service.py
LLM invocation is mediated by LiteLLM with OpenAI primary and Gemini fallback. Conversation outcomes feed lead, qualification, feedback, and analytics services.
Dashboard and Operator Workflows
The React dashboard is the control plane for workspace users: agent setup, knowledge/crawl management, bot experience/channel configuration, operator inbox, leads, analytics, and billing. Route protection and shared contexts carry identity, selected bot, workspace, entitlements, notifications, and crawl status.
• Application routing/security shell: app/src/app/routes.tsx, app/src/app/ProtectedLayout.tsx
• Agent configuration and knowledge workflows: app/src/features/agents/AgentLayout.tsx, app/src/features/agents/knowledge/KnowledgePage.tsx
• Operator console: app/src/features/inbox/InboxPage.tsx, app/src/features/inbox/useOperatorSocket.ts
Billing, Credits, and External Events
Plans and entitlements gate feature access and consumption. A FIFO credit ledger supports ingestion/chat usage and top-ups; subscriptions, invoices, promotions, and dunning are managed server-side. Inbound payment webhooks are verified and made idempotent before state mutation.
• Billing APIs and webhooks: api/app/api/subscription_routes.py, api/app/api/webhook_billing_routes.py
• Core domain services: api/app/services/plan_entitlements_service.py, api/app/services/credit_service.py, api/app/services/razorpay_service.py
• Dashboard billing workflows: app/src/features/workspace/BillingPage.tsx, app/src/features/workspace/billing/usePlanCheckout.ts
Razorpay is the primary INR rail, Stripe is fallback; Brevo handles transactional mail, and Cloudflare R2 stores uploaded/media assets.
Runtime, Async Work, and Deployment
FastAPI serves request paths while Redis supports ARQ jobs, cache, rate limits, and cross-process live-chat coordination. Long-running ingestion, crawl, email, invoice, reconciliation, and scheduled work are dispatched through the worker abstraction.
• Async execution: api/app/worker/tasks.py, api/app/worker/enqueue.py
• Production process topology: api/systemd/oyechats-api.service, api/systemd/oyechats-worker.service, api/systemd/oyechats-ws.service
• Edge/deploy configuration: api/nginx/oyechats-api.conf, .github/workflows/deploy-api.yml, .github/workflows/deploy-widget.yml
Production targets a DigitalOcean host behind Nginx/Cloudflare; Sentry and Langfuse provide observability, with Langfuse configurable/disabled for resource limits.
Main entry points: models.py PostgreSQL + pgvector · llm_service.py Chat execution · tasks.py ARQ workers · client_routes.py Workspace APIs
Components 20
Customer surfaces
- Dashboard SPA · Workspace configuration, inbox, analytics, and billing.
app/src/main.jsx - Protected dashboard shell
app/src/app/routes.tsx - Embed widget · Host-page bootstrap uses the public bot key.
widget/src/loader.js - Widget chat state
widget/src/lib/chatModeMachine.js
API runtime
- FastAPI application · Root-mounted routes and request middleware establish API boundaries.
api/app/main.py - Public chat APIs
api/app/api/chat_routes.py - Workspace APIs
api/app/api/client_routes.py - Chat execution · Applies session state, grounding, quotas, and tenant isolation.
api/app/services/llm_service.py - RAG retrieval · Combines vector and keyword search before answer generation.
api/app/services/rag_service.py - Live chat handoff
api/app/services/live_chat_routing_service.py - Billing and credits · Plans and FIFO credits gate feature access and consumption.
api/app/services/credit_service.py - Payment webhooks · Idempotently mutates subscription and invoice state.
api/app/api/webhook_billing_routes.py
Async processing
- Knowledge pipeline · Processes uploaded and crawled content into tenant knowledge.
api/app/ingestion/pipeline.py - Crawl orchestration
api/app/services/crawl_orchestrator.py - ARQ workers · Runs ingestion, crawl, mail, invoice, reconciliation, and scheduled work.
api/app/worker/tasks.py
Data and external systems
- PostgreSQL + pgvector · System of record for tenants, bots, conversations, knowledge, and billing.
api/app/db/models.py - Redis · Supports ARQ, rate limits, cache, and live-chat coordination.
- LLM providers · OpenAI is primary with Gemini fallback.
- Payment providers · Razorpay is primary INR rail; Stripe is fallback.
- Cloudflare R2
Connections 26
- Dashboard SPA → Protected dashboard shell: boots through
- Protected dashboard shell → Workspace APIs: authenticated requests
- Dashboard SPA → Live chat handoff: operator socket
- Embed widget → Widget chat state: drives UI modes
- Embed widget → Public chat APIs: bot-key requests
- Widget chat state → Live chat handoff: handoff traffic
- FastAPI application → Public chat APIs: mounts
- FastAPI application → Workspace APIs: mounts
- Public chat APIs → Chat execution: streams replies
- Chat execution → RAG retrieval: retrieves context
- Chat execution → LLM providers: invokes
- Chat execution → PostgreSQL + pgvector: persists sessions
- RAG retrieval → PostgreSQL + pgvector: vector and keyword search
- Workspace APIs → ARQ workers: dispatches long work
- ARQ workers → Knowledge pipeline: runs
- ARQ workers → Crawl orchestration: runs
- Knowledge pipeline → Cloudflare R2: reads uploads
- Knowledge pipeline → PostgreSQL + pgvector: indexes embeddings
- Crawl orchestration → Knowledge pipeline: supplies pages
- Live chat handoff → Redis: cross-process coordination
- Live chat handoff → PostgreSQL + pgvector: stores routing state
- Workspace APIs → Billing and credits: plans and usage
- Payment webhooks → Billing and credits: verified events
- Payment webhooks → Payment providers: receives events
- Billing and credits → PostgreSQL + pgvector: ledger and subscriptions
- ARQ workers → Redis: ARQ queue