typescript-design-patterns/SKILL.md
All 23 GoF design patterns implemented in TypeScript — Creational (Singleton, Factory Method, Abstract Factory, Builder, Prototype, Object Pool), Structural (Adapter, Composite, Proxy, Flyweight, Bridge, Decorator, Facade), Behavioral (Strategy...
npx skillsauth add peterbamuhigire/skills-web-dev typescript-design-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
typescript-design-patterns or would be better handled by a more specific companion skill.SKILL.md first, then load only the referenced deep-dive files that are necessary for the task.All 23 GoF patterns + Object Pool. Use TypeScript interfaces and generics to make patterns type-safe and self-documenting.
When: Exactly one instance needed globally (logger, DB connection, config).
class Logger {
private static instance: Logger;
private constructor() {}
static getInstance(): Logger {
if (!Logger.instance) Logger.instance = new Logger();
return Logger.instance;
}
log(msg: string) { console.log(`[${new Date().toISOString()}] ${msg}`); }
}
const logger = Logger.getInstance(); // same instance everywhere
When: Subclasses decide which class to instantiate; client uses the abstract type.
interface Document { open(): void; save(): void; }
class WordDocument implements Document {
open() { console.log('Opening Word doc'); }
save() { console.log('Saving Word doc'); }
}
class PdfDocument implements Document {
open() { console.log('Opening PDF'); }
save() { console.log('Saving PDF'); }
}
abstract class DocumentCreator {
abstract createDocument(): Document;
openDocument() { this.createDocument().open(); }
}
class WordCreator extends DocumentCreator {
createDocument(): Document { return new WordDocument(); }
}
When: Create families of related objects that must be compatible (e.g., cross-platform UI).
interface Button { render(): void; }
interface Checkbox { render(): void; }
interface UIFactory { createButton(): Button; createCheckbox(): Checkbox; }
class WindowsFactory implements UIFactory {
createButton(): Button { return { render: () => console.log('Windows button') }; }
createCheckbox(): Checkbox { return { render: () => console.log('Windows checkbox') }; }
}
class MacFactory implements UIFactory {
createButton(): Button { return { render: () => console.log('Mac button') }; }
createCheckbox(): Checkbox { return { render: () => console.log('Mac checkbox') }; }
}
function renderUI(factory: UIFactory) {
factory.createButton().render();
factory.createCheckbox().render();
}
When: Constructing complex objects step-by-step; same construction process, different representations.
interface Computer { cpu: string; ram: number; storage: number; gpu?: string; }
class ComputerBuilder {
private computer: Partial<Computer> = {};
setCPU(cpu: string) { this.computer.cpu = cpu; return this; }
setRAM(ram: number) { this.computer.ram = ram; return this; }
setStorage(gb: number) { this.computer.storage = gb; return this; }
setGPU(gpu: string) { this.computer.gpu = gpu; return this; }
build(): Computer { return this.computer as Computer; }
}
const pc = new ComputerBuilder()
.setCPU('Intel i9').setRAM(32).setStorage(1000).setGPU('RTX 4090').build();
When: Clone existing objects without coupling to their concrete classes.
interface Cloneable<T> { clone(): T; }
class ProductConfig implements Cloneable<ProductConfig> {
constructor(public name: string, public price: number, public tags: string[]) {}
clone(): ProductConfig {
return new ProductConfig(this.name, this.price, [...this.tags]);
}
}
const base = new ProductConfig('Widget', 9.99, ['sale']);
const variant = base.clone();
variant.price = 12.99; // base unchanged
When: Expensive objects (DB connections, threads) — reuse instead of create/destroy.
class ObjectPool<T> {
private available: T[] = [];
constructor(private factory: () => T, size: number) {
for (let i = 0; i < size; i++) this.available.push(factory());
}
acquire(): T {
return this.available.pop() ?? this.factory();
}
release(obj: T) { this.available.push(obj); }
}
// const pool = new ObjectPool(() => new DBConnection(), 5);
// const conn = pool.acquire();
// ... use conn ...
// pool.release(conn);
Extended guidance for typescript-design-patterns was moved to references/skill-deep-dive.md to keep this entrypoint compact and fast to load.
Use that deep dive for:
STRUCTURAL — Composing objects and classesBEHAVIORAL — Object communication and responsibilityPattern Selection Guidedata-ai
Use when adding AI-powered analytics to a SaaS platform — semantic search over business data, natural language queries, trend detection, anomaly alerts, and AI-generated insights for dashboards. Covers embeddings, NL2SQL, and per-tenant analytics...
data-ai
Design AI-powered analytics dashboards — what metrics to show, how to display AI predictions and confidence, drill-down patterns, KPI cards, trend visualisation, AI Insights panels, export design, and role-based dashboard variants. Invoke when...
development
Use when designing, building, reviewing, or upgrading production software systems that must be secure, performant, maintainable, scalable, and user-centered. Apply before writing specs, code, architecture, APIs, databases, mobile apps, SaaS platforms, or ERP systems.
development
Professional web app UI using commercial templates (Tabler/Bootstrap 5) with strong frontend design direction when needed. Use for CRUD interfaces, dashboards, admin panels with SweetAlert2, DataTables, Flatpickr. Clone seeder-page.php, use...