backend-standards
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.
When & Why to Use This Skill
This Claude skill provides comprehensive backend development standards and best practices optimized for Hono and Bun environments. It guides developers in implementing high-performance API endpoints, WebSocket handlers, and server-side logic while ensuring type safety, structured logging with Pino, and efficient resource management to build scalable and maintainable systems.
Use Cases
- Implementing robust RESTful API endpoints using Hono and Bun with strict schema validation via Valibot.
- Developing high-performance WebSocket services featuring explicit message type validation and output buffering to reduce overhead.
- Ensuring system stability and preventing memory leaks by applying standardized resource cleanup patterns for PTY processes and active connections.
- Enhancing backend observability and debugging efficiency through structured logging and consistent error handling across the server-side architecture.
| 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
- backend-standards.md - Directory structure, Hono, logging, services, testing, security, best practices
- websocket-patterns.md - Dual WebSocket architecture, message protocol, broadcasting