Composable Middleware Pipelines in TypeScript

Middleware is one of those patterns every backend developer uses constantly and almost nobody designs deliberately. You inherit an Express app with forty app.use() calls, or a Next.js project where every route reimplements auth and logging differently, and you accept that as the natural state of things. It doesn't have to be.

Building middleware as composable, typed primitives — rather than framework callbacks bolted together — makes pipelines testable in isolation, reorderable without fear, and readable as data flow rather than side effects.