Skip to content

path command

Arham-Qureshi edited this page Jul 21, 2026 · 1 revision

path — Find the Shortest Dependency Chain

Finds the shortest dependency path between any two nodes in the dependency graph using bidirectional BFS (breadth-first search).

codebase-vis path <source> <target>

path output

Bidirectional BFS

Standard BFS searches from the source node, expanding a frontier outward until it reaches the target. For a graph with branching factor b and depth d, it visits O(b^d) nodes.

Bidirectional BFS searches from both the source and the target simultaneously:

Standard BFS:     Source ──→ ──→ ──→ ──→ Target    O(b^d)
Bidirectional:    Source ──→ ──→ ←── ←── Target    O(b^(d/2))

The search expands the smaller frontier at each step, and stops when the two frontiers meet. For a codebase with thousands of files, this is the difference between milliseconds and minutes.

Algorithm

  1. Initialize two frontiers: {source} and {target}
  2. Initialize two parent maps: forwardParents and backwardParents
  3. At each iteration, expand the smaller frontier
  4. After each expansion, check if any node appears in both frontiers
  5. When a meeting node is found, reconstruct the path by walking forward from source and backward from target
  6. Return the complete chain with and arrows

Output Format

src/graph/builder.js
│
▼ src/cli/shared.js
│
▼ src/utils/file-system.js

Each line shows a file in the dependency chain, connected by arrows pointing from dependent to dependency.

Examples

# Path between two files
codebase-vis path src/graph/builder.js src/graph/enricher.js

# Path using partial names
codebase-vis path builder enricher

# Path to an entity
codebase-vis path src/cli/commands/generate.js "builder.js::buildGraph"

Notes

  • Run codebase-vis generate first — path reads from the existing graph.json
  • If no path exists between the two nodes, you'll see a "no path found" message
  • Only file-to-file edges are traversed (entities and external packages are excluded from pathfinding)
  • Useful for understanding "why does file A depend on file B?" — the intermediate files reveal the chain

Clone this wiki locally