# abhi-lash19/vera architecture

> Architecture diagram of the GitHub repository abhi-lash19/vera, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhi-lash19/vera
- Repository: https://github.com/abhi-lash19/vera

## Overview

#### Purpose and Entry Points
Enterprise Knowledge Brain is a terminal-oriented, grounded engineering-knowledge assistant. It ingests local documentation/code artifacts into persistent retrieval indexes, then answers queries through tool-directed retrieval and LLM synthesis. Primary entry points are `ingestion/main.py` for offline corpus construction, `cli.py` / `cli/__main__.py` for interactive use, `retrieval/main.py` for retrieval access, and `mcp_server/main.py` for MCP exposure.

#### Offline Ingestion and Persistence
The ingestion pipeline converts supported artifacts into a common chunk schema, cleans and enriches them, embeds content, and writes retrievable stores. Loaders cover archives, code, PDFs, Word, Markdown, spreadsheets, structured documents, and transcripts in `ingestion/loaders/`; processing stages are in `ingestion/processors/sanitizer.py`, `ingestion/processors/chunker.py`, and `ingestion/processors/metadata_enricher.py`. `ingestion/models/chunk_model.py` defines chunk records.

Indexes and metadata are materialized outside the package under `~/.ekb/`: dense FAISS, lexical BM25, and SQLite-backed chunk/metadata storage. Key boundaries are `ingestion/index/index_manager.py`, `ingestion/index/faiss_index.py`, `ingestion/index/bm25_index.py`, and `ingestion/storage/sqlite_writer.py`.

#### Retrieval Pipeline
Query retrieval combines semantic and lexical search against persisted ingestion outputs. `retrieval/embedders/query_embedder.py` creates query vectors; `retrieval/retrievers/faiss_retriever.py` and `retrieval/retrievers/bm25_retriever.py` retrieve candidate sets. `retrieval/fusion/hybrid_retriever.py` is the hybrid/RRF fusion boundary, with metadata filtering and cross-encoder reranking in `retrieval/filters/metadata_filter.py` and `retrieval/rerankers/cross_encoder_reranker.py`. Results use `retrieval/models/result_model.py`; SQLite reads are isolated in `retrieval/storage/sqlite_reader.py`.

#### Query Orchestration and Tool Planning
The orchestration layer selects an intent, plans tools, executes staged work, and traces execution. Core control points are `orchestration/orchestrator.py`, `orchestration/intent_classifier.py`, `orchestration/tool_planner.py`, and `orchestration/stages.py`; construction and lifecycle hooks sit in `orchestration/factory.py` and `orchestration/hooks.py`. Intent patterns and tool retrieval policy are externalized in `config/intent_patterns.yaml` and `config/tool_retrieval.yaml`.

#### MCP Tool Boundary
`mcp_server` packages capabilities as seven request-validated tools: flow explanation, component tracing, knowledge search, direct file context, integration listing, debugging, and design comparison. The server entry and dispatch boundary are `mcp_server/main.py`, `mcp_server/registry/tool_registry.py`, and `mcp_server/executor/tool_executor.py`. Tool implementations live in `mcp_server/tools/`, notably `search_knowledge.py`, `get_file_context.py`, and `compare_design.py`. Direct metadata tools can bypass LLM generation.

#### Context, Prompts, and LLM Providers
Retrieved chunks are deduplicated, diversified, compressed, validated, and constrained before model invocation. The context boundary is `ai_client/context/context_builder.py`, with token enforcement in `ai_client/context/token_budget.py` and models in `ai_client/context/models.py`. Prompt assembly, XML formatting, citations, safety, and validation are concentrated in `ai_client/prompts/builder.py`, `ai_client/prompts/assembler.py`, and `ai_client/prompts/xml_formatter.py`.

LLM integrations are provider-adapted behind `ai_client/llm/base.py` and `ai_client/llm/provider.py`, with Anthropic/Claude and OpenAI clients in `ai_client/llm/anthropic_client.py`, `ai_client/llm/claude_client.py`, and `ai_client/llm/openai_client.py`. Anthropic Claude is the intended reasoning service; OpenAI embeddings are used during ingestion.

#### Terminal Presentation
The CLI owns stdin/stdout interaction, streaming, local UI state, and debug rendering rather than retrieval or generation logic. Its main surfaces are `cli.py`, `cli_ui/console.py`, `cli_ui/stream.py`, and `cli_ui/display.py`. Final output formatting and source/token presentation are handled by `ai_client/formatter/response_formatter.py` and `ai_client/formatter/terminal_renderer.py`.

Main entry points: [`ingestion/index/index_manager.py`](https://github.com/abhi-lash19/vera/blob/main/ingestion/index/index_manager.py) (Index manager), [`retrieval/fusion/hybrid_retriever.py`](https://github.com/abhi-lash19/vera/blob/main/retrieval/fusion/hybrid_retriever.py) (Hybrid retrieval), [`mcp_server/executor/tool_executor.py`](https://github.com/abhi-lash19/vera/blob/main/mcp_server/executor/tool_executor.py) (MCP tool executor), [`retrieval/main.py`](https://github.com/abhi-lash19/vera/blob/main/retrieval/main.py) (Retrieval entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Offline Ingestion"]
  node_ingestion_entry["Ingestion entry<br/>Python entry point<br/>[main.py]"]
  node_artifact_loaders["Artifact loaders<br/>loader suite"]
  node_chunk_processing["Chunk processing<br/>processing pipeline<br/>[chunker.py]"]
  node_chunk_schema["Chunk schema<br/>data model<br/>[chunk_model.py]"]
  node_index_manager["Index manager<br/>persistence boundary<br/>[index_manager.py]"]
  node_faiss_index[("FAISS index<br/>dense index<br/>[faiss_index.py]")]
  node_bm25_index[("BM25 index<br/>lexical index<br/>[bm25_index.py]")]
  node_sqlite_store[("SQLite chunk store<br/>metadata store<br/>[sqlite_writer.py]")]
end

subgraph group_retrieval["Retrieval"]
  node_retrieval_entry["Retrieval entry<br/>Python entry point<br/>[main.py]"]
  node_query_embedder["Query embedder<br/>embedding adapter<br/>[query_embedder.py]"]
  node_hybrid_retrieval["Hybrid retrieval<br/>RRF fusion boundary"]
  node_metadata_filter["Metadata filter<br/>retrieval filter<br/>[metadata_filter.py]"]
  node_reranker["Cross-encoder reranker<br/>ranking stage"]
  node_sqlite_reader["SQLite reader<br/>storage adapter<br/>[sqlite_reader.py]"]
end

subgraph group_orchestration["Orchestration"]
  node_orchestrator{{"Query orchestrator<br/>control plane<br/>[orchestrator.py]"}}
  node_tool_planner["Intent and tool planner<br/>planning policy<br/>[tool_planner.py]"]
end

subgraph group_ai["AI Response"]
  node_context_builder["Context builder<br/>grounding boundary<br/>[context_builder.py]"]
  node_prompt_builder["Prompt assembly<br/>prompt pipeline<br/>[builder.py]"]
  node_llm_provider["LLM provider adapter<br/>provider boundary<br/>[provider.py]"]
  node_terminal_renderer["Terminal renderer<br/>output formatter"]
end

subgraph group_interfaces["Interfaces"]
  node_cli["Terminal CLI<br/>interactive entry point<br/>[cli.py]"]
  node_mcp_server["MCP server<br/>tool server entry<br/>[main.py]"]
  node_tool_executor["MCP tool executor<br/>tool dispatch boundary<br/>[tool_executor.py]"]
end

node_ingestion_entry -->|"loads artifacts"| node_artifact_loaders
node_artifact_loaders -->|"normalizes content"| node_chunk_processing
node_chunk_processing -->|"produces"| node_chunk_schema
node_chunk_schema -->|"indexes chunks"| node_index_manager
node_index_manager -->|"writes dense vectors"| node_faiss_index
node_index_manager -->|"writes lexical terms"| node_bm25_index
node_index_manager -->|"writes chunks and metadata"| node_sqlite_store
node_retrieval_entry -->|"embeds query"| node_query_embedder
node_query_embedder -->|"query vector"| node_hybrid_retrieval
node_faiss_index -->|"semantic candidates"| node_hybrid_retrieval
node_bm25_index -->|"lexical candidates"| node_hybrid_retrieval
node_hybrid_retrieval -->|"fused results"| node_metadata_filter
node_metadata_filter -->|"filtered candidates"| node_reranker
node_sqlite_store -->|"persisted metadata"| node_sqlite_reader
node_sqlite_reader -->|"chunk metadata"| node_metadata_filter
node_orchestrator -->|"selects intent and tools"| node_tool_planner
node_tool_planner -->|"plans retrieval"| node_retrieval_entry
node_reranker -->|"ranked evidence"| node_context_builder
node_context_builder -->|"grounded context"| node_prompt_builder
node_prompt_builder -->|"assembled prompt"| node_llm_provider
node_cli -->|"interactive queries"| node_orchestrator
node_mcp_server -->|"validated tool requests"| node_tool_executor
node_tool_executor -->|"LLM-backed tools"| node_orchestrator
node_tool_executor -.->|"direct retrieval tools"| node_retrieval_entry
node_llm_provider -->|"generated response"| node_terminal_renderer
node_terminal_renderer -->|"formatted output"| node_cli

click node_ingestion_entry "https://github.com/abhi-lash19/vera/blob/main/ingestion/main.py"
click node_chunk_processing "https://github.com/abhi-lash19/vera/blob/main/ingestion/processors/chunker.py"
click node_chunk_schema "https://github.com/abhi-lash19/vera/blob/main/ingestion/models/chunk_model.py"
click node_index_manager "https://github.com/abhi-lash19/vera/blob/main/ingestion/index/index_manager.py"
click node_faiss_index "https://github.com/abhi-lash19/vera/blob/main/ingestion/index/faiss_index.py"
click node_bm25_index "https://github.com/abhi-lash19/vera/blob/main/ingestion/index/bm25_index.py"
click node_sqlite_store "https://github.com/abhi-lash19/vera/blob/main/ingestion/storage/sqlite_writer.py"
click node_retrieval_entry "https://github.com/abhi-lash19/vera/blob/main/retrieval/main.py"
click node_query_embedder "https://github.com/abhi-lash19/vera/blob/main/retrieval/embedders/query_embedder.py"
click node_hybrid_retrieval "https://github.com/abhi-lash19/vera/blob/main/retrieval/fusion/hybrid_retriever.py"
click node_metadata_filter "https://github.com/abhi-lash19/vera/blob/main/retrieval/filters/metadata_filter.py"
click node_reranker "https://github.com/abhi-lash19/vera/blob/main/retrieval/rerankers/cross_encoder_reranker.py"
click node_sqlite_reader "https://github.com/abhi-lash19/vera/blob/main/retrieval/storage/sqlite_reader.py"
click node_orchestrator "https://github.com/abhi-lash19/vera/blob/main/orchestration/orchestrator.py"
click node_tool_planner "https://github.com/abhi-lash19/vera/blob/main/orchestration/tool_planner.py"
click node_context_builder "https://github.com/abhi-lash19/vera/blob/main/ai_client/context/context_builder.py"
click node_prompt_builder "https://github.com/abhi-lash19/vera/blob/main/ai_client/prompts/builder.py"
click node_llm_provider "https://github.com/abhi-lash19/vera/blob/main/ai_client/llm/provider.py"
click node_cli "https://github.com/abhi-lash19/vera/blob/main/cli.py"
click node_mcp_server "https://github.com/abhi-lash19/vera/blob/main/mcp_server/main.py"
click node_tool_executor "https://github.com/abhi-lash19/vera/blob/main/mcp_server/executor/tool_executor.py"
click node_terminal_renderer "https://github.com/abhi-lash19/vera/blob/main/ai_client/formatter/terminal_renderer.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ingestion_entry,node_artifact_loaders,node_chunk_processing,node_chunk_schema,node_index_manager,node_faiss_index,node_bm25_index,node_sqlite_store toneBlue
class node_retrieval_entry,node_query_embedder,node_hybrid_retrieval,node_metadata_filter,node_reranker,node_sqlite_reader toneAmber
class node_orchestrator,node_tool_planner toneMint
class node_context_builder,node_prompt_builder,node_llm_provider,node_terminal_renderer toneRose
class node_cli,node_mcp_server,node_tool_executor toneIndigo
```

## Components

### Offline Ingestion

Builds persistent knowledge indexes from local artifacts.

- [Ingestion entry](https://github.com/abhi-lash19/vera/blob/main/ingestion/main.py): Python entry point · `ingestion/main.py`
- **Artifact loaders**: loader suite · Supports documents, code, archives, and transcripts.
- [Chunk processing](https://github.com/abhi-lash19/vera/blob/main/ingestion/processors/chunker.py): processing pipeline · Sanitizes, chunks, and enriches common chunk records. · `ingestion/processors/chunker.py`
- [Chunk schema](https://github.com/abhi-lash19/vera/blob/main/ingestion/models/chunk_model.py): data model · `ingestion/models/chunk_model.py`
- [Index manager](https://github.com/abhi-lash19/vera/blob/main/ingestion/index/index_manager.py): persistence boundary · Coordinates dense, lexical, and metadata writes. · `ingestion/index/index_manager.py`
- [FAISS index](https://github.com/abhi-lash19/vera/blob/main/ingestion/index/faiss_index.py): dense index · `ingestion/index/faiss_index.py`
- [BM25 index](https://github.com/abhi-lash19/vera/blob/main/ingestion/index/bm25_index.py): lexical index · `ingestion/index/bm25_index.py`
- [SQLite chunk store](https://github.com/abhi-lash19/vera/blob/main/ingestion/storage/sqlite_writer.py): metadata store · Persistent chunk and metadata storage under ~/.ekb. · `ingestion/storage/sqlite_writer.py`

### Retrieval

Combines persisted semantic and lexical search.

- [Retrieval entry](https://github.com/abhi-lash19/vera/blob/main/retrieval/main.py): Python entry point · `retrieval/main.py`
- [Query embedder](https://github.com/abhi-lash19/vera/blob/main/retrieval/embedders/query_embedder.py): embedding adapter · `retrieval/embedders/query_embedder.py`
- [Hybrid retrieval](https://github.com/abhi-lash19/vera/blob/main/retrieval/fusion/hybrid_retriever.py): RRF fusion boundary · Fuses FAISS and BM25 candidate sets. · `retrieval/fusion/hybrid_retriever.py`
- [Metadata filter](https://github.com/abhi-lash19/vera/blob/main/retrieval/filters/metadata_filter.py): retrieval filter · `retrieval/filters/metadata_filter.py`
- [Cross-encoder reranker](https://github.com/abhi-lash19/vera/blob/main/retrieval/rerankers/cross_encoder_reranker.py): ranking stage · `retrieval/rerankers/cross_encoder_reranker.py`
- [SQLite reader](https://github.com/abhi-lash19/vera/blob/main/retrieval/storage/sqlite_reader.py): storage adapter · `retrieval/storage/sqlite_reader.py`

### Orchestration

Plans and executes query work.

- [Query orchestrator](https://github.com/abhi-lash19/vera/blob/main/orchestration/orchestrator.py): control plane · Classifies intent, plans tools, stages execution, and traces work. · `orchestration/orchestrator.py`
- [Intent and tool planner](https://github.com/abhi-lash19/vera/blob/main/orchestration/tool_planner.py): planning policy · Uses external intent patterns and retrieval policy. · `orchestration/tool_planner.py`

### AI Response

Builds grounded context and invokes providers.

- [Context builder](https://github.com/abhi-lash19/vera/blob/main/ai_client/context/context_builder.py): grounding boundary · Deduplicates, diversifies, compresses, validates, and token-bounds evidence. · `ai_client/context/context_builder.py`
- [Prompt assembly](https://github.com/abhi-lash19/vera/blob/main/ai_client/prompts/builder.py): prompt pipeline · Builds XML-formatted, cited, validated prompts. · `ai_client/prompts/builder.py`
- [LLM provider adapter](https://github.com/abhi-lash19/vera/blob/main/ai_client/llm/provider.py): provider boundary · Routes reasoning to Claude and supports provider clients. · `ai_client/llm/provider.py`
- [Terminal renderer](https://github.com/abhi-lash19/vera/blob/main/ai_client/formatter/terminal_renderer.py): output formatter · Formats final answers, sources, and token presentation. · `ai_client/formatter/terminal_renderer.py`

### Interfaces

Terminal and MCP access surfaces.

- [Terminal CLI](https://github.com/abhi-lash19/vera/blob/main/cli.py): interactive entry point · Owns terminal interaction, streaming, UI state, and debug rendering. · `cli.py`
- [MCP server](https://github.com/abhi-lash19/vera/blob/main/mcp_server/main.py): tool server entry · Exposes validated engineering-knowledge tools. · `mcp_server/main.py`
- [MCP tool executor](https://github.com/abhi-lash19/vera/blob/main/mcp_server/executor/tool_executor.py): tool dispatch boundary · Executes search, file context, design comparison, and metadata tools. · `mcp_server/executor/tool_executor.py`

## Connections

- Ingestion entry → Artifact loaders: loads artifacts
- Artifact loaders → Chunk processing: normalizes content
- Chunk processing → Chunk schema: produces
- Chunk schema → Index manager: indexes chunks
- Index manager → FAISS index: writes dense vectors
- Index manager → BM25 index: writes lexical terms
- Index manager → SQLite chunk store: writes chunks and metadata
- Retrieval entry → Query embedder: embeds query
- Query embedder → Hybrid retrieval: query vector
- FAISS index → Hybrid retrieval: semantic candidates
- BM25 index → Hybrid retrieval: lexical candidates
- Hybrid retrieval → Metadata filter: fused results
- Metadata filter → Cross-encoder reranker: filtered candidates
- SQLite chunk store → SQLite reader: persisted metadata
- SQLite reader → Metadata filter: chunk metadata
- Query orchestrator → Intent and tool planner: selects intent and tools
- Intent and tool planner → Retrieval entry: plans retrieval
- Cross-encoder reranker → Context builder: ranked evidence
- Context builder → Prompt assembly: grounded context
- Prompt assembly → LLM provider adapter: assembled prompt
- Terminal CLI → Query orchestrator: interactive queries
- MCP server → MCP tool executor: validated tool requests
- MCP tool executor → Query orchestrator: LLM-backed tools
- MCP tool executor → Retrieval entry: direct retrieval tools
- LLM provider adapter → Terminal renderer: generated response
- Terminal renderer → Terminal CLI: formatted output
