How elysiajs/elysia works
Elysia is a TypeScript web framework focused on end-to-end type safety, with Bun as its primary runtime. A user’s request enters through a runtime adapter, is handled by the framework’s route machinery and request context, and produces an HTTP response; applications can define routes and start listening through the framework API. The graph preserves major runtime branches such as schema validation, cookies, files, tracing and WebSockets. Some connections are dashed because the supplied excerpts do not show the invoking code for those subsystems.
Main entry points: compose.ts Composed routes · bun/index.ts Bun adapter · src/index.ts Elysia app API · schema.ts Schema validation
Components 21
Framework core
- Elysia app API
src/index.ts - Composed routes
src/compose.ts - Dynamic handling
src/dynamic-handle.ts - Request context
src/context.ts - Handler analysis
src/sucrose.ts
Request handling
- Query parsing
src/parse-query.ts - Cookie handling
src/cookies.ts - File responses
src/universal/file.ts - Request tracing
src/trace.ts - Error responses
src/error.ts
Schemas and types
- Schema validation
src/schema.ts - Type system
src/type-system/format.ts - Schema replacement
src/replace-schema.ts
Runtime integrations
- Bun adapter
src/adapter/bun/index.ts - Bun handler
src/adapter/bun/handler.ts - Web standard adapter
src/adapter/web-standard/index.ts - Web standard handler
src/adapter/web-standard/handler.ts - Cloudflare adapter
src/adapter/cloudflare-worker/index.ts - Server lifecycle
src/universal/server.ts - Bun WebSockets
src/ws/bun.ts
Other components
- HTTP client
Connections 20
- HTTP client → Bun adapter: sends request
- HTTP client → Web standard adapter: sends request
- Elysia app API → Bun adapter: starts listener
src/index.ts - Bun adapter → Bun handler: dispatches requests
src/adapter/bun/index.ts - Web standard adapter → Web standard handler: dispatches requests
src/adapter/web-standard/index.ts - Cloudflare adapter → Web standard adapter: uses adapter
src/adapter/cloudflare-worker/index.ts - Bun adapter → Server lifecycle: starts server
src/adapter/bun/index.ts - Elysia app API → Composed routes: composes routes
src/index.ts - Elysia app API → Dynamic handling: handles dynamically
src/index.ts - Composed routes → Query parsing: parses query
src/compose.ts - Composed routes → Cookie handling: parses cookies
src/compose.ts - Composed routes → Request context: uses context
- Composed routes → Schema validation: validates input
src/compose.ts - Schema validation → Schema replacement: replaces schema types
src/schema.ts - Schema validation → Type system: uses type system
- Composed routes → Request tracing: reports tracing
src/compose.ts - Composed routes → Handler analysis: uses analysis
src/compose.ts - Bun handler → File responses: serves files
src/adapter/bun/handler.ts - Bun adapter → Bun WebSockets: supports WebSockets
src/adapter/bun/index.ts - Composed routes → Error responses: handles errors
src/compose.ts