# anilkumarhv/code-doc-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/anilkumarhv/code-doc-assistant
- Repository: https://github.com/anilkumarhv/code-doc-assistant

## Overview

#### Purpose and entry points
This is a Python 3.11+ codebase-documentation assistant: it ingests local/GitHub repositories, indexes structure-aware code chunks and dependencies, and serves cited RAG answers plus persistent multi-turn chat. The FastAPI application starts at `src/main.py`; application setup/wiring is in `src/core/setup.py`. Browser access is provided by static assets in `static/index.html` and `static/app.js`.

#### HTTP/API boundary
FastAPI routes expose health, ingestion, embedding, query, and chat-session operations. Request/response validation is separated into API models, while route handlers invoke pipeline services rather than directly implementing analysis:
- `src/api/app_routes.py`
- `src/api/chat_routes.py`
- `src/api/models.py`

The API is the public boundary used by the vanilla-JS UI and programmatic clients; FastAPI also provides OpenAPI docs.

#### Ingestion and repository understanding
The ingestion pipeline accepts a GitHub source or local path, clones when needed, scans supported source/document/configuration files, and loads them for analysis. It derives structured code information through multi-language tree-sitter AST parsing and supplements it with documentation/configuration analysis:
- `src/ingestion/pipeline.py`
- `src/ingestion/github_cloner.py`
- `src/ingestion/loader.py`
- `src/ingestion/file_scanner.py`
- `src/ingestion/ast_parser.py`
- `src/ingestion/code_analyzer.py`
- `src/ingestion/documentation_parser.py`
- `src/ingestion/configuration_analyzer.py`

#### Chunking, dependency graph, and indexing
Parsed content becomes source-attributed chunks, intended to retain file and line metadata for answer citations. Dependency analysis tracks imports, calls, and cross-file references, providing connected-code signals beyond semantic similarity. The embedding pipeline converts chunks and their metadata to vectors and persists them:
- `src/ingestion/chunker.py`
- `src/ingestion/dependency_analyzer.py`
- `src/ingestion/embedding_pipeline.py`

#### Retrieval-augmented answering
A query is processed, relevant vectors are retrieved for a target codebase, and context is assembled with related source/dependency material. The QA engine invokes the configured LLM to generate an answer with citations. This is the central online request flow: API/query or chat message → RAG pipeline → retrieval/context → LLM answer.
- `src/rag/pipeline.py`
- `src/rag/query_processor.py`
- `src/rag/context_builder.py`
- `src/rag/qa_engine.py`

#### Persistence and provider boundaries
PostgreSQL with pgvector is the durable boundary for embedding vectors/metadata and chat session/message records; database initialization and vector operations are isolated from RAG and ingestion logic:
- `src/db/init.py`
- `src/vector_store/pgvector.py`
- `src/chat/session_manager.py`

Embedding providers implement a shared abstraction, with Voyage AI as the documented code embedding provider and Azure OpenAI available as an alternative. LLM providers likewise sit behind a base interface, with Gemini as the documented default and Azure OpenAI optional:
- `src/embeddings/base.py`
- `src/embeddings/voyage.py`
- `src/llm/base.py`
- `src/llm/gemini.py`

#### Runtime and deployment
Runtime configuration—including provider selection, API keys, models, and database URL—is centralized in `src/config/settings.py`. Docker Compose provisions the application and PostgreSQL locally; `Dockerfile` packages the service. Required external services are Gemini, Voyage AI, and PostgreSQL with pgvector. Production-oriented logging and metrics hooks reside in `src/utils/logger.py` and `src/utils/metrics.py`.

Main entry points: [`src/rag/context_builder.py`](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/rag/context_builder.py) (Retrieval & context), [`src/core/setup.py`](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/core/setup.py) (Application wiring), [`src/api/app_routes.py`](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/api/app_routes.py) (API routes & models), [`src/api/chat_routes.py`](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/api/chat_routes.py) (Chat routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Clients"]
  node_browser["Vanilla JS UI<br/>browser client<br/>[app.js]"]
end

subgraph group_application["Application"]
  node_main["FastAPI entry point<br/>application bootstrap<br/>[main.py]"]
  node_setup["Application wiring<br/>composition root<br/>[setup.py]"]
  node_api["API routes &amp; models<br/>FastAPI boundary<br/>[app_routes.py]"]
  node_chat_api["Chat routes<br/>FastAPI boundary<br/>[chat_routes.py]"]
  node_settings["Runtime settings<br/>configuration<br/>[settings.py]"]
end

subgraph group_ingestion["Repository ingestion"]
  node_ingestion_pipeline["Ingestion pipeline<br/>orchestrator<br/>[pipeline.py]"]
  node_repository_loader["Repository acquisition<br/>clone and load<br/>[github_cloner.py]"]
  node_code_analysis["Structure analysis<br/>AST analysis<br/>[ast_parser.py]"]
  node_content_analysis["Docs &amp; config analysis<br/>content analysis"]
  node_chunking_dependencies["Chunks &amp; dependencies<br/>code enrichment<br/>[chunker.py]"]
  node_embedding_indexer["Embedding pipeline<br/>index writer"]
end

subgraph group_rag["RAG answering"]
  node_rag_pipeline["RAG pipeline<br/>query orchestrator<br/>[pipeline.py]"]
  node_retrieval_context["Retrieval &amp; context<br/>context assembly<br/>[context_builder.py]"]
  node_qa_engine["Cited QA engine<br/>answer generator<br/>[qa_engine.py]"]
end

subgraph group_persistence["Persistence &amp; providers"]
  node_pgvector[("PostgreSQL + pgvector<br/>durable vector store<br/>[pgvector.py]")]
  node_chat_sessions["Session manager<br/>chat persistence<br/>[session_manager.py]"]
  node_embedding_provider{{"Embedding provider<br/>provider abstraction<br/>[base.py]"}}
  node_llm_provider{{"LLM provider<br/>provider abstraction<br/>[base.py]"}}
end

node_browser -->|"HTTP API"| node_api
node_browser -->|"chat requests"| node_chat_api
node_main -->|"starts"| node_setup
node_setup -->|"registers"| node_api
node_setup -->|"registers"| node_chat_api
node_settings -.->|"configures"| node_setup
node_api -->|"ingest repository"| node_ingestion_pipeline
node_api -->|"query"| node_rag_pipeline
node_chat_api -->|"chat message"| node_rag_pipeline
node_chat_api -->|"load and save history"| node_chat_sessions
node_ingestion_pipeline -->|"acquire files"| node_repository_loader
node_repository_loader -->|"source files"| node_code_analysis
node_repository_loader -->|"docs and config files"| node_content_analysis
node_code_analysis -->|"structured code"| node_chunking_dependencies
node_content_analysis -->|"supplemental content"| node_chunking_dependencies
node_chunking_dependencies -->|"attributed chunks"| node_embedding_indexer
node_embedding_indexer -->|"embed"| node_embedding_provider
node_embedding_indexer -->|"persist vectors"| node_pgvector
node_rag_pipeline -->|"retrieve context"| node_retrieval_context
node_retrieval_context -->|"vector search"| node_pgvector
node_retrieval_context -->|"embed query"| node_embedding_provider
node_retrieval_context -->|"grounded context"| node_qa_engine
node_qa_engine -->|"generate answer"| node_llm_provider
node_chat_sessions -->|"persist records"| node_pgvector
node_settings -.->|"provider selection"| node_embedding_provider
node_settings -.->|"provider selection"| node_llm_provider

click node_browser "https://github.com/anilkumarhv/code-doc-assistant/blob/main/static/app.js"
click node_main "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/main.py"
click node_setup "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/core/setup.py"
click node_api "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/api/app_routes.py"
click node_chat_api "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/api/chat_routes.py"
click node_settings "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/config/settings.py"
click node_ingestion_pipeline "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/ingestion/pipeline.py"
click node_repository_loader "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/ingestion/github_cloner.py"
click node_code_analysis "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/ingestion/ast_parser.py"
click node_content_analysis "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/ingestion/documentation_parser.py"
click node_chunking_dependencies "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/ingestion/chunker.py"
click node_embedding_indexer "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/ingestion/embedding_pipeline.py"
click node_rag_pipeline "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/rag/pipeline.py"
click node_retrieval_context "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/rag/context_builder.py"
click node_qa_engine "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/rag/qa_engine.py"
click node_pgvector "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/vector_store/pgvector.py"
click node_chat_sessions "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/chat/session_manager.py"
click node_embedding_provider "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/embeddings/base.py"
click node_llm_provider "https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/llm/base.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_browser toneBlue
class node_main,node_setup,node_api,node_chat_api,node_settings toneAmber
class node_ingestion_pipeline,node_repository_loader,node_code_analysis,node_content_analysis,node_chunking_dependencies,node_embedding_indexer toneMint
class node_rag_pipeline,node_retrieval_context,node_qa_engine toneRose
class node_pgvector,node_chat_sessions,node_embedding_provider,node_llm_provider toneIndigo
```

## Components

### Clients

- [Vanilla JS UI](https://github.com/anilkumarhv/code-doc-assistant/blob/main/static/app.js): browser client · Static interface for repository ingestion and chat. · `static/app.js`

### Application

- [FastAPI entry point](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/main.py): application bootstrap · `src/main.py`
- [Application wiring](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/core/setup.py): composition root · `src/core/setup.py`
- [API routes & models](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/api/app_routes.py): FastAPI boundary · Health, ingestion, embedding, query, and chat-session endpoints. · `src/api/app_routes.py`
- [Chat routes](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/api/chat_routes.py): FastAPI boundary · `src/api/chat_routes.py`
- [Runtime settings](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/config/settings.py): configuration · Selects providers, models, credentials, and database connection. · `src/config/settings.py`

### Repository ingestion

- [Ingestion pipeline](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/ingestion/pipeline.py): orchestrator · Acquires a repository and drives analysis and indexing. · `src/ingestion/pipeline.py`
- [Repository acquisition](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/ingestion/github_cloner.py): clone and load · Clones GitHub sources when needed, scans files, and loads content. · `src/ingestion/github_cloner.py`
- [Structure analysis](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/ingestion/ast_parser.py): AST analysis · Tree-sitter parsing derives structured multi-language code information. · `src/ingestion/ast_parser.py`
- [Docs & config analysis](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/ingestion/documentation_parser.py): content analysis · `src/ingestion/documentation_parser.py`
- [Chunks & dependencies](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/ingestion/chunker.py): code enrichment · Creates source-attributed chunks and cross-file dependency signals. · `src/ingestion/chunker.py`
- [Embedding pipeline](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/ingestion/embedding_pipeline.py): index writer · Embeds chunks and metadata for durable retrieval. · `src/ingestion/embedding_pipeline.py`

### RAG answering

- [RAG pipeline](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/rag/pipeline.py): query orchestrator · Central online flow for query and chat answers. · `src/rag/pipeline.py`
- [Retrieval & context](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/rag/context_builder.py): context assembly · Processes queries, retrieves vectors, and adds related source context. · `src/rag/context_builder.py`
- [Cited QA engine](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/rag/qa_engine.py): answer generator · Generates LLM answers with source citations. · `src/rag/qa_engine.py`

### Persistence & providers

- [PostgreSQL + pgvector](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/vector_store/pgvector.py): durable vector store · Stores embeddings, metadata, chat sessions, and messages. · `src/vector_store/pgvector.py`
- [Session manager](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/chat/session_manager.py): chat persistence · `src/chat/session_manager.py`
- [Embedding provider](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/embeddings/base.py): provider abstraction · Voyage AI is the documented embedding implementation. · `src/embeddings/base.py`
- [LLM provider](https://github.com/anilkumarhv/code-doc-assistant/blob/main/src/llm/base.py): provider abstraction · Gemini is the documented default answer model. · `src/llm/base.py`

## Connections

- Vanilla JS UI → API routes & models: HTTP API
- Vanilla JS UI → Chat routes: chat requests
- FastAPI entry point → Application wiring: starts
- Application wiring → API routes & models: registers
- Application wiring → Chat routes: registers
- Runtime settings → Application wiring: configures
- API routes & models → Ingestion pipeline: ingest repository
- API routes & models → RAG pipeline: query
- Chat routes → RAG pipeline: chat message
- Chat routes → Session manager: load and save history
- Ingestion pipeline → Repository acquisition: acquire files
- Repository acquisition → Structure analysis: source files
- Repository acquisition → Docs & config analysis: docs and config files
- Structure analysis → Chunks & dependencies: structured code
- Docs & config analysis → Chunks & dependencies: supplemental content
- Chunks & dependencies → Embedding pipeline: attributed chunks
- Embedding pipeline → Embedding provider: embed
- Embedding pipeline → PostgreSQL + pgvector: persist vectors
- RAG pipeline → Retrieval & context: retrieve context
- Retrieval & context → PostgreSQL + pgvector: vector search
- Retrieval & context → Embedding provider: embed query
- Retrieval & context → Cited QA engine: grounded context
- Cited QA engine → LLM provider: generate answer
- Session manager → PostgreSQL + pgvector: persist records
- Runtime settings → Embedding provider: provider selection
- Runtime settings → LLM provider: provider selection
