design-patterns

A guide to common software design patterns, which are reusable ways to organize code around recurring design problems.

In plain words
What is it for?
Use it to design or review code with patterns such as Factory, Builder, Adapter, Decorator, Facade, Proxy, Command, or Chain of Responsibility.
Why use it?
It helps choose or review structures that reduce tight coupling and make changing code easier, while avoiding patterns that do not fit the problem.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/booklib-ai/booklib/design-patterns
Any agent
npx skills add booklib-ai/booklib --skill design-patterns
Clone the repo
git clone --depth 1 https://github.com/booklib-ai/booklib

Made for: Claude Code, Codex.

Per session 200 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,181 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00200 $0.03181
Opus 5 $0.00100 $0.01590
Sonnet 5 $0.00040 $0.00636
Haiku 4.5 $0.00020 $0.00318

Measured 2d ago against content hash 997e1f7e859b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

design-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

The scan reads SKILL.md. This mod also ships 2 executable files (scripts/example.py, scripts/scaffold.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/design-patterns/SKILL.md · 272 lines

How it starts

The opening of the file, as written. The whole thing — 272 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Design Patterns Skill

You are an expert software designer grounded in the 23 Gang of Four design patterns as taught in Head First Design Patterns by Eric Freeman & Elisabeth Robson. You help developers in two modes:

  1. Code Generation — Produce well-structured code that applies the right pattern(s)
  2. Code Review — Analyze existing code and recommend pattern-based improvements

How to Decide Which Mode

  • If the user asks you to build, create, generate, implement, design, or refactor something → Code Generation
  • If the user asks you to review, check, improve, audit, critique, or identify patterns in code → Code Review
  • If ambiguous, ask briefly which mode they'd prefer

Mode 1: Code Generation

When generating code using design patterns, follow this decision flow:

Step 1 — Understand the Design Problem

Ask (or infer from context) what the design needs:

  • What varies? — Identify the aspects that change so you can encapsulate them
  • What's rigid? — Find tightly coupled code or areas that resist change
  • What are the forces? — Flexibility, extensibility, testability, simplicity?
  • Language/framework — What language and constraints apply?

Step 2 — Select the Right Pattern

Read references/patterns-catalog.md for full pattern details. Quick decision guide:

Design Problem Patterns to Consider
Algorithm or behavior varies at runtime Strategy (Context stores a strategy reference as a field; behavior swapped by setting a different strategy object)
Objects need to be notified of state changes Observer (subject maintains subscriber list, push/pull notification)
Add responsibilities dynamically without subclassing Decorator (wrap objects with additional behavior, same interface)
Object creation varies or is complex Factory Method (subclass decides), Abstract Factory (families of related objects), Builder (step-by-step construction)
Ensure only one instance exists globally Singleton (private constructor, thread-safe access)
Encapsulate requests as objects for undo/queue/log Command (receiver, command, invoker; supports undo/redo, macro commands)
Convert an incompatible interface Adapter (wrap adaptee, translate interface calls)
Simplify a complex subsystem interface Facade (unified high-level interface, reduce coupling)
Define algorithm skeleton, let subclasses fill steps Template Method (abstract base with hooks, Hollywood Principle)
Traverse a collection without exposing internals Iterator (uniform traversal, Single Responsibility Principle)
Treat individual objects and compositions uniformly Composite (tree structure, component/leaf/composite roles)
Object behavior changes based on internal state State (delegate to state objects, eliminate conditionals)
Control access to an object Proxy (remote, virtual, protection proxy patterns)
Decouple abstraction from implementation Bridge (two hierarchies vary independently)
Share common state across many objects Flyweight (intrinsic vs extrinsic state, factory-managed pool)
Pass request along a chain of potential handlers Chain of Responsibility (decouple sender and receiver)
Build interpreter for a simple language/grammar Interpreter (grammar rules as classes, recursive evaluation)
Centralize complex inter-object communication Mediator (objects communicate through mediator, not directly)
Capture and restore object state without violating encapsulation Memento (originator creates, caretaker stores)
Create objects by cloning existing instances Prototype (clone from registry, avoid costly construction)
Add operations to class structures without modifying them Visitor (double dispatch, new operations without changing element classes)
Combine multiple patterns for rich architecture MVC (Strategy + Observer + Composite), Compound Patterns

Read the full file on GitHub · 272 lines

Files

What ships with it

10 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 272 lines · 200 tokens per session scan A 997e1f7e859b

Subscribe to this mod's changes

design-patterns is a skill published in the GitHub repository booklib-ai/booklib (38 stars, last pushed 4mo ago), licensed MIT. It adds 200 tokens to every session and 3,181 once invoked, about $0.0010 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

project-spine-kickoff

Use when the user wants to set up Project Spine for a new project — phrases like "new client project", "kickoff", "create AGENTS.md from scratch", "generate agent instructions for this repo", "set up project context". Runs spine init → edits brief → spine compile → reviews outputs. For stale files use…

PetriLahdelma/project-spine · 84 tokens

project-spine

Use when the user mentions AGENTS.md, CLAUDE.md, copilot-instructions, Cursor rules, project brief, context for coding agents, agency kickoff, onboarding a new project, or asks "how do I set up Project Spine". This is the orientation skill — reach for it FIRST when the user's intent involves Project Spine, then chain…

PetriLahdelma/project-spine · 80 tokens

project-spine-drift

Use when the user mentions drift, says AGENTS.md / CLAUDE.md / copilot-instructions / Cursor rules are "stale" or "out of date", asks about CI catching docs drift, or says "check if my spine is still current". Runs spine drift check, interprets each drift category, and guides resolution. For initial setup use…

PetriLahdelma/project-spine · 87 tokens

project-spine-template

Use when the user wants to apply a bundled, user-local, or project-local template to a new project, or save the current project as a reusable template. Phrases like "use our agency starter", "save this as a template for future clients", "apply the shared saas-marketing starter".

PetriLahdelma/project-spine · 66 tokens

project-spine-rationale

Use when the user wants to review, polish, or share the generated Project Spine rationale file locally. Phrases like "show the project rationale", "send the client a project summary", "review rationale.md", or "make the client-facing overview safer".

PetriLahdelma/project-spine · 57 tokens

project-spine-workspace

Use when the user asks about Project Spine hosted workspaces, team sync, shared workspace templates, invites, or commands such as spine login, spine workspace, spine publish, or spine drift check --push.

PetriLahdelma/project-spine · 55 tokens