backend-standards

ms2sato 的头像作者 ms2sato

适用于此项目的Hono/Bun模式和后端最佳实践。在packages/server中实现API端点、WebSocket处理器、服务或服务器端逻辑时使用。

📖 中文导读:适用于此项目的Hono/Bun模式和后端最佳实践。在packages/server中实现API端点、WebSocket处理器、服务或服务器端逻辑时使用。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。

name: backend-standards description: Hono/Bun patterns and backend best practices for this project. Use when implementing API endpoints, WebSocket handlers, services, or server-side logic in packages/server.

Backend Standards

Key Principles

  • Server is the source of truth - Backend manages all session/worker state
  • Structured logging - Use Pino with context objects
  • Resource cleanup - Always clean up PTY processes and connections
  • Type safety - Define types in shared package, validate at boundaries

Tech Stack

  • Bun, Hono, bun-pty, Pino, Valibot

Backend Best Practices

  • Resource Cleanup - PTY processes, WebSocket connections, file handles must be cleaned up
  • Callback Detachment - Detach callbacks when resources are destroyed (memory leak prevention)
  • WebSocket Message Types - Define and validate server→client and client→server types explicitly
  • Output Buffering - Buffer rapid PTY output before WebSocket send to reduce message frequency
  • Structured Logging - Use Pino with structured data: logger.info({ sessionId }, 'message')

Detailed Documentation