middleware

Create HTTP middlewares enforcing cross-cutting concerns in TypeScript and Go backends.

4|Updated Jul 30, 2026
One-click install
npx skills add https://github.com/gabriellst/codm --skill middleware-gabriellst
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: middleware
Source: https://github.com/gabriellst/codm/tree/main/.claude/skills/middleware
Command: npx skills add https://github.com/gabriellst/codm --skill middleware-gabriellst

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Backend controllers accumulate duplicated cross-cutting logic like authentication, tenancy checks, and onboarding gates. This Skill provides language-specific playbooks for building HTTP middlewares that enforce these concerns before a controller runs, with typed errors that map to HTTP statuses and drive frontend routing. ## Core Features & Use Cases - Language dispatch hub: Routes to TypeScript or Go playbooks based on file extension, each with its own registry of mandatory patterns and bad practices. - Typed error contract: Middlewares throw typed BaseError codes registered in a GlobalErrorMapper, enabling the frontend to redirect (not just toast) via a customErrorHandlers registry. - Composition model: Default middleware chains per bounded context with per-controller overrides to add or skip middlewares. - Use Case: When adding an onboarding gate to a TypeScript API, the Skill guides creating an OnboardingMiddleware class, registering the ONBOARDING_NOT_COMPLETED error code, mapping it to HTTP 403, and wiring a frontend handler that redirects to /onboarding. ## Quick Start Ask the assistant to create an HTTP middleware that validates the user session and rejects unauthorized requests in the TypeScript backend.

Frequently Asked Questions about middleware

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create an HTTP middleware in TypeScript?

Create a @singleton() decorated class implementing the Middleware interface with an async execute method that takes HttpControllerRequest and returns HttpMiddlewareResponse. Parse request.ctx with Zod before reading it, and throw typed BaseError codes on failure.

How do I write middleware in Go with net/http?

Write a factory function returning func(next http.Handler) http.Handler that captures config like secrets in its closure. On failure call httputil.RespondError with errors.NewBaseError and return immediately; on success call next.ServeHTTP.

When should I use middleware versus a use case?

Use middleware for cross-cutting preconditions like authentication, tenancy, and flow gates that run before controllers. Business validation, aggregate mutations, and multi-entity rules belong in use cases or entity invariants, not middleware.

How does backend error routing work on the frontend?

The middleware throws a typed BaseError code, GlobalErrorMapper maps it to an HTTP status, and the frontend's customErrorHandlers registry matches the code to run a redirect instead of the default toast. The code must also be declared in the context's errors index and regenerated into the SDK.

Why does my middleware-injected ctx value disappear before the controller runs?

Controller.execute validates the request against inputSchema and Zod strips unknown keys, so any value a middleware stamps on request.ctx must be declared in a shared ctx schema composed by the controller. Undeclared keys are silently removed before handle executes.