amirtaherkhani/nestjs-skills

nestjs-oop-design-patterns

Applies pragmatic OOP, SOLID, object-design rules, and design patterns to NestJS and TypeScript code.

소스 보기

사용 방법

  1. 설치 명령을 복사하고 자신의 에이전트 환경에 설치하기 전에 소스 패키지를 확인하세요.
  2. 필요한 도구, 인증 정보, 지원 환경은 원본 문서에서 확인하세요.
  3. 입력과 원하는 산출물을 설명하고 출처와 결과를 대조하세요.
npx skills add https://github.com/amirtaherkhani/nestjs-skills --skill nestjs-oop-design-patterns

시작 전 확인

  • 설치에는 모델 구독, API 한도, 파일 접근 권한이 포함되지 않습니다.
  • 별점 수와 설치 수는 활동 지표이며 독립적인 품질·보안 검증이 아닙니다.
원본 Skill 문서

원본 저장소의 제목, 예시, 코드, 표, 링크, 이미지를 유지해 표시합니다.

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 pattern is "scalable" is not evidence that the current repository needs it.

SignalConsiderAvoid when
Same operation, real interchangeable algorithmsStrategyOne stable algorithm
Construction varies by configuration/typeFactoryConstructor is already simple
Complex construction has ordered or optional validated stepsBuilderAn object literal or constructor stays clear
Vendor model leaks into application codeAdapterLibrary API is already isolated at the edge
Abstraction and implementation have two independent variation axesBridgeAdapter or Strategy handles the only variation
Complex subsystem needs a narrow entry pointFacade/application serviceIt becomes an unrelated god service
A stable workflow has a few deliberate extension stepsTemplate Method or composed pipelineInheritance would be the only reason to use it
Cross-cutting request behaviorInterceptor, guard, pipe, filterCore business policy belongs in a domain/application object
Independent reactions to a completed factDomain/integration eventCaller requires an immediate transactional result
Explicit use-case messages add valueCommand/query handlerBasic CRUD gains only indirection
Reliable event publication with a DB writeTransactional outboxBest-effort in-process notification is sufficient

Before applying a pattern, state the problem, why a direct solution is insufficient, and the added operational or cognitive cost.

Refactoring workflow

  1. Lock current behavior with focused tests.
  2. Mark responsibilities and effects in the current code.
  3. Move misplaced behavior to its owner before extracting abstractions.
  4. Extract one seam around the observed variation or boundary.
  5. Rewire through Nest providers without changing the public contract unnecessarily.
  6. Remove obsolete branches, wrappers, and abstractions.
  7. Run unit, module, integration, and e2e checks in proportion to the changed boundary.

Use references/smells-refactoring.md for symptom-to-refactoring guidance.

Testing rules

  • Test public behavior and invariants, not private method calls.
  • Use plain unit tests for domain objects and policies.
  • Instantiate a use case directly when constructor dependencies are simple; use TestingModule when Nest wiring or provider overrides are what the test must prove.
  • Mock or fake boundaries you own, not the class under test.
  • Add contract tests when several adapters implement the same port.
  • Keep e2e tests for transport, validation, authorization, serialization, and real module wiring.

TDD is useful when behavior can be expressed incrementally, but do not falsely claim a red test was written first when changing an existing implementation. Match the repository's requested workflow.

Reject rigid pseudo-rules

Do not enforce arbitrary limits such as ten-line methods, fifty-line classes, two fields per object, mandatory value objects for every primitive, or no else statements. Use them only as prompts to inspect cohesion and readability.

Do not force:

  • inheritance where composition is clearer;
  • a repository wrapper over an already suitable persistence boundary;
  • factories for one straightforward constructor;
  • domain events for synchronous return values;
  • DTO reuse across unrelated external contracts;
  • a generic BaseService<T> that erases feature-specific invariants.

Reference routing

TaskLoad
Apply encapsulation, composition, polymorphism, or SOLIDoop-solid.md
Design entities, value objects, policies, services, and DTO mappingobject-design.md
Select patterns using 19 practical examples, Nest wiring, tradeoffs, and behavioral checkspattern-catalog.md
Map patterns to Nest modules, providers, guards, pipes, interceptors, filters, and CQRSnestjs-native-patterns.md
Diagnose smells and choose a safe refactorsmells-refactoring.md

Expected response

For a design or review, report:

  • Role and responsibility: what the object should own.
  • Evidence: the concrete coupling, invariant leak, or change pressure.
  • Pattern or direct design: one recommendation and why it fits.
  • Trade-off: indirection, lifecycle, consistency, or testing cost introduced.
  • Change: smallest safe refactor.
  • Verification: behavior and contract checks.

If a pattern is not justified, recommend the direct implementation.

같은 저장소의 Skills

더 많은 Skills

모든 Skills
amirtaherkhani
커뮤니티

nestjs-architecture-principles

Designs and reviews NestJS application architecture using cohesive feature modules, modular monoliths, layered or hexagonal boundaries, dependency inversion, and pragmatic engineering principles. Use when planning a NestJS project, changing module boundaries, evaluating Clean Architecture or DDD, resolving circular dependencies, defining ports and adapters, reviewing coupling, or deciding whether CQRS or microservices are justified. Do not use for pure frontend work or non-NestJS backends. When

1시간 설치 수
1
GitHub Stars
13
업데이트
10월 16일
amirtaherkhani
커뮤니티

nestjs-code-audit

Audits an existing NestJS repository with bundled semantic guidance and optional specialist skills and returns one prioritized, evidence-backed code-quality report. Use when asked to check a whole NestJS codebase or a scoped folder for syntax, TypeScript, lint, module-boundary, dependency, design-smell, security, testing, performance, reliability, or production-readiness problems. This is a read-only review workflow: it does not fix code, install dependencies, run migrations, or deploy. When oth

1시간 설치 수
1
GitHub Stars
13
업데이트
10월 16일
amirtaherkhani
커뮤니티

nestjs-feature-audit

Audits one NestJS feature against its documented roadmap on a specific Git branch and returns an evidence-backed implementation, gap, legacy, bug, and blocker report. Use when asked to audit a feature, validate feature completeness, compare code with a roadmap or acceptance plan, run a feature gap analysis, review migration status, or invoke /auditfeature with a feature name and optional branch. It stops when no clear roadmap is available and does not implement fixes. When other skills also appl

1시간 설치 수
1
GitHub Stars
13
업데이트
10월 16일
amirtaherkhani
커뮤니티

nestjs-features-performance

Selects and implements NestJS runtime features, error and API contracts, security, testing, DevOps, performance, and safe scale. Use for middleware, guards, pipes, interceptors, exception filters, typed failures/results, Problem Details, validation errors, HTTP/GraphQL/RPC/gRPC/WebSocket error mapping, deadlines, cancellation, retry classification, fatal process errors, authentication, authorization, caching, queues, schedulers, CI/CD, containers, Kubernetes, configuration and secrets, migration

1시간 설치 수
1
GitHub Stars
13
업데이트
10월 16일