跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
设计与 UI

nestjs-oop-design-patterns

Applies pragmatic OOP, SOLID, object-design rules, and design patterns to NestJS and TypeScript code. Use when writing or refactoring controllers, providers, use cases, entities, value objects, repositories, adapters, factories, strategies, handlers, or tests; when diagnosing god services, primitive obsession, inheritance misuse, duplicated conditionals, or leaky abstractions; and when selecting a pattern without over-engineering. Do not use for pure functional codebases or non-NestJS frontend work. When other skills also apply, reconcile ownership before mutation.

amirtaherkhani · 已有静态检查记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add amirtaherkhani/nestjs-skills --skill nestjs-oop-design-patterns

技能说明


name: nestjs-oop-design-patterns description: 'Applies pragmatic OOP, SOLID, object-design rules, and design patterns to NestJS and TypeScript code. Use when writing or refactoring controllers, providers, use cases, entities, value objects, repositories, adapters, factories, strategies, handlers, or tests; when diagnosing god services, primitive obsession, inheritance misuse, duplicated conditionals, or leaky abstractions; and when selecting a pattern without over-engineering. Do not use for pure functional codebases or non-NestJS frontend work. When other skills also apply, reconcile ownership before mutation.' license: MIT metadata: author: amirtaherkhani version: '1.2.0'

NestJS OOP and Design Patterns

Improve changeability and correctness through clear responsibilities, encapsulated invariants, and deliberate collaboration. Use patterns to solve observed forces, never as decoration.

Pre-execution conflict guard

Before editing files or running any state-changing command, reconcile active instructions. Read-only inspection may continue.

Prerequisites

Inspect repository instructions, installed versions, callers, tests, module wiring, and the observed design pressure. Preserve behavior and user changes; do not select a pattern before architecture/runtime constraints are known. Read other active skills only when their decisions overlap.

Primary ownership

This skill owns object responsibilities, invariants, encapsulation, collaborator contracts, SOLID trade-offs, patterns, and behavior-preserving refactoring. When installed and relevant, coordinate with:

  • nestjs-architecture-principles: module, dependency, data, and transaction boundaries.
  • nestjs-features-performance: lifecycle, API/security, testing, runtime, and performance.
  • nestjs-professional-software-engineering: implementation and verification.
  • nestjs-code-audit: read-only quality evidence and deduplicated reporting.
  • nestjs-feature-audit: branch-specific roadmap gate and feature reporting.
  • nestjs-git-commit-pr-message: authorized Git publication and CI follow-up.

These are decision boundaries, not required dependencies. Retain domain ownership when handing work to another workflow.

Conflict test

Check for incompatible edits/contracts, command order or side effects, competing owners, and unmet version, evidence, authorization, or repository prerequisites. Resolve using explicit user intent, repository contracts, verified runtime constraints, then the narrowest owner. Assign one lead per decision; do not create parallel designs to satisfy incompatible advice. If a material conflict remains, stop before mutation and ask for the smallest missing decision. Audits stay read-only; explicit fix authorization applies in a distinct implementation phase.

Inspect before prescribing

  1. Read the relevant controller/provider/entity plus its callers, tests, module wiring, DTOs, and persistence mapping.
  2. Identify the object's role: transport adapter, application coordinator, domain object/policy, infrastructure adapter, or composition root.
  3. Name the actual pain: invariant leakage, divergent change, difficult substitution, hidden dependency, duplicated decision logic, or framework coupling.
  4. Check repository conventions and existing abstractions before adding a new one.
  5. Preserve behavior with a characterization test before a risky refactor.

Do not infer poor design from file length alone. Complexity, cohesion, public surface, dependency count, and change history are stronger evidence.

OOP defaults

  • Encapsulate invariants; do not merely move data behind getters and setters.
  • Prefer composition and delegation over inheritance.
  • Keep mutable state private and minimize its lifetime.
  • Use polymorphism when a stable operation has real, varying implementations.
  • Inject effects and volatility; keep deterministic calculations plain.
  • Make invalid states difficult to construct when the domain value justifies the type.
  • Use domain language consistently across types, methods, tests, and errors.
  • Let Nest's container construct providers; do not instantiate dependency graphs inside business methods.

Load references/oop-solid.md for detailed OOP and SOLID guidance and references/object-design.md for entities, value objects, policies, services, and DTO boundaries.

Apply SOLID as diagnostic questions

Single Responsibility

Does this unit own one cohesive policy or change axis? A use case may coordinate several collaborators and still have one responsibility. Splitting every method into a provider creates navigation cost without cohesion.

Open/Closed

Is a real variation forcing the same conditional to change repeatedly? Extract a strategy, policy, or adapter around that variation. Do not build extension points for hypothetical providers.

Liskov Substitution

Can every implementation honor the same inputs, outputs, errors, side effects, timing assumptions, and invariants? If not, narrow the contract or use composition instead of inheritance.

Interface Segregation

Does each consumer depend only on the capability it uses? Prefer small application-owned ports over one CommonService or generic repository interface.

Dependency Inversion

Does high-level policy depend on an application contract while Nest modules select infrastructure implementations? Add a boundary for volatile effects, not an interface for every local class.

Select patterns from forces

Use references/pattern-catalog.md and references/nestjs-native-patterns.md.

Treat pattern catalogs as discovery aids, not implementation checklists. Architecture styles, framework lifecycle mechanisms, provider lifetimes, and GoF object patterns solve different kinds of problems even when an article groups them together. Popularity, familiarity, or a claim that a patt

阅读完整来源 ↗