Skip to content

Introduction

Next.js Backend is a framework for Bun and Node.js ≥ 20 designed to build flexible, high-performance, and scalable backend applications.

The core idea came from the limitations of writing APIs directly inside the Next.js ecosystem (API Routes / Route Handlers). The lack of a clear software architecture, Dependency Injection, and standard middleware flows made managing large-scale Next.js fullstack projects complex and hard to maintain.

Next.js Backend was born to solve this — bringing the full power and elegance of NestJS architecture (Decorators, Dependency Injection, Modules) but running directly inside Next.js App Router, combined with the ultra-fast core of ElysiaJS / Bun.

Philosophy

JavaScript has become the most popular language for both frontend and backend. While there are many great libraries (Express, Fastify, Elysia), finding one that provides a proper software architecture is still a challenge.

This library provides a standard out-of-the-box architecture, inspired by the proven philosophies of Angular and NestJS:

  • Loosely coupled — each module is independent and testable
  • Dependency Injection — no global state, no singletons, just clean IoC
  • Convention over configuration — familiar decorators, predictable structure

Key Features

FeatureDescription
@Controller, @Module, @InjectableNestJS-style class decorators
@Guard, @Interceptor, @PipeFull request pipeline support
@UseMiddleware, @ThrottleMiddleware and rate limiting
AiModuleMulti-provider AI agents with tools, memory, workflows
ScheduleModuleCron jobs via @Cron
EventEmitterModulePub/sub via @OnEvent
SessionModuleCookie-based sessions
CacheModuleResponse caching with TTL
JwtModule, NextAuthModuleAuthentication
WebSocketGateway, @SseReal-time communication
createParamDecoratorCustom parameter decorators
OpenAPI / SwaggerAuto-generated docs

Under the Hood

At the low level, the library uses ElysiaJS's high-speed HTTP engine for the network layer, while layering a solid software architecture on top.

This lets you leverage 100% of Elysia's rich plugin ecosystem (Swagger, JWT, WebSockets) while maintaining a production-grade code structure.

Runtime Compatibility

The framework runs identically on both runtimes. Runtime-specific APIs are abstracted behind automatic detection:

SubsystemBunNode.js ≥ 20
HTTP serverElysia on BunElysia on Node.js
Password hashingBun.password (native)bcryptjs / argon2
Response compressionBun.gzipSync / deflateSyncnode:zlib built-in
WebSocketBun native WSWS via Elysia
All other APIsWeb-standard (Request, Response, Headers, crypto)Same

Installation

bash
npm install next-js-backend elysia reflect-metadata
bash
bun add next-js-backend elysia reflect-metadata

Quick Example

typescript
import 'reflect-metadata';
import { ElysiaFactory } from 'next-js-backend';
import { AppModule } from './app.module';

const app = await ElysiaFactory.create(AppModule);
app.listen(3000);

Released under the MIT License.