$ show typestack/routing-controllers
This repository is **routing-controllers**, a TypeScript library that provides a declarative, decorator-based API for building HTTP controllers on top of Express or Koa. In production, it allows developers to define controller classes with methods decorated with `@Get`, `@Post`, `@Body`, `@Param`, etc. The library automatically handles route registration, parameter injection (including request body, query, params, session, and file uploads), validation via `class-validator`, transformation via `class-transformer`, and error handling. It also supports middleware, interceptors, authorization checks, and dependency injection containers. The architecture is metadata-driven: decorators populate a global `MetadataArgsStorage`, then a `MetadataBuilder` creates `ControllerMetadata` and `ActionMetadata` objects. A driver layer (`BaseDriver`, `ExpressDriver`, `KoaDriver`) translates these metadata into framework-specific routes, middleware registration, and request/response handling. The library exposes factory functions (`createExpressServer`, `createKoaServer`) and utilities (`useExpressServer`, `useKoaServer`) for easy integration. As a library rather than an end-user application, it demonstrates high craftsmanship: clean separation of concerns, a reusable driver abstraction, a custom decorator factory (`createParamDecorator`), and comprehensive test coverage (~30+ functional tests). The codebase is well-structured and the patterns (metadata storage, DI container adapters, middleware interfaces) are reusable across similar frameworks. Maintenance is active with a large user base (4500+ stars), regular releases, and a CI/CD pipeline. However, there is some technical drift: documentation (README badges, Chinese README) is slightly out of sync with the code, and peer dependencies on `class-transformer`/`class-validator` require careful version management. Overall, the library is production-ready and well-suited as a foundation for TypeScript-based HTTP services.
The LLM identified 4 files worth highlighting for reuse:
Central repository for all decorator metadata. Controllers, actions, parameters, middlewares, interceptors, and response handlers register themselves in this global store via decorators. This pattern decouples decorator definitions from the actual route-building logic and is reusable for any decorator-driven framework.
Abstract base class for framework-specific drivers (ExpressDriver, KoaDriver). Defines common interfaces for registering actions, handling parameters, setting up middleware, and managing success/error responses. Can be extracted and extended to support other HTTP frameworks (e.g., Fastify) with minimal changes.
Exports `createParamDecorator` function that allows users to build custom parameter decorators. It handles the boilerplate of registering the decorator in the metadata store and extracting the value during request processing. This demonstrates how the library provides extension points for user-defined patterns beyond the built-in decorators.
Implements a lightweight dependency injection container adapter (`IocAdapter` interface and `useContainer` function). This enables integration with any DI container (e.g., TypeDI, Inversify) by implementing a simple interface. The pattern is cleanly separated from the rest of the library and is a reusable example of abstracting IOC container usage.