Get the FREE Ultimate OpenClaw Setup Guide →

riligar-dev-manager

npx machina-cli add skill riligar/agents-kit/riligar-dev-manager --openclaw
Files (1)
SKILL.md
4.6 KB

Elysia 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

FileDescriptionWhen to Read
elysia-basics.mdSetup, routes, handlers, contextStarting new project
elysia-plugins.mdPlugins, guards, modular designOrganizing code
elysia-validation.mdTypeBox validation (body, query, params)Input validation
elysia-lifecycle.mdHooks (onBeforeHandle, onError, etc.)Middleware, auth checks
elysia-patterns.mdREST patterns, responses, paginationAPI 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

PacoteVersãoDescrição
bunlatestRuntime
elysialatestFramework HTTP
bun:sqlitebuiltinSQLite driver
drizzle-ormlatestORM
bun:s3latestS3/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

NeedSkill
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'tDo
Put business logic in handlersExtract to services/
Skip input validationUse TypeBox (t.Object)
Ignore error handlingUse onError lifecycle
Create monolithic filesSplit 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

  1. Step 1: Create a new Elysia app and define routes (GET '/', POST '/users' with body validation)
  2. Step 2: Attach TypeBox validation to route handlers (e.Object with name and email) and use .use() for plugins
  3. 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

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers