一键导入
backend
Backend development patterns for services, error handling, logging, caching. Use when building backend services, APIs, or microservices.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Backend development patterns for services, error handling, logging, caching. Use when building backend services, APIs, or microservices.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | backend |
| description | Backend development patterns for services, error handling, logging, caching. Use when building backend services, APIs, or microservices. |
| allowed-tools | Read, Write, Edit, Bash, Grep, Glob |
本技能提供后端服务开发的最佳实践和模式,支持多语言按需加载。
根据项目技术栈,加载对应的语言专属文件:
| 技术栈 | 加载文件 | 框架 |
|---|---|---|
| Python | python.md | FastAPI, Django, Flask |
| TypeScript/Node.js | typescript.md | Express, NestJS, Fastify |
| Java | java.md | Spring Boot, Quarkus |
| Go | go.md | Gin, Echo, Fiber |
| C# | csharp.md | ASP.NET Core |
| Rust | rust.md | Axum, Actix-web, Rocket |
加载方式: 检测项目中的 pyproject.toml/package.json/pom.xml/go.mod/Cargo.toml 等文件确定技术栈。
┌─────────────────────────────────────┐
│ Controller 层 │ 处理 HTTP 请求/响应
├─────────────────────────────────────┤
│ Service 层 │ 业务逻辑
├─────────────────────────────────────┤
│ Repository 层 │ 数据访问
├─────────────────────────────────────┤
│ Model 层 │ 数据模型
└─────────────────────────────────────┘
src/
├── controllers/ # 控制器(或 routes/handlers)
├── services/ # 业务逻辑
├── repositories/ # 数据访问(或 dal/)
├── models/ # 数据模型(或 entities/)
├── middlewares/ # 中间件
├── utils/ # 工具函数
├── config/ # 配置
└── types/ # 类型定义(如适用)
┌─────────────────────────────────────────────────────┐
│ 错误处理金字塔 │
├─────────────────────────────────────────────────────┤
│ 业务错误 (400-499) │
│ ├─ ValidationError (400) 输入验证失败 │
│ ├─ UnauthorizedError (401) 未认证 │
│ ├─ ForbiddenError (403) 无权限 │
│ └─ NotFoundError (404) 资源不存在 │
├─────────────────────────────────────────────────────┤
│ 系统错误 (500-599) │
│ ├─ InternalError (500) 服务器内部错误 │
│ ├─ ServiceUnavailable (503) 服务不可用 │
│ └─ GatewayTimeout (504) 网关超时 │
└─────────────────────────────────────────────────────┘
原则:
日志级别:
| 级别 | 用途 | 示例 |
|---|---|---|
| ERROR | 需要立即关注的错误 | 数据库连接失败 |
| WARN | 潜在问题 | 重试成功、降级处理 |
| INFO | 重要业务事件 | 用户登录、订单创建 |
| DEBUG | 开发调试信息 | 变量值、执行路径 |
结构化日志字段:
{
"timestamp": "2025-01-22T10:00:00Z",
"level": "info",
"message": "用户登录成功",
"requestId": "uuid",
"userId": "123",
"duration": 45
}
| 策略 | 适用场景 | TTL 建议 |
|---|---|---|
| Cache-Aside | 读多写少 | 5-60 分钟 |
| Write-Through | 强一致性要求 | 短 TTL |
| Write-Behind | 写多读少 | 根据业务 |
缓存键命名:
{service}:{entity}:{id}
{service}:{entity}:list:{hash}
/api/v1/...成功响应:
{
"success": true,
"data": { ... },
"meta": { "total": 100, "page": 1 }
}
错误响应:
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "邮箱格式不正确"
}
}
GET /health
{
"status": "ok",
"timestamp": "2025-01-22T10:00:00Z",
"services": {
"database": { "status": "ok" },
"redis": { "status": "ok" }
}
}
1. 收到 SIGTERM 信号
2. 停止接受新请求
3. 等待进行中的请求完成(超时时间内)
4. 关闭数据库连接
5. 关闭其他资源
6. 退出进程
详细的语言专属实现请参考:
记住: 后端代码的质量标准是可维护性——类型安全、错误处理、日志追踪缺一不可。
Frontend patterns: component design, state management, performance, accessibility. Use when building web frontends, components, or client-side apps.
Git version control best practices: branching, commits, merging, conflict resolution, PR workflows. Use when managing branches, creating commits, merging code, or resolving conflicts.
Model selection strategy and routing. Use when choosing between models for different task types, subagent configurations, or optimizing token cost vs quality tradeoffs.
Security review skill: comprehensive security checklist and patterns. Use when adding authentication, handling user input, working with secrets, or creating API endpoints.
Extracts reusable patterns from sessions. Use at session end to capture debugging insights and project-specific knowledge.
Strategic compaction skill: suggests context compression at logical breakpoints. Use to suggest compaction at logical intervals during development sessions.