Dependency Graph
CodeBuddy can generate a visual dependency graph of your workspace, showing how files import from each other. The graph is output as a Mermaid flowchart that renders directly in the chat or can be copied into documentation.
Supported languages
Section titled “Supported languages”| Language | Import pattern detected |
|---|---|
TypeScript (.ts) | import ... from '...' |
JavaScript (.js) | import ... from '...' |
TSX (.tsx) | import ... from '...' |
JSX (.jsx) | import ... from '...' |
Python (.py) | Planned (regex-based import / from) |
Go (.go) | Planned (regex-based import) |
Currently, JS/TS imports are fully parsed. Python and Go file types are watched and included as nodes, but import edge detection is focused on the ES module import ... from '...' syntax.
How it works
Section titled “How it works”Features
Section titled “Features”Automatic cache invalidation
Section titled “Automatic cache invalidation”The service watches all supported file types (**/*.{ts,js,jsx,tsx,py,go}) with a FileSystemWatcher. When any file is created, changed, or deleted, the cached graph is invalidated. The next call to generateGraph() rebuilds it.
Local imports only
Section titled “Local imports only”Only relative imports (paths starting with .) are included as edges. Third-party package imports (lodash, react, etc.) are excluded to keep the graph focused on your code.
File limit
Section titled “File limit”The service queries up to 50 files per workspace to prevent excessively large graphs. Files in node_modules, dist, out, .git, and .vscode are excluded.
Node sanitization
Section titled “Node sanitization”File names are sanitized for Mermaid compatibility — non-alphanumeric characters are replaced with underscores for node IDs, while the human-readable label preserves the original filename.
Example output
Section titled “Example output”For a small TypeScript project:
Force regeneration
Section titled “Force regeneration”Pass force: true to bypass the cache:
const graph = await dependencyGraph.generateGraph(true);This is useful after bulk file operations where the file watcher may not have caught all changes.
The dependency graph is available as an agent tool. Ask CodeBuddy:
“Show me the dependency graph for this project”
The agent calls DependencyGraphService.generateGraph() and renders the Mermaid output in the chat.