Elysia
By SaltyAom and the Elysia community
Elysia is a TypeScript web framework designed specifically for the Bun runtime, built to deliver end-to-end type safety between route definitions, request validation, and response handling without a separate code-generation step. It uses…
Definition
Elysia is a TypeScript web framework designed specifically for the Bun runtime, built to deliver end-to-end type safety between route definitions, request validation, and response handling without a separate code-generation step. It uses TypeScript's type inference so that a route's declared schema automatically produces accurate types for handlers and client calls, keeping the frontend and backend contract synchronized as routes change.
Overview
Elysia addresses the recurring gap between a web framework's runtime validation and its compile-time type checking: in many Node.js frameworks, a request body's TypeScript type and its actual runtime-validated shape can drift apart, since the type annotations are trusted but never mechanically tied to the validation logic. Elysia closes that gap by using TypeScript's type inference engine directly, so that when a route declares a validation schema, the same schema determines the type seen inside the handler and, through a companion client library, the type available to frontend code calling that route. Mechanically, Elysia is built on Bun's native HTTP server rather than Node's, letting it take advantage of Bun's faster startup and request-handling characteristics, and it defines routes through a chainable API where each call to a method like .get or .post can attach schema definitions for the body, query, params, and response. Its internal validation library, TypeBox-based by default, compiles schemas into fast runtime checks while TypeScript infers the corresponding static types, so a change to a schema immediately produces a type error anywhere the old shape was assumed. Among Bun-native and TypeScript-first frameworks, Elysia distinguishes itself by treating end-to-end type safety as its central design goal rather than a secondary feature, in contrast to frameworks like Hono that emphasize being runtime-agnostic and lightweight across many JavaScript engines, including Bun, Deno, and Cloudflare Workers. Elysia's tighter coupling to Bun lets it use Bun-specific APIs and optimizations that a portable framework would avoid. In practice, Elysia is used for building APIs where the frontend and backend share a TypeScript codebase or monorepo, since its Eden client library lets frontend code call backend routes with full type inference and no manually maintained API client. It appeals to teams building on Bun for performance reasons who also want the strict correctness guarantees that a validation-driven type system provides during rapid iteration. The main trade-off is that Elysia's deep integration with Bun means it does not run as a general-purpose framework on Node.js or Deno, so teams committed to those runtimes typically choose Hono, Fastify, or Express instead. Because Bun itself is younger and less universally supported in production infrastructure than Node.js, adopting Elysia also means adopting Bun's operational maturity and ecosystem trade-offs alongside the framework's type-safety benefits. Teams should also weigh the relative youth of Elysia's own plugin ecosystem compared with the much larger Express and Fastify communities before committing a large production codebase to it.
Key Features
- Built specifically for the Bun JavaScript runtime rather than being runtime-agnostic
- End-to-end type inference links route schemas directly to handler types
- Eden client library lets frontend code call APIs with full type safety
- Chainable route definition API for attaching validation schemas per route
- TypeBox-based validation compiles schemas into fast runtime checks
- Optimized to take advantage of Bun's native HTTP server performance
- Plugin system for extending functionality like Swagger docs or authentication
- Designed for monorepo setups sharing types between client and server