.agents/skills/server-gateway-refactor/SKILL.md
Use this skill when an apps/server route file has grown into a mixed transport/business/infra module and the user wants it engineered rather than merely split by line count.
Start from the exact route file the user named. Read nearby tests and domain services before editing. Use rg for call sites and avoid deleting legacy routes without checking tests/docs/env references.
Look for these responsibilities:
Context: auth, config availability, static files, IP-level limits.gateway.route('openai').use('chat.completions', rateLimit).post(...).use('chat.completions', ...) when the middleware is only meaningful for one endpoint group.middlewares/ for both Hono and gateway middleware in this project when they are part of a route gateway surface.operations/<operation>/index.ts for reusable operation orchestration.gateway as a domain name unless the module really owns route/runtime composition.For gateway-like HTTP surfaces:
const gateway = createXGateway(deps)
.useHono('*', '*', authGuard)
.useHono('surface', '/path/*', configGuard(...))
const surfaceRoutes = gateway.route('surface')
.use('operation.id', operationMiddleware(...))
.post('/path', surface.handler(
'operation.id',
async (c) => parseInput(c),
operation(deps),
))
.route
Keep route index readable:
Use this pattern when:
Do not force this pattern when:
After changes, run targeted validation before broader checks:
pnpm exec vitest run apps/server/src/routes/<route>/route.test.ts
pnpm -F @proj-airi/server typecheck
pnpm exec eslint <changed files>
If full pnpm lint fails from unrelated repo-wide issues, report that separately and keep targeted lint evidence.