# elysiajs/elysia architecture

> Architecture diagram of the GitHub repository elysiajs/elysia, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/elysiajs/elysia
- Repository: https://github.com/elysiajs/elysia

## Overview

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: [`src/compose.ts`](https://github.com/elysiajs/elysia/blob/main/src/compose.ts) (Composed routes), [`src/adapter/bun/index.ts`](https://github.com/elysiajs/elysia/blob/main/src/adapter/bun/index.ts) (Bun adapter), [`src/index.ts`](https://github.com/elysiajs/elysia/blob/main/src/index.ts) (Elysia app API), [`src/schema.ts`](https://github.com/elysiajs/elysia/blob/main/src/schema.ts) (Schema validation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_framework["Framework core"]
  node_app["Elysia app API<br/>[index.ts]"]
  node_static["Composed routes<br/>[compose.ts]"]
  node_dynamic["Dynamic handling<br/>[dynamic-handle.ts]"]
  node_context["Request context<br/>[context.ts]"]
  node_sucrose["Handler analysis<br/>[sucrose.ts]"]
end

subgraph group_request["Request handling"]
  node_query["Query parsing<br/>[parse-query.ts]"]
  node_cookies["Cookie handling<br/>[cookies.ts]"]
  node_files["File responses<br/>[file.ts]"]
  node_trace["Request tracing<br/>[trace.ts]"]
  node_errors["Error responses<br/>[error.ts]"]
end

subgraph group_validation["Schemas and types"]
  node_schema["Schema validation<br/>[schema.ts]"]
  node_typesystem["Type system<br/>[format.ts]"]
  node_replace["Schema replacement<br/>[replace-schema.ts]"]
end

subgraph group_runtime["Runtime integrations"]
  node_bun["Bun adapter<br/>[index.ts]"]
  node_bunhandler["Bun handler<br/>[handler.ts]"]
  node_web["Web standard adapter<br/>[index.ts]"]
  node_webhandler["Web standard handler<br/>[handler.ts]"]
  node_cloudflare["Cloudflare adapter<br/>[index.ts]"]
  node_server["Server lifecycle<br/>[server.ts]"]
  node_websocket["Bun WebSockets<br/>[bun.ts]"]
end

node_user(("HTTP client"))

node_user -.->|"sends request"| node_bun
node_user -.->|"sends request"| node_web
node_app -->|"starts listener"| node_bun
node_bun -.->|"dispatches requests"| node_bunhandler
node_web -.->|"dispatches requests"| node_webhandler
node_cloudflare -.->|"uses adapter"| node_web
node_bun -.->|"starts server"| node_server
node_app -.->|"composes routes"| node_static
node_app -.->|"handles dynamically"| node_dynamic
node_static -->|"parses query"| node_query
node_static -->|"parses cookies"| node_cookies
node_static -.->|"uses context"| node_context
node_static -.->|"validates input"| node_schema
node_schema -->|"replaces schema types"| node_replace
node_schema -.->|"uses type system"| node_typesystem
node_static -.->|"reports tracing"| node_trace
node_static -.->|"uses analysis"| node_sucrose
node_bunhandler -.->|"serves files"| node_files
node_bun -.->|"supports WebSockets"| node_websocket
node_static -.->|"handles errors"| node_errors

click node_app "https://github.com/elysiajs/elysia/blob/main/src/index.ts"
click node_static "https://github.com/elysiajs/elysia/blob/main/src/compose.ts"
click node_dynamic "https://github.com/elysiajs/elysia/blob/main/src/dynamic-handle.ts"
click node_context "https://github.com/elysiajs/elysia/blob/main/src/context.ts"
click node_bun "https://github.com/elysiajs/elysia/blob/main/src/adapter/bun/index.ts"
click node_bunhandler "https://github.com/elysiajs/elysia/blob/main/src/adapter/bun/handler.ts"
click node_web "https://github.com/elysiajs/elysia/blob/main/src/adapter/web-standard/index.ts"
click node_webhandler "https://github.com/elysiajs/elysia/blob/main/src/adapter/web-standard/handler.ts"
click node_cloudflare "https://github.com/elysiajs/elysia/blob/main/src/adapter/cloudflare-worker/index.ts"
click node_server "https://github.com/elysiajs/elysia/blob/main/src/universal/server.ts"
click node_schema "https://github.com/elysiajs/elysia/blob/main/src/schema.ts"
click node_typesystem "https://github.com/elysiajs/elysia/blob/main/src/type-system/format.ts"
click node_replace "https://github.com/elysiajs/elysia/blob/main/src/replace-schema.ts"
click node_query "https://github.com/elysiajs/elysia/blob/main/src/parse-query.ts"
click node_cookies "https://github.com/elysiajs/elysia/blob/main/src/cookies.ts"
click node_files "https://github.com/elysiajs/elysia/blob/main/src/universal/file.ts"
click node_trace "https://github.com/elysiajs/elysia/blob/main/src/trace.ts"
click node_sucrose "https://github.com/elysiajs/elysia/blob/main/src/sucrose.ts"
click node_websocket "https://github.com/elysiajs/elysia/blob/main/src/ws/bun.ts"
click node_errors "https://github.com/elysiajs/elysia/blob/main/src/error.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_static,node_dynamic,node_context,node_sucrose,node_user toneBlue
class node_query,node_cookies,node_files,node_trace,node_errors toneAmber
class node_schema,node_typesystem,node_replace toneMint
class node_bun,node_bunhandler,node_web,node_webhandler,node_cloudflare,node_server,node_websocket toneRose
```

## Components

### Framework core

- [Elysia app API](https://github.com/elysiajs/elysia/blob/main/src/index.ts): `src/index.ts`
- [Composed routes](https://github.com/elysiajs/elysia/blob/main/src/compose.ts): `src/compose.ts`
- [Dynamic handling](https://github.com/elysiajs/elysia/blob/main/src/dynamic-handle.ts): `src/dynamic-handle.ts`
- [Request context](https://github.com/elysiajs/elysia/blob/main/src/context.ts): `src/context.ts`
- [Handler analysis](https://github.com/elysiajs/elysia/blob/main/src/sucrose.ts): `src/sucrose.ts`

### Request handling

- [Query parsing](https://github.com/elysiajs/elysia/blob/main/src/parse-query.ts): `src/parse-query.ts`
- [Cookie handling](https://github.com/elysiajs/elysia/blob/main/src/cookies.ts): `src/cookies.ts`
- [File responses](https://github.com/elysiajs/elysia/blob/main/src/universal/file.ts): `src/universal/file.ts`
- [Request tracing](https://github.com/elysiajs/elysia/blob/main/src/trace.ts): `src/trace.ts`
- [Error responses](https://github.com/elysiajs/elysia/blob/main/src/error.ts): `src/error.ts`

### Schemas and types

- [Schema validation](https://github.com/elysiajs/elysia/blob/main/src/schema.ts): `src/schema.ts`
- [Type system](https://github.com/elysiajs/elysia/blob/main/src/type-system/format.ts): `src/type-system/format.ts`
- [Schema replacement](https://github.com/elysiajs/elysia/blob/main/src/replace-schema.ts): `src/replace-schema.ts`

### Runtime integrations

- [Bun adapter](https://github.com/elysiajs/elysia/blob/main/src/adapter/bun/index.ts): `src/adapter/bun/index.ts`
- [Bun handler](https://github.com/elysiajs/elysia/blob/main/src/adapter/bun/handler.ts): `src/adapter/bun/handler.ts`
- [Web standard adapter](https://github.com/elysiajs/elysia/blob/main/src/adapter/web-standard/index.ts): `src/adapter/web-standard/index.ts`
- [Web standard handler](https://github.com/elysiajs/elysia/blob/main/src/adapter/web-standard/handler.ts): `src/adapter/web-standard/handler.ts`
- [Cloudflare adapter](https://github.com/elysiajs/elysia/blob/main/src/adapter/cloudflare-worker/index.ts): `src/adapter/cloudflare-worker/index.ts`
- [Server lifecycle](https://github.com/elysiajs/elysia/blob/main/src/universal/server.ts): `src/universal/server.ts`
- [Bun WebSockets](https://github.com/elysiajs/elysia/blob/main/src/ws/bun.ts): `src/ws/bun.ts`

### Other components

- **HTTP client**

## Connections

- HTTP client → Bun adapter: sends request
- HTTP client → Web standard adapter: sends request
- Elysia app API → Bun adapter: starts listener (evidence: `src/index.ts`)
- Bun adapter → Bun handler: dispatches requests (evidence: `src/adapter/bun/index.ts`)
- Web standard adapter → Web standard handler: dispatches requests (evidence: `src/adapter/web-standard/index.ts`)
- Cloudflare adapter → Web standard adapter: uses adapter (evidence: `src/adapter/cloudflare-worker/index.ts`)
- Bun adapter → Server lifecycle: starts server (evidence: `src/adapter/bun/index.ts`)
- Elysia app API → Composed routes: composes routes (evidence: `src/index.ts`)
- Elysia app API → Dynamic handling: handles dynamically (evidence: `src/index.ts`)
- Composed routes → Query parsing: parses query (evidence: `src/compose.ts`)
- Composed routes → Cookie handling: parses cookies (evidence: `src/compose.ts`)
- Composed routes → Request context: uses context
- Composed routes → Schema validation: validates input (evidence: `src/compose.ts`)
- Schema validation → Schema replacement: replaces schema types (evidence: `src/schema.ts`)
- Schema validation → Type system: uses type system
- Composed routes → Request tracing: reports tracing (evidence: `src/compose.ts`)
- Composed routes → Handler analysis: uses analysis (evidence: `src/compose.ts`)
- Bun handler → File responses: serves files (evidence: `src/adapter/bun/handler.ts`)
- Bun adapter → Bun WebSockets: supports WebSockets (evidence: `src/adapter/bun/index.ts`)
- Composed routes → Error responses: handles errors (evidence: `src/compose.ts`)
