How muideen-ha-shem/get-kc works
Purpose and Runtime Entry Points
HavisIQ is a multi-tenant AI business-solutions advisor: it answers customer questions with cited RAG evidence, recommends products/services, and supports account, support, knowledge-management, and administration workflows. The primary API runtime is src/api/app.py; chat coordination centers on src/orchestrator/chat_orchestrator.py. The React/Vite client starts at frontend/src/main.tsx and composes routes/UI in frontend/src/App.tsx. A separate CLI path exists in src/chat_cli.py; MCP tooling is independently exposed from src/mcp/server.py.
API Boundary and Application Services
FastAPI routes form the HTTP boundary, validate schemas, resolve auth/workspace context, and delegate to services rather than embedding business logic. Chat, auth, workspace, knowledge, support, agent, and admin route groups live under src/api/routes/chat.py, src/api/routes/auth.py, and src/api/routes/knowledge_management.py. Shared request dependencies—including optional versus required identity—are centralized in src/api/deps.py.
Chat Orchestration and Grounded Answer Pipeline
ChatOrchestrator is the principal control-flow coordinator: it resolves session references, routes a question, assembles evidence, runs advisory behavior, generates an answer, validates citations, and returns a response. Core stages are represented by src/orchestrator/chat_orchestrator.py, src/services/session/session_service.py, and src/services/advisory/advisory_layer.py. The baseline RAG adapters for embeddings, vector retrieval, and LLM generation are src/api/services/embeddings.py, src/api/services/retrieval.py, and src/api/services/generator.py.
Multi-Source Retrieval Boundary
Retrieval can select internal knowledge, live web sources, or both. Routing and query preparation precede provider calls; fetched evidence is filtered/reranked/ranked, merged, and citation-cleaned before generation. This pipeline is grounded in src/services/routing/source_router.py, src/services/manager/search_manager.py, and src/services/merger/context_merger.py. Search providers are pluggable in src/services/search/providers/tavily.py and src/services/search/providers/brave.py; absent provider keys degrade to knowledge-base-only behavior. In-memory process-lifetime caches are a performance boundary rather than persistent state.
Tenant, Identity, and Persistence Model
Supabase supplies PostgreSQL/pgvector, Supabase Auth, and row-level-security-backed tenant/customer data. The infrastructure adapter is src/infrastructure/database/supabase.py; workspace isolation and resolution are defined in src/services/workspace/workspace_resolver.py and src/services/workspace/workspace_context.py. Authentication wraps Supabase tokens in src/services/auth/auth_service.py. Customer conversation persistence is deliberately best-effort behind chat and managed through src/services/conversation/conversation_service.py. Schema evolution, including workspaces, identity, escalation, and knowledge, is captured in scripts/sql/004_customer_identity.sql, scripts/sql/007_workspace_foundation.sql, and scripts/sql/012_knowledge_management.sql.
Operational Workflows Beyond Chat
Knowledge management manages collections, sources, uploads, crawling, ingestion, versioning, preview, quality, and scheduling through src/services/knowledge_management/ingestion_service.py, src/services/knowledge_management/crawl_service.py, and src/services/knowledge_management/collection_service.py. Human-support escalation selects/routes agents and creates operational context via src/services/escalation/escalation_service.py, src/services/escalation/routing.py, and src/services/agents/agent_service.py. Appointments, demo requests, feedback, saved items, and notifications are separate transactional workflows, with notification delivery deliberately centralized in src/services/notifications/notification_service.py.
Frontend and Embeddable Client Surfaces
The frontend is a React/TypeScript customer and operations portal. Its shared API/auth boundary is frontend/src/lib/apiClient.ts and frontend/src/lib/authContext.tsx; customer dashboard and knowledge UI are frontend/src/pages/DashboardPage.tsx and frontend/src/pages/knowledge/KnowledgeManagementPage.tsx; platform administration is rooted at frontend/src/pages/admin/AdminLayout.tsx. An independently buildable embedding/widget SDK exposes a client/widget surface from sdk/src/index.ts, sdk/src/client.ts, and sdk/src/widget.ts.
External Services and Offline Ingestion
Production dependencies are Groq for answer generation, Google Gemini for embeddings/reranking, Supabase for auth/database/vector search, and optionally Tavily or Brave for web search. Offline knowledge acquisition and vector loading are intentionally outside the API runtime: scripts/crawl.py, scripts/chunk_runner.py, and scripts/upload_vectors.py. Product-specific crawler scripts indicate knowledge is ingested per solution; deployment must apply schema migrations and execute ingestion before product-scoped retrieval data is available.
Main entry points: chat_orchestrator.py Chat orchestrator · supabase.py Supabase · chat.py Routes & identity deps · search_manager.py Search manager
Components 23
Client Surfaces
- React portal · Customer, knowledge, and administration workflows.
frontend/src/App.tsx - Portal API & auth
frontend/src/lib/apiClient.ts - Embed SDK
sdk/src/index.ts - Chat CLI
src/chat_cli.py
API Runtime
- FastAPI application
src/api/app.py - Routes & identity deps · Validates requests and resolves auth/workspace context.
src/api/routes/chat.py - Authentication service
src/services/auth/auth_service.py - MCP server
src/mcp/server.py
Grounded Chat
- Chat orchestrator · Coordinates routing, evidence, advisory behavior, answers, and citations.
src/orchestrator/chat_orchestrator.py - Session service
src/services/session/session_service.py - Advisory layer
src/services/advisory/advisory_layer.py - Source router · Selects internal knowledge, web, or both.
src/services/routing/source_router.py - Search manager · Fetches, filters, reranks, and ranks evidence.
src/services/manager/search_manager.py - Context merger · Merges and citation-cleans ranked context.
src/services/merger/context_merger.py - RAG generation adapters
src/api/services/generator.py
Tenant Data & Retrieval
- Workspace resolver · Establishes workspace isolation for requests.
src/services/workspace/workspace_resolver.py - Conversation service
src/services/conversation/conversation_service.py - Supabase · RLS-backed tenant data and vector search.
src/infrastructure/database/supabase.py - Web search providers · Optional providers; missing keys fall back to knowledge-base retrieval.
src/services/search/providers/tavily.py
Operations & Ingestion
- Knowledge management · Manages collections, sources, uploads, versions, and quality.
src/services/knowledge_management/ingestion_service.py - Support escalation · Routes agents and creates operational context.
src/services/escalation/escalation_service.py - Notification service
src/services/notifications/notification_service.py - Offline vector ingestion · Must run after migrations before product retrieval is available.
scripts/upload_vectors.py
Connections 30
- React portal → Portal API & auth: uses
- Portal API & auth → FastAPI application: HTTP API
- Embed SDK → FastAPI application: embedded API calls
- Chat CLI → Chat orchestrator: chat requests
- MCP server → Chat orchestrator: tool requests
- FastAPI application → Routes & identity deps: dispatches
- Routes & identity deps → Authentication service: authenticates
- Routes & identity deps → Workspace resolver: resolves tenant
- Routes & identity deps → Chat orchestrator: chat requests
- Routes & identity deps → Knowledge management: management requests
- Routes & identity deps → Support escalation: support requests
- Authentication service → Supabase: token validation
- Workspace resolver → Supabase: RLS tenant data
- Chat orchestrator → Session service: resolves session
- Chat orchestrator → Source router: routes question
- Chat orchestrator → Advisory layer: applies advisory logic
- Chat orchestrator → Context merger: assembles evidence
- Chat orchestrator → RAG generation adapters: generates and validates
- Chat orchestrator → Conversation service: persists best effort
- Source router → Search manager: prepares selected sources
- Search manager → Supabase: internal vector retrieval
- Search manager → Web search providers: live web retrieval
- Search manager → Context merger: ranked evidence
- Context merger → RAG generation adapters: grounded context
- RAG generation adapters → Supabase: vector retrieval
- Conversation service → Supabase: stores conversations
- Knowledge management → Supabase: manages knowledge
- Offline vector ingestion → Supabase: loads vectors
- Support escalation → Notification service: notifies operations
- Support escalation → Supabase: stores handoff context