Pro Graph Query
Boost productivity using this query, code, graph, database. Includes structured workflows, validation checks, and reusable patterns for ai maestro.
Code Graph Query
Overview
A skill that helps Claude Code understand and navigate the dependency graph of your codebase ā tracing function call chains, mapping component relationships, identifying impact areas before making changes, and finding unused or circular dependencies. Essential for safe refactoring and understanding complex codebases.
When to Use
- Before refactoring: understand what depends on the code you're changing
- Investigating bugs: trace the call chain from entry point to failure
- Code reviews: assess the blast radius of a change
- Architecture analysis: visualize component relationships
- Dead code detection: find unused functions and modules
- Dependency auditing: identify circular or unnecessary dependencies
Quick Start
# Find all callers of a function claude "Who calls the validateUser function?" # Trace a dependency chain claude "Show me the full call chain from the /api/orders endpoint to the database" # Find impact of a change claude "What would break if I change the User interface?" # Find unused exports claude "Find all exported functions that are never imported"
Core Principle
Read code ā Query dependency graph ā Understand impact ā Then modify
Never change a widely-used function without first understanding its callers.
Graph Query Types
1. Callers (Who calls this?)
Find all functions that call a specific function:
# Direct callers grep -rn "validateUser(" src/ --include="*.ts" # Including dynamic calls grep -rn "validateUser\|validate.*User" src/ --include="*.ts"
Example output:
src/controllers/authController.ts:45: const valid = await validateUser(input);
src/services/registrationService.ts:23: await validateUser(userData);
src/middleware/auth.ts:67: if (!validateUser(token.payload)) return next(err);
ā 3 callers across 3 files. Changing validateUser impacts auth, registration, and middleware.
2. Callees (What does this call?)
Find all functions called by a specific function:
# Read the function and trace its calls claude "Read the processOrder function and list every external function it calls"
Example:
processOrder()
āāā validateOrder()
āāā checkInventory()
āāā calculateTotal()
ā āāā applyDiscount()
ā āāā calculateTax()
āāā chargePayment()
āāā sendConfirmationEmail()
ā Changing calculateTax only affects calculateTotal ā processOrder.
3. Import Graph
Map module dependencies:
# Find all imports in a file grep -n "^import\|^const.*require" src/services/orderService.ts # Find all importers of a module grep -rn "from.*orderService\|require.*orderService" src/ --include="*.ts" # Build full import tree claude "Map the complete import tree for src/services/orderService.ts"
4. Type Dependencies
Trace interface/type usage:
# Find all files using a type grep -rn "User\b" src/ --include="*.ts" | grep -v "node_modules\|\.test\." # Find type extensions grep -rn "extends User\|Partial<User>\|Pick<User\|Omit<User" src/
5. Component Relationships
For React/frontend codebases:
# Find all components that render <UserProfile> grep -rn "<UserProfile" src/components/ --include="*.tsx" # Find all components imported by a page grep -n "^import" src/pages/Dashboard.tsx # Find props drilling chains claude "Trace how the 'user' prop flows from App.tsx down to leaf components"
Impact Analysis
Before Changing a Function
1. Find all callers ā grep -rn "functionName(" src/
2. Check test coverage ā grep -rn "functionName" tests/
3. Check if it's in the API ā grep -rn "functionName" src/routes/
4. Check if it's exported ā grep -n "export.*functionName" src/
5. Assess blast radius ā How many files? How critical?
Impact Matrix
| Change Type | Risk | Check |
|---|---|---|
| Rename function | Medium | All callers must update |
| Change params | High | All callers must match new signature |
| Change return type | High | All consumers must handle new type |
| Delete function | Critical | Must find all usages first |
| Add optional param | Low | Existing callers unaffected |
| Internal refactor | Low | If signature unchanged |
Circular Dependency Detection
# Find potential circular imports claude "Check for circular dependencies in src/services/" # Common pattern: # A imports B, B imports A ā Circular! # Fix: Extract shared code to C, both import C
Resolution strategies:
- Extract shared code to a third module
- Use dependency injection instead of direct imports
- Lazy imports for runtime-only dependencies
- Interface segregation ā depend on abstractions
Dead Code Detection
# Find exported functions never imported elsewhere claude "Find all exported functions in src/utils/ that are never imported by any other file" # Find unused components claude "Find React components in src/components/ that are never rendered by any page or other component" # Find unused types claude "Find TypeScript interfaces in src/types/ that are never referenced"
Visualization
Text-Based Dependency Tree
src/pages/OrderPage.tsx
āāā src/components/OrderForm.tsx
ā āāā src/components/ProductSelector.tsx
ā āāā src/components/AddressForm.tsx
ā āāā src/hooks/useOrderForm.ts
ā āāā src/services/orderService.ts
ā āāā src/services/inventoryService.ts
ā āāā src/services/paymentService.ts
āāā src/components/OrderSummary.tsx
āāā src/hooks/useOrder.ts
āāā src/services/orderService.ts (shared)
Mermaid Diagram
graph TD A[OrderPage] --> B[OrderForm] A --> C[OrderSummary] B --> D[orderService] C --> D D --> E[inventoryService] D --> F[paymentService]
Best Practices
- Always check callers before changing signatures ā The compiler catches types, but not logic
- Map the full tree for risky changes ā One level of callers isn't enough
- Use tests as documentation ā Tests show how functions are actually used
- Keep dependency graphs shallow ā Deep chains are hard to reason about
- Prefer explicit imports ā Avoid barrel files (
index.ts) that hide dependencies - Run dead code detection regularly ā Remove unused code to reduce complexity
- Watch for circular dependencies ā They cause import ordering issues and bundling problems
- Document architectural boundaries ā Which modules should never depend on each other
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Full-Stack Code Reviewer
Comprehensive code review skill that checks for security vulnerabilities, performance issues, accessibility, and best practices across frontend and backend code.
Test Suite Generator
Generates comprehensive test suites with unit tests, integration tests, and edge cases. Supports Jest, Vitest, Pytest, and Go testing.
Pro Architecture Workspace
Battle-tested skill for architectural, decision, making, framework. Includes structured workflows, validation checks, and reusable patterns for development.