Files
ai-proj-helper/skills-dev/dev-coding-plugin/templates/claude-md-snippets/go-gin-gorm.md
John Qiu 23ea8fdca5 feat: 融合 devflow-claude P0 批机制 (REQ-20260416-0017)
P0-1: SessionStart Hook — hooks/session-context.sh
  从分支名解析 REQ-ID,调 MCP API 查询需求详情注入 system-reminder

P0-2: PreToolUse Hook — hooks/pre-tool-confirm.sh
  拦截生产推送、force push、docker prod 容器操作、git reset --hard 等

P0-3: Release Draft 闸门设计文档 — docs/design/release-draft-gate.md
  完整架构 + 渐进式落地路径(拆 7 个子任务延后)
  附最小可用脚本 hooks/release-draft.sh 创建 Gitea draft release

P0-4: Memory 隔离规则 — 写入 req-prd / req-design / req-workflow
  禁止 auto-memory 污染模板产出物(章节结构、字段定义、文档结构)

P0-5: CLAUDE.md 架构检查 + 架构片段库
  dev-coding skill 执行前检查架构关键词
  新增 templates/claude-md-snippets/ 含 Go+Gin / React+AntD / Vue+Element /
  MCP+TS / generic 五套骨架

P0-6: /commit 分支保护自动化 — 新 skill dev-commit-plugin
  保护分支自动建功能分支 + Conventional Commits + REQ-XXX 自动关联

安装:
  bash hooks/install.sh

后续:
  P0-3 完整实现拆 7 个子任务(P0-3.1 ~ P0-3.7)
  建议先部署 hooks 跑 1-2 周观察,再推进 Release 机制落地
2026-04-16 21:02:29 +09:30

57 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!-- 复制此片段到项目根 CLAUDE.md 的 "## Architecture" 章节 -->
## Architecture
### 分层结构Go + Gin + GORM
```
backend/
├── routes/ # HTTP 路由定义(按模块拆分)
├── handlers/ # 请求解析 + 响应组装(薄层,不含业务)
├── services/ # 业务逻辑(事务、组合、校验)
├── models/ # GORM 数据模型
├── database/ # Repository 层SQL、查询
├── middleware/ # 认证、CORS、日志、限流
├── migrations/ # SQL 迁移文件
└── utils/ # 通用工具(密码、签名等)
```
### 分层规则(强制)
1. **请求流向**Route → Handler → Service → Database → Models
2. **Handler 禁止直接访问 database**:必须走 Service 层
3. **Service 禁止调用 Handler 或 Route**:单向依赖
4. **Model 仅定义结构 + GORM tag**:不含业务方法
### 命名规范
| 类型 | 约定 | 示例 |
|------|------|------|
| 文件名 | snake_case | `user_service.go` |
| 包名 | lowercase | `services`, `handlers` |
| 导出函数/类型 | PascalCase | `CreateUser`, `UserRepository` |
| 内部函数 | camelCase | `validatePassword` |
| 常量 | SCREAMING_SNAKE_CASE | `MAX_RETRY_COUNT` |
### 错误处理
- 使用 `errors.New()` 或自定义 error type
- Handler 层统一返回 `{"code": X, "msg": "...", "data": ...}`
- Service 层返回原始 error由 Handler 转换
### 日志
- 使用结构化 log`log.WithField("user_id", uid).Info("...")`
- 禁用 `fmt.Println` / `print`
### 测试
- 单元测试文件名:`xxx_test.go`
- 使用 `testify/assert`
- Mock 用 `testify/mock``gomock`
### 依赖检查
- **新 handler 禁止直接 `import database/`**:需走 Service 层
- `./scripts/check-architecture.sh check` 作为 CI 门禁