How anilkumarhv/code-doc-assistant works
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: context_builder.py Retrieval & context · setup.py Application wiring · app_routes.py API routes & models · chat_routes.py Chat routes
Components 19
Clients
- Vanilla JS UI · Static interface for repository ingestion and chat.
static/app.js
Application
- FastAPI entry point
src/main.py - Application wiring
src/core/setup.py - API routes & models · Health, ingestion, embedding, query, and chat-session endpoints.
src/api/app_routes.py - Chat routes
src/api/chat_routes.py - Runtime settings · Selects providers, models, credentials, and database connection.
src/config/settings.py
Repository ingestion
- Ingestion pipeline · Acquires a repository and drives analysis and indexing.
src/ingestion/pipeline.py - Repository acquisition · Clones GitHub sources when needed, scans files, and loads content.
src/ingestion/github_cloner.py - Structure analysis · Tree-sitter parsing derives structured multi-language code information.
src/ingestion/ast_parser.py - Docs & config analysis
src/ingestion/documentation_parser.py - Chunks & dependencies · Creates source-attributed chunks and cross-file dependency signals.
src/ingestion/chunker.py - Embedding pipeline · Embeds chunks and metadata for durable retrieval.
src/ingestion/embedding_pipeline.py
RAG answering
- RAG pipeline · Central online flow for query and chat answers.
src/rag/pipeline.py - Retrieval & context · Processes queries, retrieves vectors, and adds related source context.
src/rag/context_builder.py - Cited QA engine · Generates LLM answers with source citations.
src/rag/qa_engine.py
Persistence & providers
- PostgreSQL + pgvector · Stores embeddings, metadata, chat sessions, and messages.
src/vector_store/pgvector.py - Session manager
src/chat/session_manager.py - Embedding provider · Voyage AI is the documented embedding implementation.
src/embeddings/base.py - LLM provider · Gemini is the documented default answer model.
src/llm/base.py
Connections 26
- 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