DEV Community

Cover image for I Built a Framework-Agnostic Backend Boilerplate (Node, Bun, Express, Hono...)
Adam Golan
Adam Golan

Posted on

I Built a Framework-Agnostic Backend Boilerplate (Node, Bun, Express, Hono...)

Why Choose One Framework When You Can Have Them All? 🧠

We all know the struggle. You start a project in Express, but then Fastify catches your eye with its speed. Or maybe Bun takes off and you want to try Hono or Elysia.

Usually, switching means rewriting your router, middleware, and request/response logic.

Not anymore.

I built BEnder, a TypeScript boilerplate that abstracts the underlying framework away, letting you write your business logic once and run it anywhere.

🧠 The "Brain" Architecture

Instead of a messy routes.js, BEnder uses a biological metaphor:

  • Neurons (Directories): Containers that automatically discover and mount routes.
  • Synapses (Files): Endpoints that process the logic.

It functions like file-system routing (similar to Next.js), but strictly typed for backend APIs.

⚑ Write Once, Run on Node or Bun

Are you Team Node or Team Bun? It doesn't matter.

BEnder detects your runtime and valid installed packages to boot up the optimal server:

  • Node.js: Natively supports Fastify (Default) or Express 5.
  • Bun: Natively supports Hono or Elysia.

The Magic Code

Here is how the entry point app.ts remains clean:

// 1. Initialize Infrastructure (auto-detects framework)
const { framework } = await initInfrastructure();

// 2. Initialize Neurons (Routes)
const [get, post] = [new GET(), new POST()];

// 3. Mount them universally
server.get('*', get.router).post('*', post.router);
Enter fullscreen mode Exit fullscreen mode

And your route handlers ("Synapses") use unified types:

export class CreateUser extends Synapse {
    protected async setRouter(): Promise<void> {
        // works on Express, Fastify, Hono, AND Elysia!
        this.router.post('/create', async (req: IRequest, res: IResponse) => {
             // Unified Request/Response API
             this.responser(res, 200, { success: true });
        });
    }
}
Enter fullscreen mode Exit fullscreen mode

πŸ›‘οΈ Unified Middleware

I didn't stop at routing. Security and utilities are also abstracted.

Configure app.config.ts:

export const appConfig = {
    security: {
        cors: true,
        helmet: true,
        rateLimit: true
    }
};
Enter fullscreen mode Exit fullscreen mode

BEnder automatically loads the correct middleware package for the active framework (e.g., @fastify/helmet for Fastify, hono/cors for Hono, or @elysiajs/limit for Elysia).

πŸš€ Try It Out

I've open-sourced this to help developers spin up robust backends in seconds.

Clone it here: BEnder

Quick Start

# 1. Install Dependencies
npm install

# 2. Pick your flavor (e.g., Bun + Hono)
npm install hono hono-rate-limiter

# 3. Run!
bun run app.ts
Enter fullscreen mode Exit fullscreen mode

Let me know in the comments: Do you prefer deep abstraction or raw framework usage? πŸ‘‡

Top comments (0)