refactor-nestjs_skill

This skill refactors NestJS/TypeScript code to improve maintainability and SOLID adherence, addressing circulars, god objects, and SRP violations across

6

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill snakeo/claude-debug-and-refactor-skills-plugin --skill refactor-nestjs

  • SKILL.md17.9 KB

Overview

This skill refactors NestJS and TypeScript server-side code to improve maintainability, readability, and adherence to SOLID principles. It identifies and resolves circular dependencies, god-object services, fat controllers, deep nesting, and SRP violations, then applies proven NestJS patterns to produce clean, testable implementations.

How this skill works

I analyze the codebase to detect dependency cycles, large services, duplicated logic, and missing architectural patterns. Refactors are planned and executed incrementally: extract responsibilities into modules, repositories, services, guards, pipes, interceptors, DTOs, and exception filters, and introduce CQRS or event-driven flows where appropriate. Tests and documentation updates accompany each change to prevent regressions and communicate breaking changes.

When to use it

  • Codebase exhibits circular imports or runtime dependency errors
  • Controllers contain business logic or services have too many responsibilities
  • High technical debt: duplicated code, deep nesting, or large functions
  • You need to introduce DTO validation, exception handling, or request-scoped data
  • Preparing code for scale, microservices, or CQRS/event-driven design

Best practices

  • Break features into focused feature modules and export only needed providers
  • Keep controllers thin; move business logic to services and data access to repositories
  • Use DTOs with class-validator/class-transformer and global or controller-level pipes
  • Prefer early returns and guard clauses to avoid deep nesting
  • Introduce interceptors for cross-cutting concerns and exception filters for consistent error responses
  • Apply provider scopes judiciously; avoid injecting request-scoped providers into singletons

Example use cases

  • Split a monolithic UserService into UserService, UserRepository, and UserMapper to enforce SRP
  • Resolve circular module imports by extracting shared contracts and using forwardRef only when unavoidable
  • Convert fat controller endpoints into commands/queries using NestJS CQRS for complex workflows
  • Introduce ValidationPipe+DTOs and a global AllExceptionsFilter to standardize API errors
  • Replace duplicated auditing logic with a LoggingInterceptor and a reusable AuditService

FAQ

I prioritize non-breaking changes; when API changes are required I document breaking changes and provide migration guidance and tests.

How do you handle circular dependencies?

I map dependency graphs, extract shared modules or interfaces, convert to provider tokens, or apply forwardRef sparingly while aiming to eliminate cycles.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational