Skip to content

How to understand a Elysia codebase

Elysia is a Bun-first web framework built around chained route definitions with strong type inference. Plugins are just other Elysia instances added with `.use`, schemas are declared inline with `t`, and the exported app type powers the Eden client.

How to tell it's Elysia

  • elysia in package.json and a Bun runtime (bun.lock, bunfig.toml)
  • new Elysia().get(...).post(...) chains
  • Schemas built with t.Object(...) and @elysiajs/eden on the client

Where things usually live

src/index.ts
Creates the app, uses plugins, calls listen, exports the app type.
src/modules/ or routes/
Feature plugins, each an Elysia instance with a prefix.
src/plugins/
Shared plugins: auth, database, error handling.

Conventions, not rules. Real projects rename and move things, so confirm against the repository.

Where to start reading

  1. The root app chain
  2. Plugins that derive or decorate values onto the context

How a request moves through the code

  1. 1Lifecycle hooks such as onRequest and onParse run.
  2. 2The route is matched and its schema validates body, query and params.
  3. 3derive and resolve add values such as the current user.
  4. 4beforeHandle hooks run guards, then the handler returns data.
  5. 5afterHandle and mapResponse shape the response; onError handles failures.

Questions to ask about the repository

  • Which plugins add values to the context, and which routes use them?
  • Which routes have guards, and what do they check?
  • How does the front end call this API: through Eden or plain fetch?

What trips people up

  • Hooks apply only to routes registered after them in the chain, so order matters.
  • Types depend on the chain staying intact; splitting it can lose inference.