xiaohongshu
xiaohongshu
create-routes
Create route definitions for HTTP endpoints. Use when wiring controllers and middleware to HTTP routes. Triggers on "create routes", "router for", "route definitions".
Full skill instructions
Creates Hono route definitions that wire controllers and middleware to HTTP endpoints. Routes use a factory function pattern for dependency injection.
Location: src/routes/{entity-name}.router.ts
Naming: Singular for entities (note.router.ts), plural for cross-cutting (events.router.ts)
Before creating routes, ensure you have:
src/controllers/{entity-name}.controller.ts)src/schemas/{entity-name}.schema.ts)Create src/routes/{entity-name}.router.ts
import { Hono } from "hono";
import type { {Entity}Controller } from "@/controllers/{entity-name}.controller";
import type { AppEnv } from "@/schemas/app-env.schema";
import { validate as defaultValidate } from "@/middlewares/validation.middleware";
import { entityIdParamSchema } from "@/schemas/shared.schema";
import {
create{Entity}Schema,
{entity}QueryParamsSchema,
} from "@/schemas/{entity-name}.schema";
import { authMiddleware as defaultAuthMiddleware } from "@/middlewares/auth.middleware";
export interface Create{Entity}RoutesDeps {
{entity}Controller: {Entity}Controller;
validate?: typeof defaultValidate;
authMiddleware?: typeof defaultAuthMiddleware;
}
export const create{Entity}Routes = (dependencies: Create{Entity}RoutesDeps) => {
const {
{entity}Controller,
validate = defaultValidate,
authMiddleware = defaultAuthMiddleware,
} = dependencies;
const {entity}Routes = new Hono<AppEnv>();
// Apply auth middleware to all routes
{entity}Routes.use("*", authMiddleware);
// Define routes...
return {entity}Routes;
};
// GET / - List all
{entity}Routes.get(
"/",
validate({
schema: {entity}QueryParamsSchema,
source: "query",
varKey: "validatedQuery",
}),
{entity}Controller.getAll,
);
// GET /:id - Get by ID
{entity}Routes.get(
"/:id",
validate({
schema: entityIdParamSchema("id"),
source: "params",
varKey: "validatedParams",
}),
{entity}Controller.getById,
);
// POST / - Create
{entity}Routes.post(
"/",
validate({
schema: create{Entity}Schema,
source: "body",
varKey: "validatedBody",
}),
{entity}Controller.create,
);
// PUT /:id - Update (full replace)
{entity}Routes.put(
"/:id",
validate({
schema: entityIdParamSchema("id"),
source: "params",
varKey: "validatedParams",
}),
validate({
schema: create{Entity}Schema,
source: "body",
varKey: "validatedBody",
}),
{entity}Controller.update,
);
// DELETE /:id - Delete
{entity}Routes.delete(
"/:id",
validate({
schema: entityIdParamSchema("id"),
source: "params",
varKey: "validatedParams",
}),
{entity}Controller.delete,
);
Always use a factory function with dependency injection:
export const create{Entity}Routes = (dependencies: Create{Entity}RoutesDeps) => {
const { {entity}Controller, validate = defaultValidate } = dependencies;
const router = new Hono<AppEnv>();
// ...
return router;
};
This enables:
Use type import for controllers to avoid circular dependencies:
import type { {Entity}Controller } from "@/controllers/{entity-name}.controller";
export interface Create{Entity}RoutesDeps {
{entity}Controller: {Entity}Controller; // Not a class, just the type
}
Import middleware with aliases and provide as defaults:
import { validate as defaultValidate } from "@/middlewares/validation.middleware";
import { authMiddleware as defaultAuthMiddleware } from "@/middlewares/auth.middleware";
// In factory function
const { validate = defaultValidate, authMiddleware = defaultAuthMiddleware } =
dependencies;
Apply shared middleware globally, specific middleware per-route:
// Global auth for all routes
{
entity;
}
Routes.use("*", authMiddleware);
// Per-route validation
{
entity;
}
Routes.get(
"/",
validate({ schema: querySchema, source: "query", varKey: "validatedQuery" }),
controller.getAll,
);
For routes needing multiple validations, chain middleware:
{entity}Routes.put(
"/:id",
validate({ schema: entityIdParamSchema("id"), source: "params", varKey: "validatedParams" }),
validate({ schema: updateSchema, source: "body", varKey: "validatedBody" }),
{entity}Controller.update,
);
Always type routers with AppEnv:
const {entity}Routes = new Hono<AppEnv>();
Routes are mounted in src/app.ts:
import { createNoteRoutes } from "@/routes/note.router";
import { NoteController } from "@/controllers/note.controller";
import { NoteService } from "@/services/note.service";
// Create dependency chain
const noteService = new NoteService();
const noteController = new NoteController(noteService);
// Mount routes
app.route("/notes", createNoteRoutes({ noteController }));
See REFERENCE.md for a complete note.router.ts implementation.
new Hono() (always use new Hono<AppEnv>())create-controller - Create controllers for route handlerscreate-middleware - Create validation and auth middlewaretest-routes - Test route configurationsxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience