mediator-pattern

Installation
SKILL.md

Mediator/Middleware Pattern

The mediator pattern makes it possible for components to interact with each other through a central point: the mediator. Instead of directly talking to each other, the mediator receives the requests, and sends them forward! In JavaScript, the mediator is often nothing more than an object literal or a function.

You can compare this pattern to the relationship between an air traffic controller and a pilot. Instead of having the pilots talk to each other directly, which would probably end up being quite chaotic, the pilots talk the air traffic controller. The air traffic controller makes sure that all planes receive the information they need in order to fly safely, without hitting the other airplanes.

When to Use

  • Use this when multiple objects need to communicate but direct many-to-many relationships would be chaotic
  • This is helpful for implementing middleware chains (e.g., Express.js middleware)

When NOT to Use

  • When direct communication between two components is simpler and the system has few participants
  • When the mediator itself becomes a monolithic "god object" that's hard to maintain
  • When event-driven patterns (observer/pub-sub) provide sufficient decoupling without a central coordinator

Instructions

Related skills
Installs
299
GitHub Stars
202
First Seen
Mar 30, 2026