Refactor high-complexity React components in Dify frontend. Use when `pnpm analyze-component...
npx skills add encoredev/skills
Or install specific skill: npx add-skill https://github.com/encoredev/skills/tree/main/encore/api
# Description
Create type-safe API endpoints with Encore.ts.
# SKILL.md
name: encore-api
description: Create type-safe API endpoints with Encore.ts.
Encore API Endpoints
Instructions
When creating API endpoints with Encore.ts, follow these patterns:
1. Import the API module
import { api } from "encore.dev/api";
2. Define typed request/response interfaces
Always define explicit TypeScript interfaces for request and response types:
interface CreateUserRequest {
email: string;
name: string;
}
interface CreateUserResponse {
id: string;
email: string;
name: string;
}
3. Create the endpoint
export const createUser = api(
{ method: "POST", path: "/users", expose: true },
async (req: CreateUserRequest): Promise<CreateUserResponse> => {
// Implementation
}
);
API Options
| Option | Type | Description |
|---|---|---|
method |
string | HTTP method: GET, POST, PUT, PATCH, DELETE |
path |
string | URL path, supports :param and *wildcard |
expose |
boolean | If true, accessible from outside (default: false) |
auth |
boolean | If true, requires authentication |
Parameter Types
Path Parameters
// Path: "/users/:id"
interface GetUserRequest {
id: string; // Automatically mapped from :id
}
Query Parameters
import { Query } from "encore.dev/api";
interface ListUsersRequest {
limit?: Query<number>;
offset?: Query<number>;
}
Headers
import { Header } from "encore.dev/api";
interface WebhookRequest {
signature: Header<"X-Webhook-Signature">;
payload: string;
}
Request Validation
Encore validates requests at runtime using TypeScript types. Add constraints for stricter validation:
import { api, Min, Max, MinLen, MaxLen, IsEmail, IsURL } from "encore.dev/api";
interface CreateUserRequest {
email: string & IsEmail; // Must be valid email
username: string & MinLen<3> & MaxLen<20>; // 3-20 characters
age: number & Min<13> & Max<120>; // Between 13 and 120
website?: string & IsURL; // Optional, must be URL if provided
}
Available Validators
| Validator | Applies To | Example |
|---|---|---|
Min<N> |
number | age: number & Min<18> |
Max<N> |
number | count: number & Max<100> |
MinLen<N> |
string, array | name: string & MinLen<1> |
MaxLen<N> |
string, array | tags: string[] & MaxLen<10> |
IsEmail |
string | email: string & IsEmail |
IsURL |
string | link: string & IsURL |
Validation Error Response
Invalid requests return 400 with details:
{
"code": "invalid_argument",
"message": "validation failed",
"details": { "field": "email", "error": "must be a valid email" }
}
Raw Endpoints
Use api.raw for webhooks or when you need direct request/response access:
export const stripeWebhook = api.raw(
{ expose: true, path: "/webhooks/stripe", method: "POST" },
async (req, res) => {
const sig = req.headers["stripe-signature"];
// Handle raw request...
res.writeHead(200);
res.end();
}
);
Error Handling
Use APIError for proper HTTP error responses:
import { APIError, ErrCode } from "encore.dev/api";
// Throw with error code
throw new APIError(ErrCode.NotFound, "user not found");
// Or use shorthand
throw APIError.notFound("user not found");
throw APIError.invalidArgument("email is required");
throw APIError.unauthenticated("invalid token");
Common Error Codes
| Code | HTTP Status | Usage |
|---|---|---|
NotFound |
404 | Resource doesn't exist |
InvalidArgument |
400 | Bad input |
Unauthenticated |
401 | Missing/invalid auth |
PermissionDenied |
403 | Not allowed |
AlreadyExists |
409 | Duplicate resource |
Static Assets
Serve static files (HTML, CSS, JS, images) with api.static:
import { api } from "encore.dev/api";
// Serve files from ./assets under /static/*
export const assets = api.static(
{ expose: true, path: "/static/*path", dir: "./assets" }
);
// Serve at root (use !path for fallback routing)
export const frontend = api.static(
{ expose: true, path: "/!path", dir: "./dist" }
);
// Custom 404 page
export const app = api.static(
{ expose: true, path: "/!path", dir: "./public", notFound: "./404.html" }
);
Guidelines
- Always use
importnotrequire - Define explicit interfaces for type safety
- Use
expose: trueonly for public endpoints - Use
api.rawfor webhooks,apifor everything else - Throw
APIErrorinstead of returning error objects - Path parameters are automatically extracted from the path pattern
- Use validation constraints (
Min,MaxLen, etc.) for user input
# README.md
Encore Skills
Agent skills for building backend applications with Encore, the backend framework for Go and TypeScript.
What These Skills Do
Encore is a backend framework with built-in infrastructure. You declare what you need (databases, Pub/Sub, cron jobs, etc.) in code, and Encore understands how to run it.
These skills help AI agents use Encore's declarative patterns correctly:
- Declarative infrastructure - define resources in code
- Type-safe APIs - request/response validation built-in
- Service-to-service calls - automatic type safety across service boundaries
- Built-in observability - tracing, metrics, and logging out of the box
How Infrastructure Works
- Local development (
encore run) - Encore provisions Docker containers automatically (Postgres, Redis, etc.) - Production deployment - Either use Encore Cloud to provision in your AWS/GCP account, or self-host using the generated infrastructure configuration
Installation
npx add-skill encoredev/skills
Works with Cursor, Claude Code, Codex, OpenCode, and 10+ other agents.
# List available skills
npx add-skill encoredev/skills --list
# Install specific skills
npx add-skill encoredev/skills --skill encore-getting-started --skill encore-api
# Install to specific agents
npx add-skill encoredev/skills -a cursor -a claude-code
# Global installation
npx add-skill encoredev/skills -g
Claude Code Marketplace
If you prefer to use Claude Code directly:
claude plugin marketplace add encoredev/skills
claude plugin install encore-skills@encore-skills
Manual Installation
Copy the SKILL.md files from encore/ to your agent's skills directory.
Available Skills
TypeScript
| Skill | Description |
|---|---|
encore-getting-started |
Get started with Encore.ts |
encore-api |
Create type-safe API endpoints |
encore-auth |
Implement authentication |
encore-infrastructure |
Declare databases, Pub/Sub, cron jobs, secrets |
encore-service |
Structure and organize services |
encore-database |
Database queries, migrations, ORM integration |
encore-testing |
Test APIs with Vitest |
encore-frontend |
Connect React/Next.js apps |
encore-code-review |
Review code for best practices |
encore-migrate |
Migrate Express/Fastify apps |
Go
| Skill | Description |
|---|---|
encore-go-getting-started |
Get started with Encore Go |
encore-go-api |
Create API endpoints |
encore-go-auth |
Implement authentication |
encore-go-infrastructure |
Declare infrastructure |
encore-go-service |
Structure services |
encore-go-database |
Database queries and migrations |
encore-go-testing |
Test APIs and services |
encore-go-code-review |
Review code for best practices |
References
License
Apache-2.0
# Supported AI Coding Agents
This skill is compatible with the SKILL.md standard and works with all major AI coding agents:
Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.