refactor-to-pattern

Refactor NestJS code to Clean Architecture and DDD patterns.

13|1|Updated Jun 28, 2023
One-click install
npx skills add https://github.com/jovicon/nestjs-clean-architecture-event-driven-template --skill refactor-to-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor-to-pattern
Source: https://github.com/jovicon/nestjs-clean-architecture-event-driven-template/tree/main/.claude/skills/refactor-to-pattern
Command: npx skills add https://github.com/jovicon/nestjs-clean-architecture-event-driven-template --skill refactor-to-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Refactor code to align with Clean Architecture and Domain-Driven Design patterns, turning messy implementations into well-structured, maintainable codebases.

Core Features & Use Cases

  • Pattern-driven refactoring: Introduce domain boundaries, use cases, and value objects to replace anemic models and scattered logic.
  • Controller-to-use-case migration: Move orchestration out of controllers and into dedicated use cases.
  • Domain-centric validation: Promote validation within domain factories and entities to enforce invariants.
  • Apply multiple patterns: Includes anemic-to-rich domain, primitive-obsession to value objects, and controller-logic-to-use-case migrations.

Quick Start

Run the refactor to pattern workflow on your NestJS project to replace anti-patterns with domain-driven design patterns.

Frequently Asked Questions about refactor-to-pattern

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

FAQPage Schema
How do I refactor a NestJS project to clean architecture?

Refactoring a NestJS project to clean architecture involves moving orchestration out of controllers into dedicated use cases, applying domain boundaries, and moving validation to domain factories to enforce invariants.

What's the best way to migrate controller logic to use cases in DDD?

Migrating controller logic to use cases requires extracting orchestration from controllers and placing it in dedicated use cases, ensuring domain methods return Result<T> objects and encapsulating domain logic properly.

How do I fix anemic domain models and primitive obsession in NestJS?

Fixing anemic domain models and primitive obsession involves refactoring to rich domain models by introducing value objects, domain boundaries, and enforcing invariants within domain factories and entities.

Can I use this clean architecture refactoring approach for non-NestJS projects?

This refactoring approach targets NestJS projects specifically, applying clean architecture and DDD patterns like domain encapsulation, use-case orchestration, and domain-centric validation to fix anti-patterns.

Why does domain validation need to move to domain factories?

Domain validation moves to domain factories to enforce invariants within the domain layer, replacing scattered validation logic and ensuring that domain entities remain consistent and valid upon creation.

When should I not use domain-driven design refactoring patterns?

Domain-driven design refactoring patterns may not suit simple CRUD applications or small-scale projects where the overhead of use cases, value objects, and domain boundaries outweighs maintainability benefits.