- Home
- Skills
- Code Quality & Review
- structural refactor
Works with the AI Agents you already use
structural refactor
Audit structural debt and perform behavior-preserving refactors to reduce codebase coupling and complexity.
$9
structural refactor
Example session with this skill installed
Perform a structural audit of the /src/services directory to identify god objects and propose a refactor sequence for the most coupled module.
- Read your context and instructions
- Compiled the structural refactor
I have completed the structural audit of /src/services. The analysis covered 14 files, focusing on dependency fan-in/out and semantic cohesion.
Structural Audit
Scope: /src/services
Verification baseline: npm run test:unit (Passed)
Inspection coverage: 14 source files analyzed. Git churn data unavailable.
Hotspots
| Target | Evidence | Semantic clusters | Action | Risk | Confidence |
|---|---|---|---|---|---|
OrderProcessor.ts | 1.2k LOC, 8 external deps, handles persistence + email + tax | Persistence, Notification, TaxCalc | REFACTOR | HIGH | HIGH |
AuthService.ts | High fan-in, but single responsibility (JWT) | Session Management | LEAVE | LOW | MEDIUM |
PaymentGateway.ts | Multiple provider switches, high branching | Provider Logic, Validation | WATCH | MEDIUM | MEDIUM |
Target: OrderProcessor.ts
Current responsibility: Orchestrating order lifecycle, DB transactions, and third-party integrations.
Observed hidden responsibilities: Tax calculation logic and SMTP formatting.
Natural seams: A TaxCalculator for pure math and a NotificationDispatcher for side effects.
Suggested target topology: Extract TaxCalculator to /domain and NotificationService to /infrastructure.
Refactor sequence:
- Characterize tax math with new unit tests.
- Extract
calculateTaxto a pure class. - Introduce
NotificationServiceinterface to break direct SMTP dependency. - Inject new services into
OrderProcessor.
Next steps
- Approve the extraction of
TaxCalculator.tsto begin the refactor. - Provide the SMTP configuration schema to define the
NotificationServiceinterface. - Run
npm run lintto ensure no circular dependencies are introduced.
Connects securely to your tools. The creator never sees your data.
About this skill
Structural debt is rarely solved by splitting files based on line counts. This skill audits your codebase for high coupling, hidden responsibilities, and change amplification to deliver behavior-preserving refactors that actually reduce complexity. It moves beyond "clean code" aesthetics to ensure module boundaries match data ownership and domain logic.
What it does
- Structural auditing scans your repository for god objects, pass-through layers, and tight coupling using semantic and evolutionary signals.
- Hotspot identification combines code complexity metrics with Git churn to find high-risk areas that hinder development.
- Behavior-preserving refactoring extracts or merges modules while strictly maintaining public contracts and observable side effects.
- Anti-fragmentation filtering rejects refactors that would create thin wrappers or increase navigation overhead.
- Verification mapping identifies necessary test seams and uses native build/lint tools to validate every microstep.
How it works
- Map the topology by analyzing entry points, persistence boundaries, and dependency directions.
- Execute an audit to generate a hotspot report with action labels: LEAVE, WATCH, or REFACTOR.
- Establish a baseline by running existing tests and typechecks to ensure the refactor starts from a green state.
- Perform micro-refactors in controlled steps, such as isolating pure logic before moving mutable state.
Frameworks & tools
This skill is language-agnostic but works best with repositories that have established test suites and Git history. It integrates with your local npm, pytest, cargo, go test, or custom build scripts to verify changes.
Why this beats prompting it yourself
Generic prompts often lead to "death by a thousand helpers" or broken logic because they lack a formal protocol for behavior preservation. This skill enforces a rigorous anti-fragmentation test and requires explicit reasoning for every extraction, preventing the creation of shallow modules that only look clean on the surface.
Use cases
- Decomposing god classes that have grown to manage too many unrelated domain responsibilities.
- Fixing change amplification where one conceptual update requires edits across five different directories.
- Merging leaking abstractions that add cognitive load without providing meaningful information hiding.
- Auditing legacy code to identify natural seams for future microservices or module extractions.
Known limitations
Does not perform feature work, formatting sweeps, or security audits. Refactors may be limited if Git history is unavailable or if the codebase lacks automated verification tools.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Code Quality & Review.
Requires repository read access. Refactoring precision depends on existing test coverage. Skips performance tuning and stylistic changes. Stop conditions trigger if invariants are at risk.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 26 days ago
- Software
Git