Code Knowledge Graph for Smarter Software Architecture
A code knowledge graph stops you from treating a folder tree like architecture. When Claude Code or Cursor suggests an edit in a shared service, you need to know what breaks downstream—not guess.
What matters is traceable relationships: callers, entry points, config usage, and cross-repo paths. Don’t hand an AI a pile of files and hope it finds the dangerous one.
Start by checking:
- Which endpoints and jobs reach the symbol you plan to change
- Whether callers cross module or repository boundaries
- Whether “unused” code is really invoked through callbacks or decorators
The Problem Developers Actually Have With Architecture
You need to change one handler. Or a config loader. Or a shared auth service that "should be simple." Thirty minutes later you're clicking through four modules, two services, one deployment file, and a doc that may or may not still be true.
That's the real architecture problem.
In a small repo, folder structure gets you far enough. In a multi-module or multi-repo system, it doesn't. The thing that matters is rarely where code lives. It's what reaches it, what it calls next, which endpoint depends on it, which job reuses it at 2am, and whether some environment variable quietly changes the whole path.
A lot of teams live with a low-grade fear here:
- Refactors move slowly because nobody wants surprise breakage
- PR review turns into "did we miss anything?" instead of "is this the right change?"
- AI can generate edits fast, but you still don't trust them
- The real map of the system lives in two senior engineers and one incident postmortem
We've seen the same pattern over and over. Software architecture is mostly relationships. Not folders. Not package names. Not the diagram someone made six months ago.
If you can map those relationships, the system stops feeling mystical. You can inspect it instead of guessing at it.

What a Code Knowledge Graph Is
A code knowledge graph is a structured graph where code entities become nodes and their relationships become typed edges.
That sounds abstract until you make it concrete.
A node can be a repository, file, module, class, function, method, endpoint, config object, document, or even a business concept if you enrich beyond code. An edge is the relationship between them: one file imports another, one function calls another, one route reaches one handler, one service depends on a table or external API.
Typical node types include:
- Repositories and modules
- Files, classes, functions, methods
- API routes and queue consumers
- Config objects and environment variable references
- Docs, ADRs, and architecture notes when you include them
Typical edge types include:
CONTAINSIMPORTSCALLSINHERITS_FROMDEPENDS_ONREFERENCESDEFINES- HTTP request links
- Queue and event relationships
- Data flow links
This is where people often confuse a code knowledge graph with a software dependency graph. A software dependency graph usually tracks imports, packages, or module dependencies. Useful, but thin. A code knowledge graph can go further and model callers, entry points, API boundaries, config usage, dead code signals, and cross-repo flows.
That's why it works as a knowledge graph for software architecture. It models how the system behaves, not just how the files are arranged.
One blunt truth: an architecture graph for codebases is not valuable because it looks good in a browser tab. It's valuable because you can ask it questions and get precise answers.
Why File Trees, Grep, and Vector Search Are Not Enough
Reading code file by file breaks down once the interesting part of the system lives in the connections. You don't need the text of ten files. You need to know which five relationships matter.
Grep helps when you know the exact symbol. It falls apart when the answer is structural. "What calls this function?" is not the same question as "where does this name appear?" Those are very different failure modes, and teams blur them all the time.
Dumping a full repo into an LLM isn't the fix either.
Even with 64K or 128K token windows, you still have three problems:
- Large codebases don't fit cleanly
- The model still doesn't know what matters
- Big prompts often produce smooth but vague answers
We've all seen it. The assistant sounds informed, but it talks around the architecture because nobody grounded it in actual relationships.
Vector search has its place. It's good at semantic similarity. If you want "files that look like this other file" or "code related to retry logic," fine. It is weak at structural questions:
- What calls this function?
- Which endpoint reaches this module?
- Which services depend on this table?
- What path connects this queue consumer to that shared library?
Most engineering questions are not "find me similar text." They are one-hop, two-hop, or bounded multi-hop relationship questions.
The hidden waste is even worse. In every Claude Code or Cursor session, the assistant re-reads the repo like it's seeing the system for the first time. That's expensive in tokens and worse in attention. A reusable architecture model fixes that.
How a Repository Knowledge Graph Is Built
The pipeline is not magic. It's a series of steps, and each one matters.
Build sequence
- Parse code
Parse source code into syntax trees
- Extract entities
Extract entities such as files, classes, functions, methods, imports, and definitions
- Resolve links
Resolve relationships such as calls, references, inheritance, and entry points
- Store graph
Store the nodes and edges in a queryable model
- Add metadata
Enrich the graph with metadata or architecture signals
- Expose access
Expose it through search, API, CLI, or MCP for humans and AI tools
AST-based extraction is the backbone. Regex can get you part of the way, then betray you at the worst time. Syntax trees give you structure with much better reliability, especially across languages.
Tree-sitter shows up a lot here for a reason. It supports many languages and can reliably pull out function names, class definitions, imports, and other syntax-level facts. That's a practical starting point for a repository knowledge graph.
Still, import edges alone are not enough. Some languages allow meaningful interactions without explicit imports. Same-package class use in Java is a classic example. Frameworks hide relationships too. If your graph only knows imports, it will miss real behavior.
A simple request path makes the point:
- Request enters a controller
- Controller calls a service
- Service calls a repository
- Repository hits a data store or third party API
A good graph captures that path directly. The assistant doesn't have to infer the chain from snippets scattered across the repo. It can trace it.
The better systems don't stop at syntax. They enrich the graph with entry points, business rules, integration points, actors, and deployment context. That's where the graph starts feeling like architecture instead of just indexed source.
A Published Scale Demonstration
Scale is not just a theoretical possibility. In a published demonstration of its GraphGen4Code toolkit, IBM processed 1.3 million Python files from GitHub, covering 2,300 Python modules, and incorporated 47 million forum posts. The resulting integrated code graph contained more than 2 billion RDF triples—a graph representation for statements about entities and their relationships. IBM’s study demonstrates that code entities, program-analysis relationships, and supporting documentation can be combined at a very large corpus scale.
That is a scale demonstration, not a guarantee of build time, query latency, freshness, or extraction accuracy for a particular team’s repositories. Those operational measures still need to be tested against the languages, frameworks, and change rate in your own system.
What Relationships Matter Most for Software Architecture
Not all edges are equal. Some are nice to have. Some save you from production mistakes.
The highest-value relationships are the ones that answer day-to-day engineering questions.
Callers and callees
This is the workhorse relationship for blast radius and refactoring.
Questions it answers:
- What calls this shared function?
- If we change this method signature, what breaks first?
- Is this helper only used in tests, or is it on a live path?
If we had to pick one edge type to keep, this would be near the top.
Imports and module dependencies
These tell you about coupling, layering problems, and modules that have started reaching everywhere.
Useful questions:
- Which modules depend on this package?
- Did this "shared" library become a dumping ground?
- Are we creating cycles between domains?
Inheritance and implementation
Framework-heavy systems hide a lot behind base classes and interfaces.
Questions here are usually less glamorous, more urgent:
- Which class actually implements this interface?
- What subclasses inherit this behavior?
- If we change the base class, what fans out?
Endpoint to handler to service to data store paths
This is where architecture becomes operational.
Questions that matter:
- Which endpoint reaches this module?
- Does this route hit the old payment path or the new one?
- Which requests still touch the legacy table?
Config and environment variable usage
Teams ignore this until deploy day.
You want to know:
- Where is this environment variable used?
- Which startup path depends on this config flag?
- If we rotate this secret or rename this setting, what gets touched?
Cross-repo dependencies
In service-oriented systems, repo boundaries hide real risk.
Questions worth asking:
- Which repositories call this API?
- Which event consumers depend on this schema?
- If we change this shared model, how many repos absorb the hit?
An engineering knowledge graph gets much stronger when it spans code, docs, deployment config, and architecture notes. Code alone gives you a map. Code plus operating context gives you judgment.
Entry points deserve special attention. Routes, batch jobs, CLI commands, queue consumers, schedulers. They are where real execution begins. Find those, and the graph can follow the path that actually matters.
How a Code Knowledge Graph Makes AI Coding Assistants Smarter
The shift is simple: from code completion to architecture-aware assistance.
Without a graph, an assistant mostly sees local code, prompt context, and whatever patterns it can infer. With a code knowledge graph behind MCP, it can ask targeted questions before it edits anything:
- What calls this function?
- Which endpoints reach this module?
- What is the likely blast radius?
- Is there nearby code that already solves this?
- Is this export unreachable?
That changes trust.
The assistant is no longer guessing from training data or a giant pasted prompt. It's grounded in relationships extracted from your codebase. You still review the change, obviously. But now the assistant can reason from structure instead of vibes.
For Claude Code, Cursor, Codex, and similar tools, the practical gains are boring in the best way:
- Less time spent manually collecting context
- Fewer edits that break hidden dependencies
- Better alignment with existing architecture boundaries
- Better reuse of patterns already in the system
This matters even more across multiple repos. AI misses cross-repo relationships easily because the context is fragmented from the start.
Pharaoh is one approach built for this exact problem. We map TypeScript, JavaScript, Python, C and C++ repositories into a code knowledge graph, expose it through MCP, and remap on every push so assistants can query architecture, dependencies, callers, endpoints, environment variable usage, blast radius, and dead code before changes are made. For teams evaluating hosted tooling, one detail tends to matter more than marketing copy: we don't store source code after parsing.
That's the kind of trust detail technical teams ask about by the second conversation.

High-Value Use Cases for a Knowledge Graph for Software Architecture
The best use cases are the ones tied to risk, not curiosity.
Blast radius before edits
Before touching a shared service, map direct callers, downstream dependencies, and affected modules. This is useful in refactoring sprints, framework migrations, and ugly incident fixes where speed matters but blind speed is dangerous.
A fast edit is cheap. A fast wrong edit is expensive.
Safer PR review
Most code review tools catch problems after they ship. That's backwards.
A graph can flag structural risk during review, while the PR is still small enough to reason about. If the diff touches a shared module with twelve downstream callers, reviewers should know that before approve-and-pray mode kicks in.
Dead code detection
The simple heuristic is obvious: nodes with no incoming CALLS look unused.
The caveat matters more than the heuristic. Decorators, closures, callbacks, factory functions, and nested functions can all look dead when they are not. Conservative teams treat dead code as an investigation prompt, not a deletion list.
False confidence is worse than no signal.
Dependency and coupling analysis
Graphs are good at finding cycles, god modules, and services with too many outgoing edges. This helps you catch architecture drift while it's still annoying instead of catastrophic.
Existing pattern discovery
Before adding a new retry strategy, audit log wrapper, or auth check, find where the same problem is already solved. This helps humans and AI avoid duplicating patterns in six places.
Cross-repo impact analysis
One API, one event schema, one shared model. Ten repos. That's normal now.
You need a single architecture view when changes cross repo boundaries. Otherwise each team validates in isolation and the system still breaks as a whole.
Documentation that stays closer to reality
A graph won't save bad docs culture on its own. It can, though, generate focused architecture summaries and flow explanations from current structure, which beats stale diagrams nobody trusts.
What the Best Implementations Get Right, and Where They Still Struggle
Good systems are deterministic first. They use parsers, compilers, or static analysis to extract facts, not guesses. They produce typed edges you can inspect. They index repeatably across languages. They answer real engineering questions through queries, not screenshots.
That's the good news.
The harder part is where things still break down:
- Symbol resolution can be messy
- Dynamic languages hide relationships at runtime
- Metaprogramming can obscure call paths
- Import-only graphs miss important interactions
- Aggressive dead code detection creates noise fast
- Nice visualizations can hide shallow or stale data
We've learned a pretty stubborn lesson here: hierarchy is not enough. Folders matter. Files matter. But application behavior lives in interactions and execution paths.
The graph should answer bounded questions your team actually asks. "What reaches this code?" "What else will this touch?" "Is this path still alive?" That's enough to make it useful. Trying to solve every code analysis problem in one pass usually leads to a graph nobody trusts.
Choosing the Right Storage and System Design
This part gets turned into a religion fight more often than it should.
You have two common paths.
A graph database is a good fit when you want flexible traversal, graph-native queries, and interactive multi-hop exploration. If your team regularly asks for call chains, impact paths, implementation trees, or dependency clusters, graph-native storage feels natural.
A relational or analytical database can also work well. Nodes and edges can live in regular tables. One-hop and two-hop questions are often easy to answer with indexes, joins, or bounded recursive queries. That's enough for a surprising amount of code-agent work.
The tradeoff is straightforward:
- If your main questions are "who calls X," "what depends on Y," or "what path connects A to B within a bounded depth," regular tables may be perfectly fine
- If you need deeper exploration over large, changing graphs, a graph engine often fits better
Pick based on the questions, not aesthetics. Most teams don't need purity here. They need answers.
How to Evaluate a Tool or Build Strategy
Don't evaluate this category by demo polish. Evaluate it by whether it changes engineering decisions.
Questions worth asking:
- Does it support the languages and frameworks we actually run?
- Can it resolve more than imports?
- Can it identify callers, references, endpoints, and inheritance?
- Does it work across multiple repositories?
- How fresh is the graph after code changes?
- Can our AI tools query it through MCP or another direct interface?
- Does it produce useful outputs like blast radius, dead code signals, and cross-repo impact paths?
- How does it handle privacy and source code retention?
Workflow fit matters just as much:
- Does it help during coding sessions?
- Does it show up in PR review?
- Is it useful in refactors and migrations?
- Or is it just another dashboard people stop opening after week two?
Some teams will build in-house. Some will use open source pieces. Some will want a hosted tool because they need answers this quarter, not a graph project next quarter. All fair.
Pharaoh is the hosted option. Install the GitHub App and every repo you give it is mapped and refreshed on every push, so Claude Code, Cursor or Codex can ask what calls a function, what a change reaches and what nothing uses anymore. If your repos move fast, PR Guard runs the same graph against each pull request and posts a GitHub check for new dead code, breaking signature changes, exact duplicates and blast radius. All of it is in the trial, and Pro keeps it running after that.
If you're working on code quality more broadly, not just architecture mapping, our open source AI Code Quality Framework covers the linting and testing side.
A Practical Adoption Path for Engineering Teams
Start with one question that already wastes time every week.
Not ten questions. One.
Good starting points:
- What calls this shared service?
- Which endpoints touch this model?
- Which modules depend on this package?
- What code looks dead but still ships?
Build or evaluate the graph around that first. Don't try to model the whole universe on day one. Pick one repository or one critical flow. Prove that the answers are useful. Then expand to multi-module or multi-repo coverage.
You also need to decide on freshness. Active product repos usually want per-push updates. Slower systems can live with scheduled refreshes. There's no prize for indexing faster than your decision cycle.
One more thing people get backward: add AI access after the graph is useful on its own. If the graph can't answer architecture questions directly, wiring it into an assistant won't save it.
A practical next step this week:
Adoption path
- Choose example
Pick a recent change that caused surprise impact
- Trace impact
Trace the real callers, entry points, and downstream dependencies
- Capture gaps
Write down what you wish you'd known before the edit
- Set benchmark
Use that as the benchmark for your first repository knowledge graph
That's usually enough to tell whether this will pay off.
Conclusion
The shift is not "use more AI." It's "make the system legible."
Better architecture decisions come from visible relationships, not from reading more files or trusting faster answers. A code knowledge graph gives you clearer dependency paths, better blast radius analysis, more grounded AI assistance, and less guesswork around dead code and existing patterns.
If you do one thing this week, audit one risky area of your codebase by tracing callers, entry points, and cross-module dependencies. If your team already uses Claude Code, Cursor, or another MCP client, adding an architecture-aware graph is a practical way to give those tools the context they keep pretending they already have.
Article Record
ReferencesPrimary sources used for this article
- A Toolkit for Generating Code Knowledge Graphs for K-CAP 2021 - IBM Research
- Your codebase is a graph | OXD Labs
- Building One Knowledge Graph Across 46 Repositories With Static Analysis - DEV Community
- How We Built a Shared Code Knowledge Graph with Timeplus
- CodeGraph: Build Queryable Knowledge Graphs from Code