mcpField
B
bun-elysia

bun-elysia

github.com/ymc182Development066 installsUpdated 41w ago
Repository

About bun-elysia

bun-elysia is a reference skill for developers building with Bun and Elysia.js. It covers setup, framework patterns, Bun APIs, and migration guidance for Fastify users.

Key features

  1. 01Bun and Elysia.js project setup
  2. 02Routing, handlers, and validation
  3. 03Lifecycle hooks, plugins, and WebSockets
  4. 04Bun database and storage APIs
  5. 05OpenAPI docs and Eden typed client
  6. 06Fastify migration guidance

Use cases

  1. 01Create an Elysia app and start its dev server
  2. 02Add routes and request validation to an API
  3. 03Use Bun database or Redis APIs
  4. 04Port Fastify features to Elysia

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/ymc182/bun-elysia-skill --skill bun-elysia

After installing, type/bun-elysiain Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
monorepo.md
references/elysia/
swagger.md
lifecycle.md
core.md
websocket.md
eden.md
validation.md
references/migration/
fastify-advanced.md
fastify-hooks.md
fastify-auth.md
fastify-plugins.md
fastify-basics.md
fastify-validation.md
references/native-apis/
http-server.md
redis.md
s3.md
sql.md

Details

From the project README

Bun + Elysia.js Development

Build high-performance full-stack applications with Bun runtime and Elysia.js framework.

Quick Start

New Elysia Project
bun create elysia my-app
cd my-app
bun run dev
Basic Server
import { Elysia, t } from "elysia";

const app = new Elysia()
  .get("/", () => "Hello, World!")
  .get("/users/:id", ({ params }) => ({ id: params.id }), {
    params: t.Object({ id: t.Number() })
  })
  .post("/users", ({ body }) => ({ created: body }), {
    body: t.Object({
      name: t.String(),
      email: t.String({ format: "email" })
    })
  })
  .listen(3000);
With Bun Native APIs
import { Elysia } from "elysia";
import { sql } from "bun";
import { redis } from "bun";

const app = new Elysia()
  .decorate("sql", sql)
  .decorate("redis", redis)
  .get("/users", async ({ sql }) => {
    return sql`SELECT * FROM users`;
  })
  .get("/cache/:key", async ({ redis, params }) => {
    return redis.get(params.key);
  })
  .listen(3000);

Reference Navigation

What do you want to do?

Set up a project:

Use Bun native APIs:

Build with Elysia:

Migrate from Fastify:


Common Patterns

Authentication Middleware
import { Elysia } from "elysia";
import { jwt } from "@elysiajs/jwt";

const app = new Elysia()
  .use(jwt({ secret: process.env.JWT_SECRET! }))
  .derive(async ({ headers, jwt }) => {
    const token = headers.authorization?.replace("Bearer ", "");
    const user = token ? await jwt.verify(token) : null;
    return { user };
  })
  .get("/profile", ({ user, error }) => {
    if (!user) return error(401);
    return user;
  });
Database with Validation
import { Elysia, t } from "elysia";
import { sql } from "bun";

const app = new Elysia()
  .post("/users", async ({ body }) => {
    const [user] = await sql`
      INSERT INTO users (name, email)
      VALUES (${body.name}, ${body.email})
      RETURNING *
    `;
    return user;
  }, {
    body: t.Object({
      name: t.String({ minLength: 1 }),
      email: t.String({ format: "email" })
    })
  });
Grouped Routes with Guard
app.group("/api", (app) =>
  app
    .guard({
      headers: t.Object({
        authorization: t.String()
      }),
      beforeHandle: ({ headers, error }) => {
        if (!isValidToken(headers.authorization)) {
          return error(401);
        }
      }
    }, (app) =>
      app
        .get("/users", getUsers)
        .post("/users", createUser)
    )
);
WebSocket Chat
app.ws("/chat", {
  body: t.Object({
    room: t.String(),
    message: t.String()
  }),
  open(ws) {
    ws.subscribe("general");
  },
  message(ws, { room, message }) {
    ws.publish(room, { from: ws.id, message });
  }
});

Key Differences: Fastify vs Elysia

FastifyElysia
request.params{ params }
request.query{ query }
request.body{ body }
reply.code(n).send(x)set.status = n; return x
reply.header(k, v)set.headers[k] = v
JSON SchemaTypeBox (t.*)
preHandler hookbeforeHandle
fastify.decorate().decorate()
fastify.register(plugin).use(plugin)

Installation

# Elysia and plugins
bun add elysia @elysiajs/swagger @elysiajs/jwt @elysiajs/cors @elysiajs/static @elysiajs/eden

# Types
bun add -d @types/bun typescript

Comments

Markdown supported