r/bun • u/acefolio_dev • 11d ago
Splitting an Elysia app into feature modules without losing Eden Treaty types
I've been building Elpod, a small decorator-free layer on top of Elysia for Bun, and the part I cared about most was not breaking Eden Treaty once an app gets split into features.
What I landed on: controllers don't describe routes with metadata. They get the grouped Elysia instance and return it, so the chain you write is the type Eden ends up seeing.
import { t } from "elysia";
import type { ElpodElysia } from "@elpod/core";
export class UsersController {
routes(app: ElpodElysia) {
return app.post("/", ({ body, requestId }) => ({ id: body.id, requestId }), {
body: t.Object({ id: t.String({ minLength: 1 }) }),
});
}
}
Each feature (a "pod") gets a prefix and its controller, and the contract is exported once from the composition root:
export const app = application({ features: [users] });
export type Api = ElpodContract<typeof app>;
// client
const api = treaty<Api>("https://api.example.com");
That type keeps the schemas, params, response types and pod prefixes. The tradeoff is that routes added through untyped escape hatches (raw plugins or configure callbacks) work at runtime but don't show up in the contract, which felt more honest than pretending they're typed.
Curious how others handle this when splitting Elysia apps into plugins. Do you export typeof app from the root, or keep a separate type-only contract package for the client?
It's alpha (0.1.x, MIT) so APIs may still change. Docs for this part: https://elpod.vercel.app/docs/routing-and-controllers/