# How CRG Performs Blast Radius Analysis: Bidirectional Graph Traversal in VS Code

> Learn how CRG performs blast radius analysis using bidirectional BFS on a code dependency graph. Discover impacted code from changed files in VS Code.

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

---

**CRG computes blast radius analysis by performing a bidirectional breadth-first search (BFS) over a SQLite-backed code dependency graph, starting from changed files and traversing both incoming and outgoing relationships up to a configurable depth to identify all potentially impacted code entities.**

Code Review Graph (CRG) is a VS Code extension that maps codebase relationships into a queryable knowledge graph. Its **blast radius analysis** feature helps developers understand the ripple effects of code changes by calculating which functions, classes, and files may be affected by a modification. The analysis leverages a deterministic graph traversal algorithm implemented in the `SqliteReader` class to deliver precise impact assessments within seconds.

## The Three-Step Blast Radius Algorithm

The core implementation resides in [`src/backend/sqlite.ts`](https://github.com/tirth8205/code-review-graph/blob/main/src/backend/sqlite.ts) within the `SqliteReader.getImpactRadius` method. The algorithm executes in three distinct phases to ensure comprehensive impact detection.

### Step 1: Identifying Seed Nodes

The process begins by establishing the **seed set**—all code entities contained within the modified files. In lines 44-48 of [`sqlite.ts`](https://github.com/tirth8205/code-review-graph/blob/main/sqlite.ts), the method iterates over the supplied file list and extracts every node's `qualifiedName`, adding these identifiers to a `Set` called `seeds`. These seed nodes represent the ground truth of what actually changed in the commit or working directory.

### Step 2: Bidirectional BFS Traversal

Starting from the seed set, CRG initiates a breadth-first search to discover dependency relationships. The while-loop at lines 57-80 expands the frontier by querying **both outgoing and incoming edges**:

- **Forward traversal** via `getEdgesBySource` identifies what the current node calls or depends upon
- **Reverse traversal** via `getEdgesByTarget` discovers what calls or references the current node

Each newly discovered node is added to the `impacted` set, and the traversal continues until reaching the user-configurable `blastRadiusDepth`. This bidirectional approach ensures that CRG captures both downstream effects (what the change breaks) and upstream dependencies (what might break the change).

### Step 3: Constructing the Impact Report

After traversal completes, the method resolves raw qualified names back to full `GraphNode` objects (lines 82-95). It then compiles the final result object containing:

- `changedNodes`: The original seed entities from modified files
- `impactedNodes`: All entities reached during the BFS traversal
- `impactedFiles`: Distinct file paths containing impacted nodes (lines 96-99)
- `edges`: The subset of dependency edges connecting all involved nodes (lines 101-103)

## VS Code Integration Architecture

The UI layer bridges the editor context to the graph analysis engine through the `codeReviewGraph.showBlastRadius` command, implemented in [`src/features/blastRadius.ts`](https://github.com/tirth8205/code-review-graph/blob/main/src/features/blastRadius.ts) (lines 24-62).

When triggered, the command:

1. Resolves the active editor and cursor position
2. Attempts to locate the specific node at the cursor via `reader.getNodeAtCursor`
3. Falls back to file-level analysis if no specific entity is found
4. Retrieves the configured depth from `codeReviewGraph.blastRadiusDepth` (defaulting to 2)
5. Invokes `reader.getImpactRadius([filePath], depth)`
6. Updates the `BlastRadiusTreeProvider` to render changed versus impacted nodes in the VS Code tree view

This architecture separates the graph storage concerns in `SqliteReader` from the presentation logic, allowing the blast radius analysis to be invoked both programmatically and through the GUI.

## Practical Usage Examples

You can leverage the blast radius engine both as a standalone API and within the VS Code UI.

### Programmatic API Access

For automation or custom extension development, interact directly with the `SqliteReader` class:

```typescript
import { SqliteReader } from 'code-review-graph-vscode/src/backend/sqlite';

// Assume `reader` is an initialized SqliteReader instance
const changedFiles = ['src/auth.py', 'src/middleware.py'];
const depth = 2;

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

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

```

### VS Code Command Registration

The extension registers the user-facing command in [`src/features/blastRadius.ts`](https://github.com/tirth8205/code-review-graph/blob/main/src/features/blastRadius.ts) as follows:

```typescript
vscode.commands.registerCommand('codeReviewGraph.showBlastRadius', async () => {
  const reader = getReader();
  const editor = vscode.window.activeTextEditor;
  const cursorLine = editor?.selection.active.line + 1;
  
  // Resolve specific node or fall back to file
  const node = reader?.getNodeAtCursor(editor.document.uri.fsPath, cursorLine);
  const filePath = node?.filePath ?? editor?.document.uri.fsPath;
  
  const depth = vscode.workspace.getConfiguration('codeReviewGraph')
                                .get<number>('blastRadiusDepth', 2);
  
  const impact = reader?.getImpactRadius([filePath], depth);
  blastRadiusProvider.setResults(impact?.changedNodes, impact?.impactedNodes);
  await vscode.commands.executeCommand('codeReviewGraph.blastRadius.focus');
});

```

## Summary

- CRG stores code entities and relationships in a **SQLite-backed knowledge graph** managed by `SqliteReader`
- **Blast radius analysis** executes a bidirectional BFS starting from seed nodes in changed files, traversing both `getEdgesBySource` and `getEdgesByTarget` up to a configurable depth
- The algorithm returns comprehensive impact data including changed nodes, impacted nodes, affected file paths, and connecting edges
- The VS Code command `codeReviewGraph.showBlastRadius` in [`src/features/blastRadius.ts`](https://github.com/tirth8205/code-review-graph/blob/main/src/features/blastRadius.ts) provides UI integration with cursor-based entity resolution
- Developers can invoke the analysis programmatically via `SqliteReader.getImpactRadius` for custom tooling and CI/CD pipelines

## Frequently Asked Questions

### What is the default traversal depth for blast radius analysis?

The default `blastRadiusDepth` is **2 levels**, as defined in the VS Code configuration settings. Users can modify this value through the Settings UI or by directly editing the `codeReviewGraph.blastRadiusDepth` configuration key. Increasing the depth captures more distant dependencies but may significantly expand the result set depending on the codebase's coupling.

### Does CRG analyze dependencies in both directions?

Yes. Unlike simple call-graph analysis, CRG performs **bidirectional traversal** using both `getEdgesBySource` (outgoing dependencies) and `getEdgesByTarget` (incoming references). This ensures the blast radius includes not only what the changed code affects downstream, but also what upstream code might impact or be impacted by the changes.

### How does CRG distinguish between changed files and impacted files?

CRG maintains a strict separation between **seed nodes** (entities physically present in the modified files) and **impacted nodes** (entities reached through graph traversal). The `changedNodes` array contains only entities from the input file list, while `impactedNodes` contains entities discovered during the BFS. The `impactedFiles` property provides a deduplicated list of file paths containing impacted nodes, excluding the originally changed files unless they appear in the traversal results.

### Can blast radius analysis target specific functions rather than entire files?

Yes. When invoked through the VS Code UI, the command first attempts to resolve the specific code entity at the cursor position using `reader.getNodeAtCursor`. If a specific function or class is identified, only that entity becomes the seed node. If no specific entity is found at the cursor location, the system falls back to treating the entire file as the seed set, allowing both granular and broad analysis scopes.