From harness-claude
Guides JavaScript implementation of Chain of Responsibility pattern to pass requests along handler chains for auth pipelines, validation, or middleware. Decouples senders from receivers.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Pass a request along a chain of handlers until one handles it
Implements Chain of Responsibility pattern in TypeScript for linked handler chains with short-circuiting and Express-style async middleware pipelines. Use for HTTP middleware, validation, or event handling.
Generates Chain of Responsibility pattern for PHP 8.4, creating handler chains for middleware-style request processing like validation and approvals. Includes unit tests.
Builds Next.js App Router API routes with Route Handlers for HTTP methods, request bodies (JSON/form/text), dynamic params, queries, headers, and JSON responses.
Share bugs, ideas, or general feedback.
Pass a request along a chain of handlers until one handles it
handle(request) method and a setNext(handler) reference.h1.setNext(h2).setNext(h3).class Handler {
setNext(handler) {
this.next = handler;
return handler;
}
handle(request) {
if (this.next) return this.next.handle(request);
return null;
}
}
class AuthHandler extends Handler {
handle(req) {
if (!req.token) return { error: 'Unauthorized' };
return super.handle(req);
}
}
class RateLimitHandler extends Handler {
handle(req) {
if (req.rateLimited) return { error: 'Too many requests' };
return super.handle(req);
}
}
The Chain of Responsibility pattern decouples senders from receivers by giving multiple objects a chance to handle a request. The request travels along the chain until a handler processes it or it reaches the end. Express.js middleware is a functional variant of this pattern.
Trade-offs:
When NOT to use:
https://patterns.dev/javascript/chain-of-responsibility-pattern