refactor-module

Refactors an entire NestJS feature module through phased cleanup with build and lint verification gates.

Updated Jul 9, 2026
One-click install
npx skills add https://github.com/MadheshSM/learning --skill refactor-module-madheshsm
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor-module
Source: https://github.com/MadheshSM/learning/tree/main/Node/.claude/backend/skills/refactor-module
Command: npx skills add https://github.com/MadheshSM/learning --skill refactor-module-madheshsm

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Large NestJS feature modules accumulate dead code, any types, console statements, duplicated logic, and inconsistent naming over time, and manual cleanup is error-prone because each change can break the build. This Skill performs a deep, context-aware refactor of an entire module in controlled phases, with a build and ESLint verification gate after every phase so breakage never cascades. ## Core Features & Use Cases - Phased refactoring pipeline: Nine phases covering dead code removal, type safety (eliminating any/unknown, extracting inline interfaces), console-to-Logger replacement, magic string/number extraction, error handling audits, SQL parameterization, duplicate code extraction, naming conventions, and NestJS best practices. - Verification gates with self-healing: Every phase ends with npm run build plus ESLint on touched files, with an automatic fix-and-retry loop (max 3 attempts) before stopping to report. - Discovery report before changes: Phase 0 is read-only, producing a full issue inventory and planned actions that require user confirmation before any code is modified. - Use Case: Run /refactor-module review on a legacy NestJS module to remove unused imports, replace throw new Error() with proper HttpExceptions, parameterize unsafe raw SQL, and receive a dated markdown report of all changes and metrics. ## Quick Start Ask the assistant to run /refactor-module followed by your module name, for example: refactor the dashboard module and confirm the discovery report before applying changes.

Frequently Asked Questions about refactor-module

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor a NestJS module without breaking the build?

Run /refactor-module with the module name, and it applies changes in nine small phases. After each phase it runs npm run build and ESLint on touched files, automatically fixing failures up to three times before stopping, so breakage never cascades across phases.

What code issues does this NestJS refactoring skill detect?

It detects dead code, unused imports, any/unknown type usage, missing return types, console statements, magic strings and numbers, TODO comments, poor error handling, naming violations, SQL injection risks in raw queries, and duplicated logic across services.

Does it change code automatically or ask for confirmation first?

Phase 0 is strictly read-only: it inventories all module files, detects issues, and prints a discovery report with planned actions. No code is modified until the user reviews the report and confirms to proceed.

Can it fix unsafe raw SQL queries in TypeORM?

Yes, it finds .query() calls using string interpolation and converts them to parameterized queries with bound parameters. It only parameterizes existing SQL and does not convert raw SQL to QueryBuilder or create new stored procedures.

What happens if a verification gate keeps failing?

The gate retries fixes up to three times, targeting only the reported file, line, and rule failures. If it still fails after three attempts, the skill stops, reports exactly what is broken, and asks the user for guidance instead of proceeding.

When should I use refactor-module versus refactor-service?

Use refactor-module for whole-module cleanup across all files. If a single service has grown too large, such as more than 15 constructor dependencies, the skill flags it for decomposition with the separate /refactor-service skill instead.