(and why I built chō)
NestJS has made a significant contribution to the JavaScript backend ecosystem. It introduced a structured, opinionated approach to server-side application development, bringing modularity, dependency injection, and declarative programming into an ecosystem that was historically dominated by minimalist HTTP frameworks.
There is a lot to appreciate about NestJS. However, there are also several fundamental architectural decisions that I believe deserve reconsideration.
My criticism is not about performance, popularity, or the size of its ecosystem. It is about the architectural foundations of the framework, the unnecessary complexity of some of its abstractions, and the limitations they impose on application developers.
These concerns eventually led me to design and develop chō.
1. When Frontend Architecture Meets the Backend
NestJS was heavily inspired by Angular. This influence is evident throughout its architecture, terminology, dependency injection system, decorators, and module configuration patterns.
Angular introduced some excellent architectural concepts. Modules, dependency injection, separation of concerns, and declarative programming are all valuable concepts that extend far beyond frontend development.
However, borrowing architectural principles is different from borrowing their implementations.
Angular was designed to solve the problems of client-side applications. Its abstractions evolved around component hierarchies, client-side navigation, rendering, and application lifecycle management.
Server-side applications operate under a fundamentally different set of requirements.
They handle concurrent requests, consume messages, manage shared resources, execute transactions, enforce security policies, and coordinate distributed operations.
Some of the abstractions inherited or inspired by Angular make considerably less sense in this environment.
The problem is not that NestJS was inspired by Angular. The problem is that some of its design decisions were adopted without sufficiently reconsidering whether they were appropriate for server-side applications.
Angular's influence extends beyond architectural patterns to the choice of dependencies themselves. A prominent example is RxJS, which NestJS integrates deeply into its execution model. While reactive programming is particularly valuable in frontend applications, where continuous streams of user interactions, state changes, and asynchronous events are common, most server-side operations follow a much simpler request-response or message-processing model. Native JavaScript features such as Promises, async/await, async iterators, and Web Streams already provide powerful mechanisms for handling asynchronous operations. RxJS certainly has legitimate use cases on the server, but making it an integral part of a general-purpose backend framework introduces unnecessary complexity, additional dependencies, and a programming paradigm that developers may never actually need. A framework should enable reactive programming when the application requires it, rather than impose it as a consequence of its architectural design.
2. Reinventing Middleware
Middleware is one of the most elegant and powerful architectural patterns in server-side development.
Its fundamental concept is remarkably simple: a chain of operations, each of which can perform work, delegate execution to the next operation, intercept the result, or terminate the execution entirely.
A properly designed middleware mechanism can address numerous cross-cutting concerns:
- Authentication and authorization
- Logging and observability
- Caching
- Rate limiting
- Transaction management
- Error handling
- Request and response transformations
- Input validation
NestJS instead introduces several distinct abstractions:
- Middleware
- Guards
- Interceptors
- Pipes
- Exception filters
Each comes with its own interface, registration mechanism, execution semantics, and position within the application lifecycle.
While these abstractions serve distinct semantic purposes, much of their behavior can be implemented through a sufficiently expressive middleware mechanism.
The most significant problem with this separation is the loss of composability.
Execution order should be an application decision
In NestJS, the standard request lifecycle follows a predefined sequence:
Request
↓
Middleware
↓
Guards
↓
Interceptors
↓
Pipes
↓
Controller
↓
Interceptors
↓
Response
Developers can control the ordering of multiple guards or interceptors within the same scope, but they cannot freely compose these different types of operations into an arbitrary execution chain.
For example, consider an interceptor responsible for collecting request metrics.
Because guards execute before interceptors, the interceptor cannot naturally wrap the authorization process. Requests rejected by a guard never reach it.
Similarly, an interceptor cannot perform an operation that must occur before a guard without moving that operation into a different framework abstraction.
The developer is forced to design around the framework's lifecycle instead of defining a lifecycle that reflects the application's requirements.
A general-purpose middleware mechanism allows the developer to express the execution order directly:
Tracing
→ Authentication
→ Authorization
→ Transaction
→ Validation
→ Handler
Each operation can execute logic before and after delegating to the next operation.
The same mechanism can implement what NestJS calls a guard, an interceptor, or many other cross-cutting concerns.
There is nothing wrong with giving these operations meaningful names. The problem begins when their names become separate architectural mechanisms with incompatible execution rules.
Semantic separation does not necessarily justify architectural separation.
3. Global Modules and the Erosion of Modularity
One of the primary reasons for adopting a modular architecture is to establish explicit boundaries between different parts of an application.
A module should declare what it owns, what it exposes, and what it depends on.
Ideally, the module dependency graph should represent the actual architectural dependencies of the application.
NestJS introduces global modules through the @Global() decorator and the global configuration property.
Once a module is registered globally, its exported providers become accessible to other modules without requiring explicit imports.
This is convenient, but convenience comes at an architectural cost.
Consider the following dependency graph:
UsersModule ──→ DatabaseModule
OrdersModule ──→ DatabaseModule
The relationship is explicit. Anyone examining these modules can understand their dependencies.
When the database module becomes global, those relationships no longer need to appear in the module definitions.
The dependencies still exist, but the module graph no longer accurately represents them.
This creates several potential problems:
- Hidden dependencies between modules.
- Reduced module portability and reusability.
- Increased dependence on application-wide configuration.
- More complicated isolated testing.
- Reduced architectural transparency as the application grows.
To be clear, global providers in NestJS are not JavaScript global variables. They are providers whose visibility is expanded across the application's dependency injection container.
Nevertheless, the architectural concern remains the same: implicit availability replaces explicit dependency declaration.
NestJS itself recommends using global modules sparingly. But I would argue that a well-designed module system should not need to compromise its boundaries simply to make dependency management more convenient.
Sharing a provider instance does not require making that provider globally visible.
Shared instances and global visibility are two entirely different architectural concerns.
4. The forRoot() Pattern
Another interesting example of Angular's influence is the widespread use of the forRoot() and forFeature() patterns.
A typical NestJS application might contain configurations such as:
@Module({
imports: [
ConfigModule.forRoot(),
TypeOrmModule.forRoot(databaseOptions),
JwtModule.register(jwtOptions),
],
})
export class AppModule {}
This approach originates from the Angular ecosystem, where RouterModule.forRoot() and RouterModule.forChild() were introduced to distinguish between root-level service registration and feature-level configuration.
Angular needed to address the interaction between its module system, injector hierarchy, and the registration of services that should be instantiated only once.
Modern Angular has since introduced a more direct provider-oriented approach:
bootstrapApplication(AppComponent, {
providers: [
provideRouter(routes),
],
});
Although the original forRoot() API remains supported, it is no longer necessary when using the modern standalone configuration model.
Meanwhile, NestJS has made variations of this pattern a central part of its ecosystem.
Developers encounter methods such as:
forRoot()forRootAsync()forFeature()register()registerAsync()
These are conventions rather than a single, universally enforced configuration contract.
The semantics of these methods can vary between libraries, introducing additional cognitive overhead for something that should be a fundamental capability of the framework: configuring modules and their dependencies.
Why should a module need to know whether it is being imported by the root application or by another feature?
Why should synchronous and asynchronous provider initialization require different module configuration APIs?
Why should every library author implement their own variation of module configuration?
In my view, configuration, dependency visibility, instance ownership, and asynchronous initialization should be first-class capabilities of the underlying module system.
They should not require a collection of conventions layered on top of it.
5. JavaScript Is No Longer Synonymous with Node.js
When NestJS was originally designed, targeting Node.js was an entirely reasonable decision.
The JavaScript ecosystem has changed considerably since then.
Today, developers can choose between several execution environments:
- Node.js
- Deno
- Bun
- Cloudflare Workers
- Other edge and serverless runtimes
Modern JavaScript increasingly benefits from standardized APIs such as Request, Response, fetch, Web Streams, Web Crypto, and URL.
These standards create an opportunity to design applications that are substantially less dependent on a particular runtime.
NestJS, however, remains fundamentally a Node.js-oriented framework.
It is possible to run certain NestJS applications on alternative runtimes through Node.js compatibility mechanisms, but compatibility with Node.js is not the same as being designed for runtime independence.
There is a fundamental architectural difference between:
Application
↓
Framework
↓
Node.js APIs
↓
Compatibility Layer
↓
Alternative Runtime
And:
Application
↓
Runtime-independent Framework
↓
Standard JavaScript and Web APIs
↓
Runtime of Choice
Runtime independence should not be an afterthought implemented through emulation or compatibility layers. It should be a design consideration from the very beginning.
The choice of JavaScript runtime should be primarily an infrastructure and deployment decision, rather than a consequence of the application framework.
6. Building on Standard JavaScript
Another architectural decision worth reconsidering is the traditional NestJS dependency injection model, which relies heavily on TypeScript's legacy decorators and emitted metadata.
For years, experimental decorators were the practical way to implement declarative dependency injection in JavaScript and TypeScript applications.
However, standardized JavaScript decorators introduce an opportunity to reconsider that approach.
Automatically inferring dependencies from emitted TypeScript metadata is convenient, but it also introduces coupling between the dependency injection system and compiler-specific behavior.
I prefer dependencies to be declared explicitly and validated wherever possible by the type system itself.
The framework should not need to reconstruct information at runtime that the developer could have expressed directly in the source code.
Less implicit behavior means fewer assumptions, better portability, and a more transparent execution model.
7. Why I Built chō
These architectural concerns eventually led me to a question:
What would a decorator-based application framework look like if it were designed from scratch today?
I did not want to abandon the development experience that made NestJS attractive.
I wanted to preserve its strongest ideas:
- Modular application architecture.
- Declarative programming.
- Dependency injection.
- Controllers and providers.
- Separation of business logic from infrastructure.
- A consistent development experience across large applications.
But I wanted to reconsider the mechanisms underlying those ideas.
That is why I created chō, an open-source framework for building modular JavaScript and TypeScript applications.
chō was designed around a different set of architectural principles.
A unified middleware model
Instead of introducing separate execution mechanisms for guards and interceptors, chō uses composable middleware that can control execution, terminate processing, or wrap downstream operations.
Middleware can be applied at the module, controller, and method levels.
Explicit module boundaries
Dependencies are declared explicitly. Modules import the capabilities they require and export the capabilities they provide.
Shared instances do not require globally visible providers.
Dependency injection without reflection
chō supports standard JavaScript decorators without requiring reflect-metadata or emitDecoratorMetadata.
Dependencies are explicitly declared, with type checking against constructor signatures.
Runtime independence
chō's HTTP applications are tested across Node.js, Deno, Bun, and Cloudflare Workers.
The application architecture is designed independently of the underlying execution environment.
Beyond HTTP
A modular application framework should not be limited to web servers.
HTTP requests, command-line commands, and incoming messages are different entry points into an application. They should be able to share the same architectural principles, business logic, and dependency management mechanisms.
chō supports HTTP applications, CLI applications, and message consumers through a consistent programming model.
Its Apache Kafka consumers can run on Node.js, Deno, and Bun.
Conclusion
NestJS is not a bad framework. It is a successful framework that made structured backend development significantly more accessible to the JavaScript community.
It has a mature ecosystem, an established community, and a substantial production footprint.
However, the success of a framework does not mean that all of its architectural decisions should be preserved indefinitely.
Some abstractions solve problems that no longer exist. Others introduce restrictions that are unnecessary. Some reflect the technological limitations of the time in which they were designed.
JavaScript has evolved. Its runtimes have evolved. Its standards have evolved.
Application frameworks should evolve as well.
With chō, my objective was not to create another NestJS clone or simply a lighter alternative. It was to rethink the architectural foundations of a modular, decorator-based application framework while preserving the development experience that developers already know and appreciate.
Sometimes, improving an architecture requires more than adding features or introducing new abstractions.
Sometimes, it requires going back to first principles and asking whether those abstractions should exist at all.
Explore chō:
- Website: chojs.io
- GitHub: github.com/cho-js/cho
- Middleware documentation
- Dependency injection documentation
References:
- NestJS — Request lifecycle
- NestJS — Modules
- NestJS — Dynamic modules
- Angular — RouterModule
- Angular — provideRouter
- NestJS — Cloudflare Workers
I'm interested in hearing from other developers and software architects. Which architectural decisions would you reconsider if you were designing NestJS from scratch today?
Top comments (0)