From 90bc132ca50f8fcffce82f67bb37798224087d77 Mon Sep 17 00:00:00 2001 From: dark Date: Mon, 9 Mar 2026 11:19:29 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=20app=20=E5=AD=90?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=8C=87=E9=92=88=E5=B9=B6=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20.cursorrules=20=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 app 子模块指向最新本地提交,新增 go-zero 开发规则配置用于统一协作约束。 Made-with: Cursor --- .cursorrules | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ app | 2 +- 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 .cursorrules diff --git a/.cursorrules b/.cursorrules new file mode 100644 index 0000000..ec855a3 --- /dev/null +++ b/.cursorrules @@ -0,0 +1,88 @@ +# go-zero Development Rules + +You are an expert in go-zero microservices framework development. + +## Key Principles + +Follow these go-zero patterns strictly: + +### Architecture +- **Three-layer separation**: Handler (HTTP) → Logic (business) → Model (data) +- Never put business logic in handlers +- Always use ServiceContext for dependency injection +- Use GORM as ORM for database operations + +### Code Generation +- Use `goctl` for code generation, never hand-write boilerplate +- API definitions go in `.api` files +- RPC definitions go in `.proto` files + +### Error Handling +- Use custom `response.Success(w, data)` for success responses +- Use custom `response.Error(w, err)` for error responses +- Use `errorx.CodeError` for business errors with error codes +- Never use `fmt.Fprintf()` or `w.Write()` directly + +### Configuration +- Load config with `conf.MustLoad(&c, *configFile)` +- Never hard-code ports, hosts, or credentials +- Use environment-specific config files + +### Context Propagation +- Always pass `ctx context.Context` through all layers +- Use context for tracing, cancellation, and timeouts + +### Database (GORM) +- Use GORM for all database operations +- Define models in `internal/model/` directory +- Initialize DB connection in ServiceContext +- Use soft delete with `gorm.DeletedAt` field + +## Pattern References + +When I need detailed patterns, I'll reference these files: +- REST APIs: .ai-context/zero-skills/references/rest-api-patterns.md +- RPC services: .ai-context/zero-skills/references/rpc-patterns.md +- Database: .ai-context/zero-skills/references/database-patterns.md +- Resilience: .ai-context/zero-skills/references/resilience-patterns.md +- Troubleshooting: .ai-context/zero-skills/troubleshooting/common-issues.md + +## Project Structure + +``` +backend/healthapi/ +├── healthapi.api # API definitions +├── healthapi.go # Entry point +├── internal/ +│ ├── config/ # Configuration +│ ├── handler/ # HTTP handlers +│ ├── logic/ # Business logic +│ ├── model/ # GORM models +│ ├── svc/ # ServiceContext +│ └── types/ # Generated types +├── pkg/ +│ ├── errorx/ # Custom errors +│ └── response/ # Unified response +└── etc/ + └── healthapi.yaml # Config file +``` + +## Common Commands + +```bash +# Generate API code +goctl api go -api healthapi.api -dir . + +# Generate model from database (if needed) +goctl model mysql datasource -url="user:pass@tcp(localhost:3306)/db" -table="users" -dir="./model" + +# Run the service +go run healthapi.go -f etc/healthapi.yaml +``` + +## AI Service Integration + +This project integrates with Aliyun Dashscope (Qwen models) for AI chat functionality: +- AI client initialized in ServiceContext +- SSE streaming support for real-time responses +- System prompt includes user health profile data diff --git a/app b/app index 4045a08..50050b6 160000 --- a/app +++ b/app @@ -1 +1 @@ -Subproject commit 4045a0873a31f059adf14e7f2752f35befc756fc +Subproject commit 50050b66cc4db674e781f1b70fd4e5d322f47bb5