refactor-service

Refactors a single NestJS service through phased cleanup, async migration, and decomposition.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Large NestJS service files accumulate technical debt: promise chains, console.log calls, raw SQL injection risks, duplicated logic, and god-classes mixing many concerns. This Skill applies a structured, phase-gated refactoring process that cleans up one service file at a time without breaking the build. ## Core Features & Use Cases - Phased refactoring with verification gates: Discovery, async/await migration, code cleanup, error handling and SQL safety, optional decomposition, and reporting — each phase ends with a build + ESLint + Prettier gate and a self-healing retry loop. - Auto-detected service decomposition: Analyzes line count, dependency injections, and concern groupings to recommend splitting a service into a facade plus sub-services, with --no-split and --force-split overrides. - SQL safety and simplification: Parameterizes unsafe raw queries, replaces inline SQL with existing stored procedures, and converts simple queries to TypeORM find() or QueryBuilder. - Use Case: Run it on a 1,500-line NestJS service full of .then() chains and interpolated SQL; it migrates to async/await, replaces console.log with NestJS Logger, parameterizes queries, extracts interfaces and constants, and produces a change report. ## Quick Start Ask Claude Code to run /refactor-service on a target service, for example: refactor the review service in my NestJS backend.

Frequently Asked Questions about refactor-service

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

FAQPage Schema
How do I refactor a large NestJS service file?

Run the refactor-service skill with the service name, for example /refactor-service review. It discovers baseline metrics, migrates promise chains to async/await, cleans up dead code and console.log calls, standardizes error handling, and optionally splits the service into a facade plus sub-services.

How to convert .then() promise chains to async/await in TypeScript?

The skill converts each .then()/.catch() chain into try/catch with await, marks the containing method async, and uses typed unknown errors with getErrorMessage helpers. It also fixes fire-and-forget patterns like .map(async ...) by wrapping them in Promise.all.

When does the skill split a NestJS service into sub-services?

Decomposition is recommended when a service exceeds 700 lines and has at least three distinct concern groups. You can override detection with --no-split or --force-split, and already-decomposed sub-services are automatically skipped.

Does it fix SQL injection risks in raw TypeORM queries?

Yes. It detects raw .query() calls using string interpolation and rewrites them with parameter binding (@0, @1 syntax). It can also replace large inline SQL blocks with matching existing stored procedures, but never creates new stored procedures.

What happens if the build fails during refactoring?

Every phase ends with a verification gate running npm build, ESLint, and Prettier. On failure the skill enters a self-healing loop that fixes only the reported errors and retries up to three times before stopping and asking for guidance.