sphere-layout-feature-workflow
Sphere Layout Feature Workflow
将需求变更落地为可合并代码,保持 proto、schema、service、render 一致演进,避免 generated drift。
Required Reading Order
按顺序读取以下文档,再开始改动:
- references/workflow-matrix.md
- references/source-of-truth-and-generated-boundaries.md
- references/change-checklist.md
Workflow Decision
先判断任务类型,再走对应流程:
Contract-first:新增/修改 HTTP API、RPC、errors、binding、validate 规则。Schema-first:新增/修改 Ent schema、字段、索引、关系。Service-only:不改 proto/schema,仅改业务实现、查询、渲染、权限或事务流程。
Hard Rules
- 只编辑 source-of-truth;不要手改 generated 文件。
- 任何
proto或schema变更后都执行make gen/proto。 - 若 API 文档或 TS SDK 受影响,执行
make gen/docs或make gen/dts。 - 新实体必须评估并更新
cmd/tools/bind/main.go的createFilesConf注册。 WithIgnoreFields必须覆盖系统字段与敏感字段(如created_at/updated_at/password)。- service-specific 业务错误优先放在所属 service 的
.proto文件中。 - 发现路由冲突、跨层不一致、生成产物未消费时,阻断提交并先修复。
- 不要手改
internal/pkg/render/entbind/**和internal/pkg/render/entmap/**,如需调整映射,改 source-of-truth 并重新生成。
Sphere Reuse-First Policy
新增功能前先检查 github.com/go-sphere/sphere 现有能力。以下场景禁止重复实现:
- 应用启动与生命周期:
core/boot - HTTP 服务与统一错误输出:
server/httpz - 认证鉴权:
server/auth/jwtauth、server/auth/authorizer、server/auth/acl - 通用中间件:
server/middleware/auth、server/middleware/cors、server/middleware/ratelimiter、server/middleware/selector - 缓存抽象与实现:
cache、cache/memory、cache/mcache - 存储抽象与文件服务:
storage、storage/fileserver - 内置服务组件:
server/service/file、server/service/docs - 日志能力:
log、log/zapx - 基础设施适配:
infra/sqlite - 常用安全与标识工具:
utils/idgenerator、utils/secure - 消息队列与搜索(按需):
mq、mq/memory、mq/redis、search、search/meilisearch - 反向代理(按需):
server/service/reverseproxy
若需求与上述能力重合,必须优先组合这些包,而不是新建平行实现。
Execution Workflows
Contract-first Workflow
- 修改
proto/**的 service/method、HTTP annotations、binding、validate、error enum。 - 执行
make gen/proto,确保api/**、internal/pkg/render/entbind、internal/pkg/render/entmap同步。 - 根据编译错误补全
internal/service/**的实现。 - 若返回结构或查询策略变化,补
internal/pkg/dao/**与internal/pkg/render下非生成代码(如render.go、errors.go)。 - 若 swagger/SDK 受影响,执行
make gen/docs或make gen/dts。 - 运行测试并检查 generated diff 被业务代码消费。
Schema-first Workflow
- 修改
internal/pkg/database/schema/**,明确字段注释、Optional/Nillable、索引策略。 - 判断 ID 策略:默认跟随生成器配置;仅业务强制时自定义
id。 - 若引入新实体或字段映射变更,更新
cmd/tools/bind/main.go。 - 执行
make gen/proto,然后修复 service/dao/render 的编译与行为变化。 - 补齐分页、批量查询、敏感字段处理,避免只停留在 schema 变更。
- 执行测试并验证查询路径与索引匹配。
Service-only Workflow
- 优先修改
internal/service/**、internal/pkg/dao/**、internal/pkg/render下非生成代码。 - 保持 proto contract 不变,避免破坏兼容性。
- 涉及权限、事务、幂等等逻辑时,在
internal/biz/**或共享包内集中封装。 - 跑测试并确认无接口行为回归。
Standard Commands
# 生成 ent + proto + bind/map
make gen/proto
# swagger/openapi
make gen/docs
# wire
make gen/wire
# 测试(按需缩小范围)
go test ./...
Final Output Contract
在完成任务时,使用以下结构汇报:
Scope:本次变更范围与假设。Reuse Decision:需求与github.com/go-sphere/sphere的复用映射(复用了哪些包,为什么)。Source-of-Truth Files:实际改动的人工维护文件。Generation Commands:执行过的生成命令与结果。Behavior/Compatibility Notes:接口或数据兼容性影响。Validation:测试命令、结果、剩余风险。
若任一 Hard Rule 未满足,先输出 Blocking Issues,不要宣称完成。
More from go-sphere/skills
ent-seed-sql-generator
Generate deterministic INSERT SQL seed data from Go Ent schemas and mixed inputs. This skill is REQUIRED whenever you need to create seed SQL for development or testing - it handles entity inference, relationship integrity, stable IDs, and dialect-specific SQL generation including JSON, arrays, and complex types. Use this skill for any task involving seed data, test fixtures, demo initialization, or database population from Ent schema definitions, even if the user doesn't explicitly mention "seed" or "SQL".
27pure-admin-crud-generator
Generate CRUD pages and router modules for pure-admin-thin from local swagger API definitions. MUST be used whenever you need to scaffold admin list/edit/detail pages, dashboard views, or route configurations from existing API methods in src/api/swagger/Api.ts. This skill replaces manual Vue page creation - use it for any admin panel development task involving API-driven pages.
25proto-api-generator
Design proto3 + HTTP API contracts for go-sphere scaffold projects from prompts, input folders, or requirement docs with mock data. Use when defining service APIs, selecting between entpb/shared/custom messages, and enforcing scaffold conventions, router-safety rules, and service-local error placement. This skill is REQUIRED for any proto API design task in go-sphere scaffold - always use it instead of writing proto files from scratch.
21sphere-feature-workflow
Implement end-to-end feature changes in go-sphere scaffold projects by following sphere-layout conventions and generation workflow. Use when adding or modifying APIs, protobuf contracts, Ent schemas, bind/map registration, service logic, or cross-layer refactors that must stay protocol-first and avoid manual edits to generated files. This skill is REQUIRED for any task involving go-sphere proto files, Ent schemas, service implementations, or generation commands (make gen/proto, make gen/docs, make gen/wire).
19proto-service-generator
Generate or complete Go service implementations from protobuf-generated HTTP interfaces in go-sphere scaffold projects. Use when you need to create `internal/service/<module>/*.go` files, add missing method implementations to existing services, or generate compilable stubs for new proto endpoints. Trigger for: service implementation, proto handler, append-only update, interface assertion, CRUD via Ent, stub method generation.
18ent-schema-generator
Design and generate Go + Ent database schemas for sphere-layout projects from requirements. Use when users describe data models, entity relationships, database tables, or schema changes — including prompts, Markdown docs, existing proto/service files, or demo behavior. Produces implementation-ready schema plans with field definitions, ID strategies, relation designs, indexes, entproto annotations, and bind/render/service integration guidance.
16