pattern-decorator

Wrap NestJS providers with decorator layers to add logging, caching, or metrics.

Updated Mar 26, 2026
One-click install
npx skills add https://github.com/johnnystefan/test-saas-business --skill pattern-decorator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pattern-decorator
Source: https://github.com/johnnystefan/test-saas-business/tree/main/skills/design-patterns/structurals/pattern-decorator
Command: npx skills add https://github.com/johnnystefan/test-saas-business --skill pattern-decorator

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The decorator pattern skill keeps you from modifying existing classes when new behaviors are needed, letting you compose responsibilities with runtime wrappers and preserving the original component contracts.

Core Features & Use Cases

  • Flexible Behavior Composition: Create decorator classes that wrap a core component and add logging, caching, retries, or metrics without altering the wrapped implementation.
  • Shared Interface Contract: Define a common interface so both the base object and decorators can be used interchangeably throughout the application.
  • Use Case: Wrap a PrismaRepository with CachedRepository and then layer LoggedUseCase to add caching and observability around a NestJS provider while keeping the provider code untouched.

Quick Start

Use the decorator pattern skill to wrap a notifier when you need to add logging without modifying the notifier class.

Frequently Asked Questions about pattern-decorator

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

FAQPage Schema
How do I add logging or caching to a NestJS provider without modifying its class?

To add logging or caching to a NestJS provider without modifying its class, wrap the provider in decorator layers that implement a shared interface, injecting new runtime behaviors while delegating execution to the base component.

What is the decorator pattern for adding runtime behaviors in TypeScript?

The decorator pattern for adding runtime behaviors in TypeScript wraps objects in layers that share an interface, allowing you to compose responsibilities like metrics and retries around a base component without altering its class definition.

How do I wrap a repository with caching and logging in NestJS?

To wrap a repository with caching and logging in NestJS, define a shared interface contract and create chained decorator classes like CachedRepository and LoggedUseCase that delegate to the base object while adding functionality.

Does the decorator pattern require a shared interface for behavior composition?

Yes, the decorator pattern requires a shared interface contract so both the base object and its wrappers can be used interchangeably throughout the application, ensuring decorators can delegate calls to the core component seamlessly.

When should I use the decorator pattern instead of modifying existing classes?

Use the decorator pattern instead of modifying existing classes when you need to compose new responsibilities like retries or metrics at runtime while preserving the original component contracts and keeping the wrapped implementation untouched.

Can I layer multiple decorators like caching and observability around a single use case?

You can layer multiple decorators like caching and observability around a single use case by building a decorator chain where each wrapper delegates to the base component while injecting its specific functionality.