Refactoring
Plan safe refactors by mapping dependencies
Plan safe refactors by mapping dependencies BEFORE making changes.
Quick Start
"I want to rename getUserData to fetchUserProfile"
"What calls getUserData?"
"What would be impacted if I changed getUserData?"
When to Use
Use this workflow when planning:
- Renaming functions, classes, or variables
- Extracting code into new modules
- Splitting services
- Moving code between files
- Deprecating APIs
Refactoring Patterns
| Pattern | First Step |
|---|---|
| Rename symbol | Use noodlbox_rename_symbol for automated multi-file rename |
| Extract module | Map internal dependencies |
| Split service | Group by domain, map cross-dependencies |
| Move to new file | Check import relationships |
| Deprecate API | Find all callers, plan migration path |
Planning Workflow
Find the Symbol
Locate the code you want to refactor:
"Find the getUserData function"
Uses: noodlbox_query_with_context tool
Get Full Symbol Context
Understand the symbol's role, all references, and community:
"Show me the full context for getUserData"
Uses: noodlbox_symbol_context tool
Returns categorized incoming/outgoing references, community membership, and centrality score.
Map All Callers
Find everything that depends on this code:
"What calls getUserData?"
Uses: noodlbox_raw_cypher_query tool
MATCH (caller)-[:CALLS]->(target:Symbol {name: "getUserData"})
RETURN caller.name, caller.file_path, caller.kind
ORDER BY caller.file_pathThis tells you what will break if you change the signature.
Map All Callees
Find everything this code depends on:
"What does getUserData call?"
MATCH (source:Symbol {name: "getUserData"})-[:CALLS]->(callee)
RETURN callee.name, callee.file_path, callee.kindThis tells you what you're bringing along if you move the code.
Identify Cross-Community Dependencies
Check if refactoring crosses module boundaries:
"Which communities reference getUserData?"
MATCH (caller)-[:CALLS]->(target:Symbol {name: "getUserData"})
MATCH (caller)-[:BELONGS_TO]->(comm:Community)
RETURN DISTINCT comm.name, comm.label, count(caller) as caller_countCross-community changes require more coordination.
Preview Impact
Before making changes, preview the blast radius:
"What would be impacted if I changed getUserData?"
Uses: noodlbox_detect_impact tool
Review the potentially_affected symbols.
Risk Assessment
| Indicator | Risk Level | Action |
|---|---|---|
| < 5 callers, same community | Low | Proceed with care |
| 5-20 callers, same community | Medium | Document changes, update tests |
| > 20 callers | High | Consider gradual migration |
| Cross-community callers | High | Coordinate with teams |
| Part of public API | Critical | Version and deprecate properly |
Example: Planning a Rename
Task: Rename getUserData to fetchUserProfile
Get Symbol Context
"Show me the context for getUserData"
Uses: noodlbox_symbol_context
Returns: 12 incoming callers across 4 files, all in the "UserManagement" community. Centrality score: 0.72.
Preview the Rename
"Preview renaming getUserData to fetchUserProfile"
Uses: noodlbox_rename_symbol with dry_run: true
Returns: 4 files affected, 14 total edits (12 graph edits, 2 ast_search edits), with per-file change details and confidence tags.
Assess and Apply
- 12 graph edits (high confidence) -- auto-accept
- 2 ast_search edits (lower confidence) -- review in test files
- Same community (low coordination risk)
- Decision: Apply the rename with
dry_run: false
Example: Planning a Service Split
Task: Split DataService into UserDataService and ProductDataService
Map Internal Methods
MATCH (method)-[:DEFINED_IN]->(class:Symbol {name: "DataService"})
RETURN method.name, method.kindGroup by Domain
MATCH (method)-[:DEFINED_IN]->(class:Symbol {name: "DataService"})
MATCH (method)-[:CALLS]->(dep)
RETURN method.name,
CASE
WHEN dep.name CONTAINS "User" THEN "user"
WHEN dep.name CONTAINS "Product" THEN "product"
ELSE "shared"
END as domainIdentify Shared Dependencies
Methods calling both user and product code need special handling.
Plan Extraction Order
- Extract shared utilities first
- Create
UserDataServicewith user methods - Create
ProductDataServicewith product methods - Update callers
- Remove original
DataService
Tools Reference
| Purpose | Tool |
|---|---|
| Find code | noodlbox_query_with_context |
| Symbol deep-dive | noodlbox_symbol_context |
| Map dependencies | noodlbox_raw_cypher_query |
| Rename symbol | noodlbox_rename_symbol |
| Preview impact | noodlbox_detect_impact |