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
elysiainpackage.jsonand a Bun runtime (bun.lock,bunfig.toml)new Elysia().get(...).post(...)chains- Schemas built with
t.Object(...)and@elysiajs/edenon 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
- The root app chain
- Plugins that
deriveordecoratevalues onto the context
How a request moves through the code
- Lifecycle hooks such as
onRequestandonParserun. - The route is matched and its schema validates body, query and params.
deriveandresolveadd values such as the current user.beforeHandlehooks run guards, then the handler returns data.afterHandleandmapResponseshape the response;onErrorhandles 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.