riligar-dev-manager
npx machina-cli add skill riligar/agents-kit/riligar-dev-manager --openclawElysia Backend Development
Build fast, type-safe APIs with Elysia + Bun.
Mandatory Guidelines
[!IMPORTANT] All work in this skill MUST adhere to rules em
.agent/rules/— clean-code, code-style, javascript-only, naming-conventions.
Quick Reference
import { Elysia, t } from 'elysia'
const app = new Elysia()
.get('/', () => 'Hello Elysia')
.post('/users', ({ body }) => createUser(body), {
body: t.Object({
name: t.String(),
email: t.String({ format: 'email' }),
}),
})
.listen(3000)
Content Map
| File | Description | When to Read |
|---|---|---|
| elysia-basics.md | Setup, routes, handlers, context | Starting new project |
| elysia-plugins.md | Plugins, guards, modular design | Organizing code |
| elysia-validation.md | TypeBox validation (body, query, params) | Input validation |
| elysia-lifecycle.md | Hooks (onBeforeHandle, onError, etc.) | Middleware, auth checks |
| elysia-patterns.md | REST patterns, responses, pagination | API design |
Project Structure
src/
├── index.js # Entry point
├── routes/
│ ├── index.js # Route aggregator
│ ├── users.js # User routes plugin
│ └── posts.js # Post routes plugin
├── services/
│ ├── user.js # Business logic
│ └── post.js
├── database/
│ ├── db.js # Drizzle connection
│ ├── schema.js # Drizzle schema
│ └── migrations/
└── middleware/
├── auth.js # Auth middleware
└── logger.js # Request logging
Dependencies
| Pacote | Versão | Descrição |
|---|---|---|
bun | latest | Runtime |
elysia | latest | Framework HTTP |
bun:sqlite | builtin | SQLite driver |
drizzle-orm | latest | ORM |
bun:s3 | latest | S3/R2 Storage |
Core Patterns
Route Plugin
// routes/users.js
import { Elysia, t } from 'elysia'
import { getUserById, createUser } from '../services/user'
export const userRoutes = new Elysia({ prefix: '/users' })
.get('/', () => getAllUsers())
.get('/:id', ({ params }) => getUserById(params.id))
.post('/', ({ body }) => createUser(body), {
body: t.Object({
name: t.String({ minLength: 1 }),
email: t.String({ format: 'email' }),
}),
})
Main App
// index.js
import { Elysia } from 'elysia'
import { userRoutes } from './routes/users'
import { postRoutes } from './routes/posts'
const app = new Elysia()
.onError(({ error, set }) => {
console.error(error)
set.status = 500
return { error: 'Internal Server Error' }
})
.use(userRoutes)
.use(postRoutes)
.listen(3000)
console.log(`Server running at ${app.server?.url}`)
Related Skills
| Need | Skill |
|---|---|
| Authentication | @[.agent/skills/riligar-dev-auth-elysia] |
| database | @[.agent/skills/riligar-dev-database] |
| Infrastructure | @[.agent/skills/riligar-infra-fly] |
Decision Checklist
Before building an API:
- Defined route structure and prefixes?
- Planned validation for all inputs?
- Error handling configured?
- Auth middleware needed? → Use
riligar-dev-auth-elysia - database connection setup? → Use
riligar-dev-database
Anti-Patterns
| Don't | Do |
|---|---|
| Put business logic in handlers | Extract to services/ |
| Skip input validation | Use TypeBox (t.Object) |
| Ignore error handling | Use onError lifecycle |
| Create monolithic files | Split into plugins |
Use verbs in routes (/getUser) | Use nouns (/users/:id) |
Source
git clone https://github.com/riligar/agents-kit/blob/prod/.agent/skills/riligar-dev-manager/SKILL.mdView on GitHub Overview
Provides proven patterns for building fast, type-safe backends with Elysia on Bun. It covers routes, plugins, validation with TypeBox, middleware, and centralized error handling to keep code modular and maintainable.
How This Skill Works
Developers create route plugins (for example, routes/users.js) using Elysia and export them, then mount them in a main app with .use(). Validation is attached to routes via TypeBox (e.g., t.Object with name and email) to enforce input shapes. Errors are handled centrally in the main app using onError to standardize responses.
When to Use It
- Starting a Bun + Elysia API project with a clear route structure
- Organizing code with route plugins under prefixes (e.g., /users, /posts)
- Implementing input validation for body, query, and params using TypeBox
- Centralizing error handling with an onError handler for consistent responses
- Designing RESTful APIs with modular patterns and reusable services
Quick Start
- Step 1: Create a new Elysia app and define routes (GET '/', POST '/users' with body validation)
- Step 2: Attach TypeBox validation to route handlers (e.Object with name and email) and use .use() for plugins
- Step 3: Start the server with .listen(port) and observe logs, using onError for centralized handling
Best Practices
- Follow clean-code and naming conventions from .agent/rules (JavaScript-only, consistent style)
- Structure code with route plugins and a main app to keep concerns separated
- Validate all inputs (body, query, params) using TypeBox schemas
- Centralize error handling via app.onError to return consistent error responses
- Document and reuse patterns across routes (e.g., services and middleware) for maintainability
Example Use Cases
- Hello endpoint: GET '/' returns a simple response to verify the server
- User API: POST '/users' with body validation for name and email using t.Object
- Route plugins: separate routes for users and posts mounted via .use() in the main app
- Centralized errors: onError logs the error and returns a standardized 500 response
- Project layout: src with routes/, services/, middleware/ reflecting the Core Patterns and Project Structure