Design Patterns - Node.js Reference Map

// 23 Gang of Four patterns ยท Creational, structural, behavioral ยท Node.js examples

23 total patterns
Creational
Structural
Behavioral
01Creational Patterns- How objects are created without hard-coding construction everywhere
02Structural Patterns- How objects and modules are composed into larger shapes
03Behavioral Patterns- How objects communicate, delegate work, and manage behavior
โ›“๏ธChain of Responsibilitybehavioral
Pass a request through handlers until one handles it.
Request -> auth -> validation -> controller -> response
e.g.: Express middleware, Koa middleware, error pipelines
๐Ÿ“ฆCommandbehavioral
Wrap an action as an object so it can be queued, logged, or undone.
Client creates command -> queue/log/execute -> optional undo
e.g.: BullMQ jobs, task queues, undo stacks
๐Ÿ—ฃ๏ธInterpreterbehavioral
Represent grammar rules and evaluate expressions.
Input expression -> parse rules -> evaluate AST
e.g.: Template engines, rule engines, query parsers
๐Ÿ”Iteratorbehavioral
Traverse a collection without exposing how it is stored.
Collection -> iterator.next() -> item by item
e.g.: for...of, async iterators, streams
๐ŸŽ›๏ธMediatorbehavioral
Centralize communication so objects do not talk directly to each other.
Component A -> Mediator -> Component B/C
e.g.: Event bus, message broker wrappers, NestJS CQRS bus
๐Ÿ’พMementobehavioral
Capture and restore object state without exposing internals.
state now -> save snapshot -> changes -> restore snapshot
e.g.: Undo history, drafts, editor snapshots
๐Ÿ‘€Observerbehavioral
Notify subscribed listeners when state changes.
Subject emits event -> listener A -> listener B -> listener C
e.g.: EventEmitter, RxJS, DOM events, Redis pub/sub
๐ŸšฅStatebehavioral
Change behavior when an object changes internal state.
Order: pending -> paid -> shipped -> delivered
e.g.: Workflow engines, XState, order lifecycles
โ™Ÿ๏ธStrategybehavioral
Swap algorithms at runtime without changing the caller.
Context -> strategy.pay() -> Stripe / PayPal / Razorpay
e.g.: Passport strategies, payment strategies, sorting strategies
๐Ÿ“‹Template Methodbehavioral
Define an algorithm skeleton and let subclasses fill in steps.
generate() -> fetch -> format -> render steps vary
e.g.: Report generators, test runners, ETL jobs
๐ŸงณVisitorbehavioral
Add operations to object structures without changing those objects.
Visitor -> visitUser() -> visitOrder() -> visitInvoice()
e.g.: AST transforms, Babel plugins, tree walkers
Design patterns are code-structure patterns. They help objects and modules stay flexible, but they should be used when they simplify real change, not just to make code look formal.