How narender-rk10/openbi works
Purpose and Entry Points
OpenBI is a self-hosted AI business-intelligence platform: connect live data sources, define MindsDB-backed agents, query via chat, build dashboards, and distribute reports. The FastAPI process starts at backend/main.py; domain routers are assembled from backend/api/. The React SPA starts at frontend/src/main.tsx and routes from frontend/src/App.tsx. Docker topology is defined in docker-compose.yml.
Application Boundary, Identity, and Persistence
The backend owns tenancy, application state, and authorization; MongoDB is the system of record, accessed asynchronously through backend/core/database.py. JWT authentication, bcrypt password verification, and Fernet encryption for stored connection/LLM credentials are centralized in backend/core/security.py; API dependency enforcement is in backend/api/deps.py. Domain APIs persist projects, connections, agents, chats, dashboards, schedules, exports, and settings in MongoDB, while MindsDB holds executable agent/KB constructs.
Data Connectivity and AI Agent Layer
Connection management translates UI-provided source settings into encrypted MongoDB records and MindsDB database handlers through backend/api/connections.py and backend/services/mindsdb_client.py. Agent creation binds selected tables/connections and optional knowledge bases into MindsDB multi-skill agents via backend/api/agents.py. MindsDB is therefore the boundary to 90+ source handlers, text-to-SQL execution, and RAG retrieval; the OpenBI backend does not directly query customer databases.
Chat Execution Pipeline
frontend/src/hooks/useChat.ts consumes the primary SSE interaction exposed by backend/api/chat.py. Requests can target mentioned agents, use an active agent, or invoke LLM-based routing. The backend restores bounded conversation history from MongoDB, handles greetings locally, streams MindsDB agent output, extracts generated SQL, re-executes it for structured rows, and emits status/SQL/data/answer events. backend/services/llm_client.py abstracts Gemini, OpenAI, and Anthropic for routing and synthesis; optional tracing flows through backend/services/langfuse_client.py.
Dashboard Authoring and Real-Time State
Dashboards store widget SQL, display configuration, cached result data, filters, and versions as application documents behind backend/api/dashboards.py and backend/services/version_service.py. Widgets execute through MindsDB; AI-generated visual/table configurations are produced by backend/services/chart_agent.py and backend/services/table_agent.py. The primary interactive surface is frontend/src/pages/DashboardViewPage.tsx, rendering chart/table/KPI/narrative widgets from frontend/src/components/dashboard/. WebSocket coordination is handled by backend/api/ws.py and backend/services/websocket_manager.py, with Redis pub/sub as the multi-viewer broadcast boundary.
Knowledge Bases and Exports
Knowledge-base APIs in backend/api/knowledge_bases.py ingest uploads or crawled content, prepare supported files, and delegate chunking, embeddings, and vector storage to MindsDB. PDF history/export behavior is represented by backend/services/pdf_service.py; PPTX generation delegates asynchronously to the separate Presenton service through backend/services/pptx_service.py. PDF capture is client-side from dashboard UI, while persisted export/version metadata remains in MongoDB.
Automation and Deployment Services
Schedules are persisted and registered in the in-process APScheduler flow in backend/services/scheduler_service.py; execution refreshes dashboard data and dispatches email, Telegram, or webhook deliveries through backend/services/report_runner.py and backend/services/delivery_service.py. The optional bot is an independent process at telegram_bot/bot.py. Material runtime services are FastAPI/Python 3.11, React/TypeScript, MindsDB, Redis, external MongoDB, optional Presenton, SMTP, Telegram, and Langfuse, containerized by docker-compose.yml.
Main entry points: main.py API application · database.py Application persistence · chat.py Chat pipeline · dashboards.py Dashboards API
Components 22
React SPA
- SPA entry
frontend/src/main.tsx - App routes
frontend/src/App.tsx - Chat client · Consumes streamed chat events.
frontend/src/hooks/useChat.ts - Dashboard view · Renders dashboard widgets and captures PDFs client-side.
frontend/src/pages/DashboardViewPage.tsx
FastAPI backend
- API application · Assembles domain routers.
backend/main.py - Identity and access · Dependencies enforce authorization; credentials are encrypted.
backend/api/deps.py - Security services · JWT, bcrypt, and Fernet credential encryption.
backend/core/security.py - Application persistence · Stores tenancy, state, metadata, and histories.
backend/core/database.py - Connections API · Persists encrypted source settings and provisions handlers.
backend/api/connections.py - Agents API · Creates multi-skill agents from connections, tables, and KBs.
backend/api/agents.py - Chat pipeline · Restores history, routes requests, streams answers, and re-executes generated SQL.
backend/api/chat.py - Dashboards API · Stores widget SQL, configurations, cached data, filters, and versions.
backend/api/dashboards.py - Realtime coordination · Coordinates multi-viewer dashboard updates.
backend/api/ws.py - Report scheduler · Registers persisted schedules and refreshes dashboards.
backend/services/scheduler_service.py - Report delivery · Dispatches email, Telegram, and webhook reports.
backend/services/delivery_service.py
AI and data boundary
- MindsDB client · Backend boundary for handlers, agents, SQL execution, and knowledge bases.
backend/services/mindsdb_client.py - LLM abstraction · Uses Gemini, OpenAI, or Anthropic for routing and synthesis.
backend/services/llm_client.py - MindsDB · Owns source handlers, text-to-SQL, RAG, embeddings, and vectors.
Runtime services
- MongoDB · External application database.
- Redis pub/sub · Multi-viewer realtime broadcast boundary.
- Delivery channels
- Container topology · Defines the material runtime services.
docker-compose.yml
Connections 31
- SPA entry → App routes: mounts
- App routes → Chat client: chat UI
- App routes → Dashboard view: dashboard UI
- Chat client → Chat pipeline: SSE chat
- Dashboard view → Dashboards API: author and load
- Dashboard view → Realtime coordination: WebSocket updates
- API application → Identity and access: applies dependencies
- Identity and access → Security services: validates tokens
- API application → Connections API: routes
- API application → Agents API: routes
- API application → Chat pipeline: routes
- API application → Dashboards API: routes
- Connections API → Application persistence: stores settings
- Agents API → Application persistence: stores metadata
- Chat pipeline → Application persistence: loads history
- Dashboards API → Application persistence: stores dashboards
- Application persistence → MongoDB: async persistence
- Connections API → MindsDB client: provisions handlers
- Agents API → MindsDB client: creates agents
- Chat pipeline → LLM abstraction: routing and synthesis
- Chat pipeline → MindsDB client: streams agent and SQL results
- Dashboards API → MindsDB client: executes widgets
- MindsDB client → MindsDB: API boundary
- Realtime coordination → Redis pub/sub: publishes updates
- Report scheduler → Application persistence: loads schedules
- Report scheduler → Dashboards API: refreshes dashboard data
- Report scheduler → Report delivery: runs reports
- Report delivery → Delivery channels: dispatches
- Container topology → API application: runs
- Container topology → MindsDB: runs
- Container topology → Redis pub/sub: runs