Architecture Overview

July 21, 2026 · View on GitHub

Code-Graph-RAG consists of two main components that work together to analyse and query codebases.

Components

1. Multi-Language Parser

A Tree-sitter based parsing system that analyses codebases and ingests data into Memgraph.

  • Uses Tree-sitter for robust, language-agnostic AST parsing
  • Extracts functions, classes, methods, modules, and their relationships
  • Supports 13 programming languages with a unified graph schema (plus Scala in development)
  • Handles complex patterns like nested functions, class hierarchies, and cross-module calls

2. RAG System (codebase_rag/)

An interactive CLI for querying the stored knowledge graph.

  • Translates natural language questions into Cypher queries
  • Retrieves source code snippets for found elements
  • Supports AI-powered code editing with AST-based targeting
  • Provides code optimisation with interactive approval workflow

Data Flow

Source Code → Tree-sitter Parser → AST Analysis → Memgraph Knowledge Graph

User Query → AI Model (Cypher Gen) → Cypher Query → Graph Results → Response

Key Dependencies

DependencyPurpose
tree-sitterLanguage-agnostic AST parsing
pymgclientMemgraph database adapter
pydantic-aiAgent framework for LLM integration
pydantic-settingsSettings management
mcpModel Context Protocol SDK
typerCLI framework
richTerminal rendering
prompt-toolkitInteractive command line
diff-match-patchCode patching
watchdogFilesystem events monitoring
huggingface-hubUniXcoder model download