How k-abhishek/ai-matrix-backend works
AI Matrix is a multi-tenant backend combining website crawling and semantic search, conversational tool-using agents, connector/MCP execution, and Indian legal research. The main documented flow is a client request through the API into crawling and indexing, or into a grounded chat agent that retrieves knowledge and responds. The graph also preserves the connector and legal-research capabilities. Edges rely on the README and SOURCE INDEX references; unsampled implementation details are not inferred beyond those references.
Main entry points: crawl.service.ts Crawl orchestration · app.ts HTTP API gateway · agent-runtime.service.ts Agent runtime · qdrant.service.ts Vector index
Components 24
API and tenancy
- HTTP API gateway
src/app.ts - Authentication
src/middleware/auth.ts
Crawl and search
- Crawl orchestration
src/services/crawl.service.ts - Sitemap discovery
src/services/sitemap.service.ts - Safe page fetching
src/services/fetcher.service.ts - Content extraction
src/services/content-extractor.service.ts - Token-aware chunking
src/services/chunking.service.ts - Embedding generation
src/services/embedding.service.ts - Vector index
src/services/qdrant.service.ts - Semantic search
src/modules/search/search.service.ts
Agents and chat
- Chat orchestration
src/modules/chat/chat.service.ts - Agent runtime
src/modules/runtime/agent-runtime.service.ts - Model selection
src/services/modelFactory.service.ts - Context window
src/services/contextWindow.service.ts - Chat persistence
src/modules/chat/chat.repository.ts
Connectors and MCP
- Workspace connections
src/modules/connections/connection.service.ts - OAuth authorization
src/modules/connections/auth.manager.ts - Tool execution
src/modules/execution/execution-engine.service.ts - MCP client
src/modules/mcp/mcp-client.manager.ts
Legal research
- Legal ingestion
src/modules/legal-research/ingestion/legal-ingestion.service.ts - Legal source discovery
src/modules/legal-research/discovery/legal-discovery.service.ts - Legal research agent
src/modules/legal-research/agents/legal-research.graph.ts - Legal retrieval
src/modules/legal-research/retrieval/hybrid-search.service.ts
Other components
- Frontend clients
Connections 23
- Frontend clients → HTTP API gateway: sends requests
README.md - HTTP API gateway → Authentication: authenticates
src/app.ts - HTTP API gateway → Crawl orchestration: routes crawl requests
- HTTP API gateway → Chat orchestration: routes chat requests
- Crawl orchestration → Sitemap discovery: discovers URLs
src/services/crawl.service.ts - Crawl orchestration → Safe page fetching: fetches pages
src/services/crawl.service.ts - Crawl orchestration → Content extraction: extracts content
src/services/crawl.service.ts - Crawl orchestration → Token-aware chunking: chunks content
src/services/crawl.service.ts - Crawl orchestration → Embedding generation: generates embeddings
src/services/crawl.service.ts - Crawl orchestration → Vector index: stores vectors
src/services/crawl.service.ts - Embedding generation → Vector index: provides vectors
src/services/qdrant.service.ts - Semantic search → Vector index: queries vectors
- Chat orchestration → Agent runtime: invokes agent
src/routes/chatRoutes.ts - Agent runtime → Model selection: selects model
src/modules/runtime/agent-runtime.service.ts - Agent runtime → Context window: manages context
src/modules/runtime/agent-runtime.service.ts - Agent runtime → Chat persistence: loads conversation
src/modules/runtime/agent-runtime.service.ts - Workspace connections → OAuth authorization: starts authorization
src/modules/connections/auth.manager.ts - OAuth authorization → Workspace connections: triggers discovery
src/modules/connections/auth.manager.ts - Tool execution → MCP client: dispatches MCP tools
src/modules/execution/execution-engine.service.ts - Legal source discovery → Legal ingestion: supplies discovered documents
src/modules/legal-research/ingestion/legal-one-time-ingestion.service.ts - Legal ingestion → Embedding generation: embeds legal chunks
src/modules/legal-research/ingestion/legal-ingestion.service.ts - Legal ingestion → Vector index: indexes legal content
src/modules/legal-research/ingestion/legal-ingestion.service.ts - Legal research agent → Legal retrieval: retrieves authorities