# How code-review-graph Identifies Affected Code in a Change Set Using Impact Radius Analysis

> Learn how code-review-graph finds affected code with impact radius analysis. It uses BFS on a codebase graph to map dependencies up to a set depth.

- Repository: [Tirth Kanani/code-review-graph](https://github.com/tirth8205/code-review-graph)
- Tags: deep-dive
- Published: 2026-08-07

---

**The `code-review-graph` extension identifies affected code by modeling the codebase as a directed graph in SQLite, then executing a bidirectional breadth-first search (BFS) from changed files to find all dependent and related symbols up to a configurable depth.**

The `tirth8205/code-review-graph` repository provides a VS Code extension that helps developers understand the ripple effects of code changes through **impact radius analysis**. By treating functions, classes, and files as nodes in a dependency graph, the system can precisely calculate which parts of the codebase may be affected by a given change set. This graph-driven approach enables the **Blast Radius view**, SCM decorations, and review assistant features that visualize potential impact before code is committed.

## Modeling the Codebase as a Dependency Graph

At the core of the analysis lies a SQLite database representing the entire codebase as a directed graph. Each **node** corresponds to a symbol—such as a function, class, or file—while **edges** capture relationships including function calls, imports, inheritance, and test coverage. This graph structure allows the system to traverse dependencies bidirectionally, identifying both what a changed module calls and what depends upon it.

## The Impact Radius Algorithm: A Bidirectional BFS Approach

The `SqliteReader.getImpactRadius` method in [`code-review-graph-vscode/src/backend/sqlite.ts`](https://github.com/tirth8205/code-review-graph/blob/main/code-review-graph-vscode/src/backend/sqlite.ts) implements the core logic through a four-stage pipeline that converts file paths into a comprehensive impact report.

### Step 1: Seed Collection from Changed Files

The algorithm begins by gathering all graph nodes that belong to the modified files supplied in the change set. These nodes form the **seed set**—the entry points for the graph traversal.

In [`sqlite.ts`](https://github.com/tirth8205/code-review-graph/blob/main/sqlite.ts) lines 44-48, the implementation iterates over the input file paths to collect every symbol defined within those files, establishing the starting frontier for the search:

```typescript
// Simplified representation of the seed collection logic
const seeds: Node[] = [];
for (const filePath of changedFiles) {
    const nodes = this.getNodesByFile(filePath);
    seeds.push(...nodes);
}

```

### Step 2: Bidirectional Breadth-First Search

Starting from the seeds, the system performs a **bidirectional BFS** that explores both outgoing edges (what the seed affects) and incoming edges (what depends on the seed). This traversal continues up to a configurable depth, which defaults to 2 hops but can be adjusted based on the desired sensitivity of the analysis.

The expansion logic appears in [`sqlite.ts`](https://github.com/tirth8205/code-review-graph/blob/main/sqlite.ts) lines 57-78, where the algorithm maintains a `frontier` queue and iteratively discovers neighbors to populate `nextFrontier`:

```typescript
while (depth > 0) {
    const nextFrontier: Node[] = [];
    for (const node of frontier) {
        // Outgoing: what this node calls/imports
        const outgoing = this.getOutgoingEdges(node);
        // Incoming: what calls/depends on this node
        const incoming = this.getIncomingEdges(node);
        
        nextFrontier.push(...outgoing, ...incoming);
    }
    frontier = nextFrontier;
    depth--;
}

```

This bidirectional approach ensures the analysis captures both downstream consumers of changed code and upstream dependencies that might influence behavior.

### Step 3: Resolving Impacted Nodes

After the BFS completes, the algorithm distinguishes between **changed nodes** (the original seeds) and **impacted nodes** (all other visited vertices). The system filters the visited set to exclude seeds, then retrieves full metadata for each impacted symbol.

As implemented in [`sqlite.ts`](https://github.com/tirth8205/code-review-graph/blob/main/sqlite.ts) lines 89-94, this resolution phase creates the `impactedNodes` array that drives downstream reporting:

```typescript
const impactedNodes: Node[] = [];
for (const node of visitedNodes) {
    if (!seeds.has(node.id)) {
        impactedNodes.push(this.getNodeMetadata(node));
    }
}

```

### Step 4: Extracting Impacted Files and Relationships

The final stage derives two critical artifacts: the set of distinct file paths containing impacted nodes (`impactedFiles`), and the complete set of edges connecting seeds to impacted nodes (`edges`). This data structures the raw graph traversal into a format suitable for visualization.

The implementation in [`sqlite.ts`](https://github.com/tirth8205/code-review-graph/blob/main/sqlite.ts) lines 96-103 aggregates these results:

```typescript
const impactedFiles = new Set(impactedNodes.map(n => n.filePath));
const edges = this.getEdgesBetween([...seeds, ...impactedNodes]);

```

## Integration with VS Code Features

The impact radius data flows into three primary VS Code extension points, each consuming the `getImpactRadius` method to surface dependency information to developers.

### Blast Radius Visualization

The **Blast Radius view** command (`codeReviewGraph.showBlastRadius`) leverages the active editor to compute context-specific impact. When invoked, the extension reads the current file path and calls `reader.getImpactRadius([filePath], depth)`, then delegates the results to the tree view provider.

This integration appears in [`code-review-graph-vscode/src/features/blastRadius.ts`](https://github.com/tirth8205/code-review-graph/blob/main/code-review-graph-vscode/src/features/blastRadius.ts) lines 54-58:

```typescript
const filePath = editor.document.uri.fsPath;
const depth = configuration.get<number>('blastRadiusDepth', 2);
const impact = reader.getImpactRadius([filePath], depth);
blastRadiusProvider.setResults(impact.changedNodes, impact.impactedNodes);

```

### Source Control Decorations

The extension enhances the SCM explorer by coloring files that may be affected by pending changes. When decorations refresh, the system invokes `getImpactRadius` against the working set of modified files to identify transitive dependencies requiring attention.

The decoration logic resides in [`code-review-graph-vscode/src/features/scmDecorations.ts`](https://github.com/tirth8205/code-review-graph/blob/main/code-review-graph-vscode/src/features/scmDecorations.ts) lines 61-69, where impacted files receive visual indicators in the gutter and file explorer.

### Review Assistant Summaries

The **Review Assistant** feature synthesizes impact analysis into natural language summaries. After calculating the radius, the assistant reports statistics such as the count of additionally impacted files beyond the direct change set, helping reviewers understand the scope of their examination.

This summarization occurs in [`code-review-graph-vscode/src/features/reviewAssistant.ts`](https://github.com/tirth8205/code-review-graph/blob/main/code-review-graph-vscode/src/features/reviewAssistant.ts) lines 94-99:

```typescript
const impact = reader.getImpactRadius(modifiedFiles, 2);
const additionalFiles = impact.impactedFiles.length;
reviewPanel.appendMessage(
    `This change affects ${additionalFiles} additional files through dependency relationships.`
);

```

## Practical Implementation Examples

To compute the impact radius programmatically for a Git diff or arbitrary file list, instantiate `SqliteReader` and invoke the analysis method:

```typescript
import { SqliteReader } from './backend/sqlite';

// Initialize with an open database connection
const reader = new SqliteReader(dbPath);

const changedFiles = ['src/controllers/auth.ts', 'src/services/user.ts'];
const depth = 2; // Configurable traversal depth

const impact = reader.getImpactRadius(changedFiles, depth);

console.log('Changed nodes:', impact.changedNodes.length);
console.log('Impacted nodes:', impact.impactedNodes.length);
console.log('Impacted files:', Array.from(impact.impactedFiles));

```

For VS Code extension development, integrate the analysis into command handlers by accessing the active editor and configuration:

```typescript
vscode.commands.registerCommand('codeReviewGraph.showBlastRadius', async () => {
    const reader = getReader();
    if (!reader) return;

    const editor = vscode.window.activeTextEditor;
    if (!editor) return;

    const filePath = editor.document.uri.fsPath;
    const depth = vscode.workspace
        .getConfiguration('codeReviewGraph')
        .get<number>('blastRadiusDepth', 2);

    const impact = reader.getImpactRadius([filePath], depth);
    
    // Update tree view with changed and impacted nodes
    blastRadiusProvider.setResults(impact.changedNodes, impact.impactedNodes);
});

```

## Summary

- **Graph representation**: The extension stores code relationships in a SQLite-backed directed graph where nodes represent symbols and edges capture dependencies.
- **Bidirectional BFS**: Impact radius analysis performs a breadth-first search traversing both incoming and outgoing edges up to a configurable depth (default 2).
- **Seed-to-impact pipeline**: The algorithm collects seed nodes from changed files, explores the graph, filters out seeds to identify impacted nodes, and aggregates affected file paths.
- **VS Code integration**: Results power the Blast Radius tree view, SCM file decorations, and review assistant summaries in [`blastRadius.ts`](https://github.com/tirth8205/code-review-graph/blob/main/blastRadius.ts), [`scmDecorations.ts`](https://github.com/tirth8205/code-review-graph/blob/main/scmDecorations.ts), and [`reviewAssistant.ts`](https://github.com/tirth8205/code-review-graph/blob/main/reviewAssistant.ts) respectively.

## Frequently Asked Questions

### What is impact radius analysis in code-review-graph?

Impact radius analysis is the process of calculating all code symbols and files that may be affected by a set of changes. According to the `tirth8205/code-review-graph` source code, this involves treating changed files as entry points in a dependency graph and performing a bidirectional graph traversal to discover transitive relationships. The analysis returns both the directly changed nodes and the indirectly impacted nodes up to a specified depth.

### How does the bidirectional BFS differ from unidirectional traversal?

Unlike unidirectional traversal that only follows outgoing dependencies (what the changed code calls), the bidirectional BFS implemented in [`sqlite.ts`](https://github.com/tirth8205/code-review-graph/blob/main/sqlite.ts) lines 57-78 explores both outgoing edges (downstream effects) and incoming edges (upstream dependents). This ensures the analysis captures not only what the change might break, but also what external code might influence the behavior of the changed module, providing a complete picture of the dependency graph.

### What is the default search depth and how does it affect performance?

The default search depth is 2 hops from the seed nodes, as configured in [`blastRadius.ts`](https://github.com/tirth8205/code-review-graph/blob/main/blastRadius.ts) and the VS Code settings. This balances comprehensiveness with performance—deeper searches may identify more distant dependencies but increase query complexity and result set size linearly with depth. Developers can adjust this value in their workspace configuration to trade off between analysis thoroughness and computational cost.

### Which VS Code features consume the impact radius data?

Three primary features consume the impact radius results: the **Blast Radius view** ([`blastRadius.ts`](https://github.com/tirth8205/code-review-graph/blob/main/blastRadius.ts) lines 54-58) which visualizes dependencies in a tree view; **SCM decorations** ([`scmDecorations.ts`](https://github.com/tirth8205/code-review-graph/blob/main/scmDecorations.ts) lines 61-69) which color-code affected files in the source control panel; and the **Review Assistant** ([`reviewAssistant.ts`](https://github.com/tirth8205/code-review-graph/blob/main/reviewAssistant.ts) lines 94-99) which generates summaries of how many additional files are impacted by a change set. All three invoke `SqliteReader.getImpactRadius` with the current file context or modified file list.