Codebase Knowledge Graph consulting

    AI isn’t hard. Understanding your codebase is.

    Built for engineering leaders facing a legacy re-platform, or an AI rollout on a large, multi-language codebase. Anyone can point an LLM at a repository and generate code. What’s hard is knowing what that code should do — and whether it’s correct. We map your system into a knowledge graph, so AI works with your architecture, not against it.

    • Deterministic structure
    • Grounded LLMs
    • Safe refactoring
    The problem

    Large codebases hide how they really work.

    Multiple languages, integrations and poor documentation. If you don’t know how the pieces connect, browsing the repo becomes guesswork — for your engineers and for your AI tools.

    1. 01

      Multiple languages

      C++, Java, Python, JavaScript and shell — each with its own conventions.

    2. 02

      Build systems

      Maven, npm, Make and friends, quietly deciding what actually ships.

    3. 03

      Framework glue

      The wiring that makes components talk, rarely written down.

    4. 04

      Test harnesses

      Fixtures and mocks that encode assumptions about behaviour.

    5. 05

      Configuration files

      Environment-specific switches that change how code runs.

    6. 06

      Generated assets

      Code nobody wrote by hand — and nobody wants to read.

    Why plain prompting breaks

    Refactoring with LLMs isn’t new. Doing it safely at scale is.

    01

    How do you fit an entire codebase into a prompt?

    Every model has a token limit. A mid-sized repo can run to tens of millions of tokens.

    Our answerGraph queries select only the relevant part of the codebase for each task.

    02

    How do you stop an LLM from hallucinating?

    Left unchecked, it drifts — inventing functions and starting doom loops.

    Our answerPrompts are grounded in deterministic structure extracted from your code.

    03

    Can you trust it to follow your architecture?

    Standards and patterns live in people’s heads, not in the model.

    Our answerResponses are parsed and checked against the patterns stored in the graph.

    Portrait of George Jayaratnam
    Who you work with

    George Jayaratnam

    Founder · Sydney, Australia

    MCMC Graph Co is led by George Jayaratnam: 25+ years building risk models and the data systems behind them in financial markets, now applying the same discipline to codebases.

    More about George
    What is GraphRAG?

    A knowledge graph of your system, plus an LLM.

    GraphRAG combines a knowledge graph grounded in your own code and data with a large language model. We use it the way we use compilers and databases — as a tool grounded in structure, not guesswork.

    • Context-aware answers centred on your own code and data
    • Follows the patterns specified in your knowledge graph
    • Adapts automatically — change the graph, and the LLM’s responses follow

    Where we focus first

    Large, complex codebases with multiple languages, integrations, and poor documentation.

    How it works

    Deterministic where it matters. AI where it helps.

    We build two knowledge graphs of your codebase without any LLMs. Only then do we bring in a model — and check everything it says against the graphs.

    Deterministic · no LLMs

    Data KG

    Database schema metadata ingested straight into a graph model.

    1. Database
    2. Schema
    3. Graph model
    4. Data KG

    Application KG

    Language-specific parsers map functions, parameters and services across files and repos.

    1. Codebase repo
    2. Parse syntax → ASTFull-text → lexical search
    3. Graph model
    4. Application KG
    Graph queryOnly the relevant subgraph

    Probabilistic

    Prompt interfaceLLM

    Explain or refactor code with exactly the context it needs — nothing more.

    Validation loop. Every LLM response is parsed and compared against the patterns and standards in the knowledge graphs — before anyone has to review it.

    Our tooling

    The codebase teardown engine.

    A deterministic, modular build system that maps an entire codebase into a graph. Graph queries then prompt LLMs to refactor code, which is checked against a new, pre-specified schema.

    1. 01Extract repository metadata to analyse file types and directory structure
    2. 02Traverse the Abstract Syntax Tree (AST) of every file to extract classes, functions and variables
    3. 03Store everything in a knowledge graph for structural reasoning
    4. 04Use the graph to re-design and re-architect the codebase
    5. 05Use graph queries as prompts for an LLM to refactor code
    6. 06Automatically check the LLM’s output against the revised graph schema
    Explore the open-source tools on GitHub
    graphrag-code-kg — tree
    graphrag-code-kg/
    ├── pyproject.toml
    ├── README.md
    ├── .env
    ├── notebooks/                       # Experiments + presentations
    ├── src/
    │   └── codebase_kg/
    │       ├── services/                # Backend integration APIs
    │       │   ├── neo4j_services.py    # Neo4j connection
    │       │   ├── neo4j_cypher.py      # Cypher query runner
    │       │   └── github_repo_service.py  # Repo metadata via GitHub API
    │       ├── cli/                     # Thin interface layer
    │       │   ├── cli.py               # Auto-scans ./commands
    │       │   └── commands/
    │       │       ├── neo4j.py         # CLI → Neo4j service
    │       │       └── repo.py          # CLI → GitHub service
    │       ├── schemas/                 # Software architecture schemas
    │       ├── data_kg/                 # Database metadata ingestion
    │       │   ├── extract/             # Connectors + foreign-key logic
    │       │   ├── transform/           # Raw metadata → graph model
    │       │   ├── load/                # Bulk CSV → Neo4j
    │       │   └── pipeline.py          # Builds the Data KG
    │       ├── app_kg/                  # Business-logic metadata ingestion
    │       │   ├── repo_metadata/       # Directory structure + file types
    │       │   ├── parsers/             # Language-specific AST extraction
    │       │   ├── codesearch/          # Cross-file usage + invocations
    │       │   ├── transform/           # Raw metadata → graph model
    │       │   ├── load/                # Bulk CSV → Neo4j
    │       │   └── pipeline.py          # Builds the Application KG
    │       ├── neo4jImports/            # CSV files for Neo4j
    │       └── graph_queries/           # Deterministic graph intelligence
    │           ├── shortest_join_paths.cypher
    │           ├── application_logic.cypher
    │           └── dependency_paths.cypher
    ├── tests/                           # Test-driven development
    ├── graphrag/                        # Graph ↔ LLM interaction
    │   ├── embeddings/
    │   ├── retrievers/
    │   ├── prompt_builders/
    │   └── response_synthesis/
    └── docs/                            # Code documentation site
    
    Articles

    Notes from the graph.

    Practical write-ups on codebase knowledge graphs, GraphRAG and AI-assisted refactoring.

    All articles
    Get started

    Turn your codebase into a queryable, explainable system.

    Request a discovery call. We’ll talk through your system, where it hurts, and whether a Codebase Knowledge Graph is the right fit.