# How to Analyze the Blast Radius of Code Changes Using CRG

> Analyze code change blast radius with CRG. This tool traverses your codebase graph using BFS to pinpoint impacted functions, classes, and files. Understand your code's impact effectively.

- Repository: [Tirth Kanani/code-review-graph](https://github.com/tirth8205/code-review-graph)
- Tags: how-to-guide
- Published: 2026-08-08

---

**Code Review Graph (CRG) analyzes blast radius by traversing an offline SQLite graph of your codebase using bidirectional breadth-first search (BFS) to identify every function, class, and file impacted by a specific change.**

Code Review Graph (CRG) is an open-source VS Code extension from `tirth8205/code-review-graph` that maps your repository into a queryable graph database. By analyzing the blast radius of code changes, you can predict downstream impacts before modifications reach production. This guide explains how CRG's graph traversal algorithms calculate precisely which code entities depend on—or are depended upon by—your changes.

## Understanding the Blast Radius Algorithm

### The SQLite Graph Foundation

CRG constructs an offline SQLite database where every **code entity** (functions, classes, modules) represents a node and every relationship (calls, imports, inheritance) represents an edge. This graph structure enables fast, complex queries across the entire codebase without re-parsing files at runtime.

### Bidirectional BFS Traversal in getImpactRadius

The core blast radius calculation happens in `SqliteReader.getImpactRadius` within [`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) (lines 31-50). The algorithm performs a breadth-first search that walks both **forward (outgoing)** and **backward (incoming)** edges up to a configurable depth.

The BFS starts by collecting seed nodes from the changed files, then expands the frontier in both directions:

- **Forward edges** (`getEdgesBySource`): Identify code that the changed node calls or affects
- **Backward edges** (`getEdgesByTarget`): Identify code that depends on or calls the changed node

```typescript
// Simplified logic from sqlite.ts
for (const file of changedFiles) {
  for (const node of this.getNodesByFile(file)) {
    seeds.add(node.qualifiedName);
  }
}

while (frontier.size > 0 && depth < maxDepth) {
  for (const qn of frontier) {
    // Forward: things this node affects
    for (const e of this.getEdgesBySource(qn)) { /* ... */ }
    
    // Reverse: things that depend on this node
    for (const e of this.getEdgesByTarget(qn)) { /* ... */ }
  }
}

```

The method returns three collections: `changedNodes` (the seeds), `impactedNodes` (all reachable nodes excluding seeds), and `impactedFiles` (unique file paths containing the impacted nodes).

## Using the Blast Radius Feature in VS Code

### Command Palette Workflow

The `registerBlastRadiusCommand` function 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 17-55) registers the **`codeReviewGraph.showBlastRadius`** command. To analyze blast radius interactively:

1. Open a file and place your cursor on the symbol to analyze (or anywhere in the file)
2. Execute **Code Review Graph: Show Blast Radius** from the command palette
3. CRG resolves the node via [`cursorResolver.ts`](https://github.com/tirth8205/code-review-graph/blob/main/cursorResolver.ts), runs the BFS, and displays results in the Blast Radius side panel managed by `BlastRadiusTreeProvider`

### Configuring Search Depth

The traversal depth is controlled by the **`codeReviewGraph.blastRadiusDepth`** setting (default: 2). Increasing this value expands the search horizon to include secondary and tertiary dependencies, while setting it to 0 shows only the nodes within the changed file itself.

## Programmatic Blast Radius Analysis

You can invoke the blast radius calculation programmatically using the `SqliteReader` API for custom extensions or automation scripts:

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

// Initialize the reader with your database path
const reader = new SqliteReader(dbPath);

// Read configuration or use default
const depth = vscode.workspace.getConfiguration('codeReviewGraph')
  .get<number>('blastRadiusDepth', 2);

// Calculate impact for specific files
const impact = reader.getImpactRadius(['src/auth.py', 'src/utils.py'], depth);

console.log(`Changed nodes: ${impact.changedNodes.length}`);
console.log(`Impacted nodes: ${impact.impactedNodes.length}`);
console.log(`Affected files: ${impact.impactedFiles.length}`);

```

### Integrating with the Tree View

To display results in the VS Code UI programmatically:

```typescript
import { BlastRadiusTreeProvider } from './views/treeView';

const treeProvider = new BlastRadiusTreeProvider();

// After calling getImpactRadius...
treeProvider.setResults(impact.changedNodes, impact.impactedNodes);
await vscode.commands.executeCommand('codeReviewGraph.blastRadius.focus');

```

## Key Source Files and Architecture

| File | Purpose |
|------|---------|
| [`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 `SqliteReader` and the core **`getImpactRadius`** BFS algorithm |
| [`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) | Registers the **`codeReviewGraph.showBlastRadius`** command and orchestrates the analysis workflow |
| [`code-review-graph-vscode/src/views/treeView.ts`](https://github.com/tirth8205/code-review-graph/blob/main/code-review-graph-vscode/src/views/treeView.ts) | Provides **`BlastRadiusTreeProvider`** for rendering results in the side panel |
| [`code-review-graph-vscode/src/features/cursorResolver.ts`](https://github.com/tirth8205/code-review-graph/blob/main/code-review-graph-vscode/src/features/cursorResolver.ts) | Maps cursor positions to specific graph nodes by looking up the innermost entity in the SQLite database |
| [`code-review-graph-vscode/src/extension.ts`](https://github.com/tirth8205/code-review-graph/blob/main/code-review-graph-vscode/src/extension.ts) | Entry point that wires commands into VS Code's command palette (lines 173-180) |

## Summary

- CRG constructs an offline SQLite graph where code entities are nodes and relationships are edges
- The **`getImpactRadius`** method in [`sqlite.ts`](https://github.com/tirth8205/code-review-graph/blob/main/sqlite.ts) performs bidirectional BFS to find all code affected by changes
- Analysis depth is configurable via **`codeReviewGraph.blastRadiusDepth`** (default: 2)
- Results are accessible through the VS Code command palette **`codeReviewGraph.showBlastRadius`** or programmatically via the TypeScript API
- The extension resolves cursor positions to specific nodes using **[`cursorResolver.ts`](https://github.com/tirth8205/code-review-graph/blob/main/cursorResolver.ts)**

## Frequently Asked Questions

### What is a code blast radius?

The blast radius of a code change refers to the total scope of impact that modification has on the rest of the codebase. It includes all functions, classes, and files that either depend on the changed code or are depended upon by it, helping developers assess the risk and testing requirements associated with a change.

### How does CRG determine which nodes are affected?

CRG uses a bidirectional breadth-first search algorithm implemented in `SqliteReader.getImpactRadius` (located 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)). The algorithm traverses both outgoing edges (what the code calls) and incoming edges (what calls the code) up to a configurable maximum depth to identify all reachable code entities.

### Can I adjust the sensitivity of the blast radius analysis?

Yes, you can control the search radius by modifying the **`codeReviewGraph.blastRadiusDepth`** setting in VS Code. The default value of 2 traverses two levels of dependencies in both directions. Increasing this value captures wider architectural impacts but may include more noise, while decreasing it focuses on immediate dependencies only.

### Does CRG support analyzing multiple files simultaneously?

Yes, the `getImpactRadius` method accepts an array of file paths, allowing you to analyze the combined blast radius of changes across multiple files. The VS Code extension interface currently focuses on single-file or cursor-specific analysis, but the underlying API supports batch analysis of several files at once.