elysiajs/skills
Overview
This skill guides developers to build type-safe, high-performance backends using ElysiaJS with TypeScript. It covers routing, validation, authentication, plugins, integrations, WebSockets, testing, and deployment. Practical examples and recommended project structure help deliver maintainable, production-ready services quickly.
How this skill works
The skill explains how to define Elysia instances, chain methods to preserve type inference, and declare explicit dependencies and scopes. It demonstrates input/output validation (TypeBox, Zod, Valibot), lifecycle hooks, macros, guards, and plugins for common needs (CORS, JWT, OpenAPI, static files). It also shows integration patterns with ORMs, auth libraries, and hosting targets.
When to use it
- Scaffold a new Bun-first or Node/Deno-compatible backend with TypeScript and tight types.
- Add request/response validation, file uploads, query/params parsing, and typed responses.
- Implement authentication flows (JWT, sessions, guards) and reuseable macros/plugins.
- Expose OpenAPI, generate typed clients (Eden), or integrate with ORMs like Drizzle/Prisma.
- Create WebSocket endpoints or add runtime features like cron jobs and server timing.
- Prepare unit tests for Elysia instances and deploy to Vercel, Docker, or Cloudflare Workers.
Best practices
- Chain methods when building instances to preserve type inference and avoid lost types.
- Declare explicit dependencies via .use or .decorate so types and services remain isolated.
- Keep lifecycle hooks scoped intentionally (local, scoped, global) to avoid leakage.
- Organize code by feature: controllers (routes), services (business logic), and models (schemas).
- Register shared models and use named references or prefix/suffix for consistent OpenAPI docs.
- Prefer returning status responses for errors and centralize onError for local error handling.
Example use cases
- Create a user service with TypeBox or Zod validation, typed request/response, and JWT auth.
- Add an OpenAPI plugin to generate API docs and use OpenAPI Type Gen to produce client types.
- Integrate Elysia with Drizzle ORM for typed database access and expose typed endpoints.
- Implement a real-time chat with WebSocket plugin, validating messages and broadcasting safely.
- Deploy an Elysia app to Vercel or as a Docker container with static file serving and HMR for local dev.
FAQ
No. Elysia is Bun-first for performance but supports Node, Deno, and Cloudflare runtimes via adapters.
How do I preserve types across plugins and instances?
Declare types explicitly using .decorate, .model, and .use; avoid breaking chains and scope lifecycle/hooks deliberately.