Catalog
22 patterns, grouped by purpose.
Each card opens a tutorial: problem → step-by-step solution → structure → runnable demo → when not to use it.
Template Method
Pin down the order of an algorithm's steps in exactly one place and leave open only the steps that can vary. The GoF version opens them through inheritance; the modern JS version opens them through hooks/callbacks.
Strategy
Pull an algorithm that keeps changing out into separate objects (the "strategies"), and let the object that uses it pick one at runtime instead of hard-coding the choice with if/else.
Observer
Let many parties subscribe to "listen" to an event source; when the source changes state, it notifies all of them without knowing who is listening or how many there are.
Factory Method
Wrap the "which class do I new up" decision in a single method or function, so the call site only declares what it needs, and the choice of implementation is made at runtime by a subclass, config or registry.
Singleton
Guarantee that the whole process has exactly one instance, and expose a single door for getting it. In JS, ES modules already handle the "one instance" part, so the real value of the pattern lies elsewhere: controlling *when* the instance is born, *with which arguments*, and *who is allowed to replace it in tests*.
Decorator
Wrap an object in another object with exactly the same interface to add responsibilities (log, retry, cache, validate) around the call — the client does not know, and does not need to know, that it is holding the wrapped version.
Iterator
Traverse a collection without exposing how it is stored: array, map, tree, or pages of remote data. The outside only sees `next()` returning `{ value, done }`, and `for...of` runs on exactly that contract.
Adapter
Insert a translation layer at the boundary: it takes data and calls in someone else's shape (a third-party API, a legacy module, a DTO) and returns exactly your internal contract, so the core of the system only ever knows its own data types.
Command
Wrap a "thing to do" (its parameters, the object it acts on, how to do it, how to undo it) in an object, so you can queue it, log it, send it somewhere, retry it, replay it or undo it — instead of calling a function and losing all trace of it.
Composite
Give leaves and branches one shared interface in which every operation is defined recursively: a leaf answers directly, a branch answers by asking its children. Calling code can then handle a single element and an entire tree with exactly the same code.
Facade
Collapse a subsystem's scattered API into ONE API phrased in business language: the client calls one function, and call order, parameters, retries and logging are the facade's job.
State
Package each state of an object as its own set of behaviour, so the state itself decides which actions are valid and which state it moves to next — instead of making every other place guess from `status` with if/else.
Builder
Construct an object with many parameters (mostly optional) through an intermediate object that accumulates them step by step, then commit in build() — the one place that validates every constraint and produces a final object that is guaranteed to be valid.
Prototype
Create new objects by copying an existing template object instead of rebuilding an expensive configuration from scratch — and in JS/TS, the hard part isn't "cloning" but cloning *correctly*: shallow or deep, and whether the prototype, Maps/Sets, and circular references survive.
Proxy
Put a stand-in in front of the real object: the client holds the proxy and can't tell the difference, while the proxy decides when the real object gets touched, what gets touched, and whether it gets touched at all.
Abstract Factory
A single factory creates an entire family of related products (Button + Input + Card of the same theme), so the client can no longer accidentally mix products from two different families.
Bridge
Split a class that carries two independent axes of change into two separate hierarchies joined by composition (one side holds an interface reference to the other), so either side can gain new members without touching the other.
Chain of Responsibility
Pass a request through a series of handlers: each one either answers it and stops the chain, or calls `next` to push it along. Whoever sends the request doesn't need to know who will handle it.
Flyweight
Share the duplicated state across many objects instead of giving each object its own copy: the common part lives in one object reused by key, and the per-object part (external state) is passed in at the point of use.
Mediator
Pull all the communication logic between a group of objects into exactly one place, so the objects only talk to that place and never to each other.
Memento
Capture an object's state into a sealed package you can restore later, without forcing the object to expose its internal fields to whoever holds that package.
Visitor
Add new operations to a fixed tree of nodes without modifying any node: each node only declares "what kind I am", and all of the operation's logic lives in the visitor.
The full path
The order below goes from easiest to hardest and from most to least useful in real web projects. Go one by one, ~10-15 minutes each.
- Template MethodPin down the order of an algorithm's steps in exactly one place and leave open only the steps that can vary. The GoF version opens them through inheritance; the modern JS version opens them through hooks/callbacks.
- StrategyPull an algorithm that keeps changing out into separate objects (the "strategies"), and let the object that uses it pick one at runtime instead of hard-coding the choice with if/else.
- ObserverLet many parties subscribe to "listen" to an event source; when the source changes state, it notifies all of them without knowing who is listening or how many there are.
- Factory MethodWrap the "which class do I new up" decision in a single method or function, so the call site only declares what it needs, and the choice of implementation is made at runtime by a subclass, config or registry.
- SingletonGuarantee that the whole process has exactly one instance, and expose a single door for getting it. In JS, ES modules already handle the "one instance" part, so the real value of the pattern lies elsewhere: controlling *when* the instance is born, *with which arguments*, and *who is allowed to replace it in tests*.
- DecoratorWrap an object in another object with exactly the same interface to add responsibilities (log, retry, cache, validate) around the call — the client does not know, and does not need to know, that it is holding the wrapped version.
- IteratorTraverse a collection without exposing how it is stored: array, map, tree, or pages of remote data. The outside only sees `next()` returning `{ value, done }`, and `for...of` runs on exactly that contract.
- AdapterInsert a translation layer at the boundary: it takes data and calls in someone else's shape (a third-party API, a legacy module, a DTO) and returns exactly your internal contract, so the core of the system only ever knows its own data types.
- CommandWrap a "thing to do" (its parameters, the object it acts on, how to do it, how to undo it) in an object, so you can queue it, log it, send it somewhere, retry it, replay it or undo it — instead of calling a function and losing all trace of it.
- CompositeGive leaves and branches one shared interface in which every operation is defined recursively: a leaf answers directly, a branch answers by asking its children. Calling code can then handle a single element and an entire tree with exactly the same code.
- FacadeCollapse a subsystem's scattered API into ONE API phrased in business language: the client calls one function, and call order, parameters, retries and logging are the facade's job.
- StatePackage each state of an object as its own set of behaviour, so the state itself decides which actions are valid and which state it moves to next — instead of making every other place guess from `status` with if/else.
- BuilderConstruct an object with many parameters (mostly optional) through an intermediate object that accumulates them step by step, then commit in build() — the one place that validates every constraint and produces a final object that is guaranteed to be valid.
- PrototypeCreate new objects by copying an existing template object instead of rebuilding an expensive configuration from scratch — and in JS/TS, the hard part isn't "cloning" but cloning *correctly*: shallow or deep, and whether the prototype, Maps/Sets, and circular references survive.
- ProxyPut a stand-in in front of the real object: the client holds the proxy and can't tell the difference, while the proxy decides when the real object gets touched, what gets touched, and whether it gets touched at all.
- Abstract FactoryA single factory creates an entire family of related products (Button + Input + Card of the same theme), so the client can no longer accidentally mix products from two different families.
- BridgeSplit a class that carries two independent axes of change into two separate hierarchies joined by composition (one side holds an interface reference to the other), so either side can gain new members without touching the other.
- Chain of ResponsibilityPass a request through a series of handlers: each one either answers it and stops the chain, or calls `next` to push it along. Whoever sends the request doesn't need to know who will handle it.
- FlyweightShare the duplicated state across many objects instead of giving each object its own copy: the common part lives in one object reused by key, and the per-object part (external state) is passed in at the point of use.
- MediatorPull all the communication logic between a group of objects into exactly one place, so the objects only talk to that place and never to each other.
- MementoCapture an object's state into a sealed package you can restore later, without forcing the object to expose its internal fields to whoever holds that package.
- VisitorAdd new operations to a fixed tree of nodes without modifying any node: each node only declares "what kind I am", and all of the operation's logic lives in the visitor.