-
Notifications
You must be signed in to change notification settings - Fork 0
path command
Arham-Qureshi edited this page Jul 21, 2026
·
1 revision
Finds the shortest dependency path between any two nodes in the dependency graph using bidirectional BFS (breadth-first search).
codebase-vis path <source> <target>
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.
- Initialize two frontiers:
{source}and{target} - Initialize two parent maps:
forwardParentsandbackwardParents - At each iteration, expand the smaller frontier
- After each expansion, check if any node appears in both frontiers
- When a meeting node is found, reconstruct the path by walking forward from source and backward from target
- Return the complete chain with
│and▼arrows
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.
# 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"- Run
codebase-vis generatefirst —pathreads from the existinggraph.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