sphere-feature-workflow

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Sphere Feature Workflow

Sphere 功能工作流

Overview

概述

Implement merge-ready feature changes in
go-sphere
scaffold projects while keeping
proto
,
schema
,
service
, and
render
layers synchronized.
This skill is scaffold-specific. Prefer repository conventions over generic architecture patterns unless the user explicitly requests otherwise.
go-sphere
脚手架项目中实现可合并的功能变更,同时保持
proto
schema
service
render
层同步。
本技能为脚手架专属,优先遵循仓库约定而非通用架构模式,除非用户明确提出其他要求。

Required Reading Order

必读顺序

Read these references before making edits:
  1. references/workflow-matrix.md
  2. references/source-of-truth-and-generated-boundaries.md
  3. references/change-checklist.md
编辑前请先阅读以下参考文档:
  1. references/workflow-matrix.md
  2. references/source-of-truth-and-generated-boundaries.md
  3. references/change-checklist.md

Scope

适用范围

Use this skill when the task involves one or more of the following:
  1. HTTP/API contract changes in
    proto/**
  2. Ent schema updates in
    internal/pkg/database/schema/**
  3. Bind/map registration updates in
    cmd/tools/bind/main.go
  4. Service/DAO/render behavior updates that must stay generation-safe
  5. Cross-layer refactors that require protocol-first consistency
当任务涉及以下一项或多项内容时使用本技能:
  1. proto/**
    目录下的HTTP/API契约变更
  2. internal/pkg/database/schema/**
    目录下的Ent schema更新
  3. cmd/tools/bind/main.go
    中的绑定/映射注册更新
  4. 必须保证生成安全的服务/DAO/render行为更新
  5. 需要协议优先一致性的跨层重构

Workflow Selection

工作流选择

Classify the task first, then run the matching workflow:
  1. Contract-first
  • Start from
    proto/**
  • Use when adding or changing service methods, HTTP annotations, errors, or validation
  1. Schema-first
  • Start from
    internal/pkg/database/schema/**
  • Use when adding/changing entities, fields, indexes, or relationships
  1. Service-only
  • Start from
    internal/service/**
    and
    internal/pkg/dao/**
  • Use when behavior changes without contract/schema changes
  1. Cross-layer
  • Use
    Contract-first
    or
    Schema-first
    as entrypoint, then complete all impacted layers
If classification is unclear, follow the preflight checks in references/workflow-matrix.md.
首先对任务进行分类,然后运行匹配的工作流:
  1. 契约优先
  • proto/**
    开始
  • 适用于添加或修改服务方法、HTTP注解、错误定义或校验规则的场景
  1. Schema优先
  • internal/pkg/database/schema/**
    开始
  • 适用于添加/修改实体、字段、索引或关联关系的场景
  1. 仅服务层
  • internal/service/**
    internal/pkg/dao/**
    开始
  • 适用于不需要变更契约/schema的行为调整场景
  1. 跨层
  • 契约优先
    Schema优先
    为切入点,然后完成所有受影响层的调整
如果分类不明确,请遵循references/workflow-matrix.md中的预检要求。

Reuse-First Policy

优先复用原则

Before implementing new framework-level capability, check existing Sphere packages first. Do not duplicate behavior already covered by:
  1. Lifecycle and bootstrapping:
    core/boot
  2. HTTP transport and error flow:
    server/httpz
  3. Auth and authorization:
    server/auth/*
    ,
    server/middleware/auth
  4. Common middleware:
    server/middleware/cors
    ,
    ratelimiter
    ,
    selector
  5. Infrastructure adapters and shared runtime packages:
    cache/*
    ,
    storage/*
    ,
    log/*
    ,
    utils/*
    ,
    infra/*
When overlap exists, reuse existing packages and document the decision.
在实现新的框架级能力前,请先检查现有Sphere包。不要重复实现以下包已覆盖的功能:
  1. 生命周期与启动:
    core/boot
  2. HTTP传输与错误流:
    server/httpz
  3. 身份验证与授权:
    server/auth/*
    server/middleware/auth
  4. 通用中间件:
    server/middleware/cors
    ratelimiter
    selector
  5. 基础设施适配器与共享运行时包:
    cache/*
    storage/*
    log/*
    utils/*
    infra/*
如果存在功能重叠,请复用现有包并记录该决策。

Execution Workflows

执行工作流

Contract-first Workflow

契约优先工作流

  1. Edit
    proto/**
    (service/method, HTTP annotation, validation, errors).
  2. Run
    make gen/proto
    .
  3. Resolve compile and behavior impacts in:
  • internal/service/**
  • internal/pkg/dao/**
  • internal/pkg/render/**
    non-generated files
  1. If contract-facing docs or SDK are impacted, run
    make gen/docs
    and/or
    make gen/dts
    .
  2. Run tests and ensure generated diffs are consumed by manual code.
  1. 编辑
    proto/**
    (服务/方法、HTTP注解、校验规则、错误定义)。
  2. 运行
    make gen/proto
  3. 解决以下位置的编译和行为影响:
  • internal/service/**
  • internal/pkg/dao/**
  • internal/pkg/render/**
    下的非生成文件
  1. 如果面向契约的文档或SDK受影响,运行
    make gen/docs
    和/或
    make gen/dts
  2. 运行测试,确保生成的差异已被手动编写的代码适配。

Schema-first Workflow

Schema优先工作流

  1. Edit
    internal/pkg/database/schema/**
    (field policy, relation, index strategy).
  2. Verify bind/map registration impact in
    cmd/tools/bind/main.go#createFilesConf
    .
  3. Review
    WithIgnoreFields
    for system-managed and sensitive fields.
  4. Run
    make gen/proto
    .
  5. Resolve compile and behavior impacts across service/dao/render.
  6. Run tests and verify query paths align with index intent.
  1. 编辑
    internal/pkg/database/schema/**
    (字段策略、关联关系、索引策略)。
  2. 检查
    cmd/tools/bind/main.go#createFilesConf
    中的绑定/映射注册影响。
  3. 检查系统管理字段和敏感字段的
    WithIgnoreFields
    配置。
  4. 运行
    make gen/proto
  5. 解决service/dao/render各层的编译和行为影响。
  6. 运行测试,验证查询路径与索引设计意图一致。

Service-only Workflow

仅服务层工作流

  1. Edit only non-generated business code:
  • internal/service/**
  • internal/pkg/dao/**
  • internal/pkg/render/**
    non-generated files
  • optional shared orchestration in
    internal/biz/**
  1. Keep contract/schema stable unless explicitly requested.
  2. Run targeted or full tests and confirm no API behavior regression.
  1. 仅编辑非生成的业务代码:
  • internal/service/**
  • internal/pkg/dao/**
  • internal/pkg/render/**
    下的非生成文件
  • 可选的
    internal/biz/**
    下的共享编排代码
  1. 除非明确要求,否则保持契约/schema稳定。
  2. 运行定向或全量测试,确认无API行为回归。

Hard Rules

硬性规则

  1. Edit source-of-truth files only; never patch generated files directly.
  2. Run
    make gen/proto
    after any proto/schema change.
  3. Run
    make gen/docs
    when HTTP contract output changes.
  4. Run
    make gen/wire
    when dependency wiring signatures change.
  5. New entity exposure must be reviewed in
    cmd/tools/bind/main.go#createFilesConf
    .
  6. WithIgnoreFields
    must cover system-managed and sensitive fields.
  7. Keep service-specific business errors in the owning service proto unless explicitly shared.
  8. Block delivery on route conflicts, cross-layer drift, or unconsumed generated changes.
  9. Never manually edit
    internal/pkg/render/entbind/**
    or
    internal/pkg/render/entmap/**
    .
  1. 仅编辑可信数据源文件;绝对不要直接修改生成的文件。
  2. 任何proto/schema变更后都要运行
    make gen/proto
  3. HTTP契约输出变更时运行
    make gen/docs
  4. 依赖绑定签名变更时运行
    make gen/wire
  5. 新实体暴露必须在
    cmd/tools/bind/main.go#createFilesConf
    中审核。
  6. WithIgnoreFields
    必须覆盖系统管理字段和敏感字段。
  7. 服务专属的业务错误应保存在所属服务的proto中,除非明确需要共享。
  8. 存在路由冲突、跨层不一致或未适配的生成变更时,禁止交付。
  9. 绝对不要手动编辑
    internal/pkg/render/entbind/**
    internal/pkg/render/entmap/**

Standard Commands

标准命令

bash
undefined
bash
undefined

ent + proto + bind/map generation chain

ent + proto + bind/map 生成链路

make gen/proto
make gen/proto

openapi/swagger generation

openapi/swagger 生成

make gen/docs
make gen/docs

dependency injection generation

依赖注入生成

make gen/wire
make gen/wire

validation

校验

go test ./...
undefined
go test ./...
undefined

Failure Conditions

失败条件

Do not mark the task complete if any of the following is true:
  1. Workflow type is not explicitly classified.
  2. Required generation commands were skipped.
  3. Generated diffs exist but are not reflected in service/dao/render logic.
  4. Generated files were manually edited.
  5. Bind/map or ignore-field policy impact was missed for schema-affecting changes.
  6. Compatibility impact and residual risks were not reported.
When a failure condition is hit, output
Blocking Issues
first, then a fix plan.
如果出现以下任意情况,不要标记任务完成:
  1. 未明确分类工作流类型。
  2. 跳过了必须的生成命令。
  3. 存在生成的差异,但未在service/dao/render逻辑中体现。
  4. 手动编辑了生成文件。
  5. 影响schema的变更遗漏了绑定/映射或忽略字段策略的影响检查。
  6. 未报告兼容性影响和残留风险。
当遇到失败条件时,首先输出
阻塞问题
,然后输出修复方案。

Final Output Contract

最终输出规范

Use this exact section order when reporting completion:
  1. Scope
  2. Workflow Selection
  3. Reuse Decision
  4. Source-of-Truth Files
  5. Generation Commands
  6. Behavior/Compatibility Notes
  7. Validation
  8. Blocking Issues
    (only when applicable)
报告完成时请严格遵循以下章节顺序:
  1. 适用范围
  2. 工作流选择
  3. 复用决策
  4. 可信数据源文件
  5. 生成命令
  6. 行为/兼容性说明
  7. 校验结果
  8. 阻塞问题
    (仅适用于存在阻塞问题的场景)