noodlbox

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

PatternFirst Step
Rename symbolUse noodlbox_rename_symbol for automated multi-file rename
Extract moduleMap internal dependencies
Split serviceGroup by domain, map cross-dependencies
Move to new fileCheck import relationships
Deprecate APIFind 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_path

This 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.kind

This 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_count

Cross-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

IndicatorRisk LevelAction
< 5 callers, same communityLowProceed with care
5-20 callers, same communityMediumDocument changes, update tests
> 20 callersHighConsider gradual migration
Cross-community callersHighCoordinate with teams
Part of public APICriticalVersion 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.kind

Group 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 domain

Identify Shared Dependencies

Methods calling both user and product code need special handling.

Plan Extraction Order

  1. Extract shared utilities first
  2. Create UserDataService with user methods
  3. Create ProductDataService with product methods
  4. Update callers
  5. Remove original DataService

Tools Reference

PurposeTool
Find codenoodlbox_query_with_context
Symbol deep-divenoodlbox_symbol_context
Map dependenciesnoodlbox_raw_cypher_query
Rename symbolnoodlbox_rename_symbol
Preview impactnoodlbox_detect_impact

On this page