Proto API Generator
Design implementation-ready proto3 + HTTP contracts for go-sphere scaffold projects.
If any of these are missing, ask one question at a time before proceeding.
When a design decision has multiple reasonable options (message type, route strategy, pagination shape), present 2-3 options with your recommendation — do not choose unilaterally.
Operating Model
- Follow go-sphere scaffold conventions unless the user explicitly requests deviation.
- Treat local references as the working source of truth for scaffold rules, runtime behavior, and output shape.
- Keep outputs protocol-first; do not rely on lint plugins, scripts, or manual edits to generated files as substitutes for reasoning checks.
Checklist (track with TodoWrite)
At task start, call TodoWrite to create a task for each numbered item below. Mark each complete before moving to the next.
- Confirm module name, file mode (new / add to existing), and message strategy — through dialogue with the user, not by inferring from context
- Ask clarifying questions one at a time for any ambiguous scope or behavior
- For non-obvious decisions, propose 2-3 options with recommendation
- Present service overview (service name, RPC list) — get approval
- Present message designs section by section — get approval for each
- Run Final Gate checklist (
references/go-sphere-api-definitions-checklist.md)
- Write the API design doc to disk (
prd/API.md or design/<feature>/api.md)
- Ask if the user wants to proceed to proto file generation
Output path rule: Use design/<feature>/api.md if the user names a specific feature or change-id; default to prd/API.md otherwise.
Task Intake
Supported task inputs:
- Prompt-only: infer entities and use cases, then state assumptions explicitly.
- Folder input: inspect only the provided folders; prefer scaffold-standard structure (
proto/, internal/, api/) when present.
- Requirement + mock demo: treat requirement docs as business truth, mock payloads as response-shape truth, and Ent schema as implementation reference rather than contract mirror.
Progressive Reference Loading
Do not load every reference by default. Load the smallest set that can support the current decision.
Start Here
- references/repo-proto-conventions-reference.md
Use for package style, route namespace strategy, pagination defaults, reuse policy, naming compatibility, and topology rules.
Load Only When Needed
- Final output shape selection or final formatting:
references/proto-output-template.md
Then load exactly one template:
- references/proto-output-condensed-template.md
- references/proto-output-full-template.md
- Service routes, path templates, or backend portability:
references/router-conflict-reference.md
- HTTP method, binding, body, response shaping, or server-streaming SSE:
references/go-sphere-api-definitions-reference.md
- Error enums,
sphere.errors, or runtime error behavior:
references/go-sphere-error-handling-reference.md
- Package layout, codegen pipeline, or runtime assumptions:
references/protocol-and-codegen-reference.md
references/proto-packages-and-runtime-reference.md
Final Gate
- references/go-sphere-api-definitions-checklist.md
If any required check fails, stop and output Validation Notes -> Blocking Issues with corrected proposals.
Do not replace local references with external links in final outputs.
Core Decisions
File Mode
Classify each target proto file as one of:
service proto: contains a service definition.
message-only proto: contains messages or enums only.
Mode handling:
service proto must satisfy service-only topology, route, and error-placement rules.
message-only proto is allowed and must record service-only exemptions explicitly.
- Both modes must still satisfy naming, import, runtime, and codegen compatibility checks.
Reuse Order
Default reuse priority:
- Reuse
entpb when it already satisfies external contract needs.
- Reuse or extract
shared.v1 messages for cross-service usage.
- Create custom DTO or VO only when contract shaping requires it.
Use custom DTO or VO only when at least one condition is true:
- Sensitive or internal fields must be hidden.
- Cross-aggregate composition is required.
- External contract stability must be isolated from storage model changes.
Error Placement Default
- Keep service-specific business errors in the same proto file as the owning
service.
- Reuse or create shared errors only for cross-service semantics.
- For
message-only proto, skip service-local error placement rules but still validate runtime and import compatibility.
Workflow
- Classify each target file by mode.
- Read scaffold conventions first and choose package style, service prefix, and compatibility constraints before drafting.
- Decide reuse (
entpb, shared.v1, custom DTO or VO`) before finalizing message shapes.
- For
service proto, define business use cases, unary/server-streaming transport shape, HTTP bindings, route-safe paths, and error enums.
- For
message-only proto, draft messages and enums only, then record service-only exemptions in validation notes.
- Load detailed HTTP, error, router, or runtime references only when the draft actually depends on them.
- Choose the deliverable shape late:
- use the condensed template for straightforward CRUD with clear reuse and routing;
- use the full template for custom business logic, multiple services, complex routing, or heavy validation notes.
- Run the final checklist before delivery.
Non-Negotiables
Keep these principles in mind throughout the task. Detailed rule text lives in the references and checklist.
- Design business capability first; avoid table-mirror public contracts.
- List APIs require pagination; batch APIs are preferred over repeated single reads.
- Prefer not to use
oneof in HTTP-exposed request or response messages. Tags land on wrapper structs; generated handlers bind the parent request, so QUERY/URI/HEADER oneof members are not filled. JSON codecs also handle oneof poorly.
- Keep error contracts machine-readable and stable.
- Do not leak sensitive or storage-only fields into external contracts.
- Keep routes conflict-safe; when backend is unknown, design for the Gin-safe subset first. Generated handlers use
httpx, not *gin.Context.
- Add concise
// business comments for exposed service/rpc, core messages, and key enum values.
- Map only
returns (stream Reply) methods to SSE. Client-streaming and bidirectional methods are not supported by protoc-gen-sphere's HTTP transport.
- Treat stream completion, failure, cancellation, optional resume behavior, and lazy-vs-eager commit needs as explicit API-contract decisions. Streaming events always carry the whole reply message; do not use
response_body.
Mandatory Pre-Output Checklist
BEFORE writing the final proto file, you MUST verify all of the following:
Package Naming Check
HTTP Binding Check
Error Handling Check
Field Type Check
Validation Check
Reuse Check
If ANY check fails, fix the proto file before delivering. Do not output proto files that fail these checks.
Output
Use references/proto-output-template.md only as the template selector.
Before final formatting, load exactly one of:
- references/proto-output-condensed-template.md
- references/proto-output-full-template.md
1---2name: proto-api-generator3description: Design proto3 + HTTP API contracts, including server-streaming SSE endpoints, 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.4---56# Proto API Generator78Design implementation-ready `proto3 + HTTP` contracts for go-sphere scaffold projects.910<HARD-GATE>11Do not write any `.proto` file or API design document until the following are confirmed through dialogue:12- Which service module is being designed (e.g., `task`, `user`, `order`)13- Whether this is a new file or an addition to an existing proto14- The primary message strategy (entpb / shared / custom) for at least the main entities1516If any of these are missing, ask one question at a time before proceeding.17When a design decision has multiple reasonable options (message type, route strategy, pagination shape), present 2-3 options with your recommendation — do not choose unilaterally.18</HARD-GATE>1920## Operating Model21221. Follow go-sphere scaffold conventions unless the user explicitly requests deviation.232. Treat local references as the working source of truth for scaffold rules, runtime behavior, and output shape.243. Keep outputs protocol-first; do not rely on lint plugins, scripts, or manual edits to generated files as substitutes for reasoning checks.2526## Checklist (track with TodoWrite)2728At task start, call TodoWrite to create a task for each numbered item below. Mark each complete before moving to the next.29301. Confirm module name, file mode (new / add to existing), and message strategy — through dialogue with the user, not by inferring from context312. Ask clarifying questions one at a time for any ambiguous scope or behavior323. For non-obvious decisions, propose 2-3 options with recommendation334. Present service overview (service name, RPC list) — get approval345. Present message designs section by section — get approval for each356. Run Final Gate checklist (`references/go-sphere-api-definitions-checklist.md`)367. Write the API design doc to disk (`prd/API.md` or `design/<feature>/api.md`)378. Ask if the user wants to proceed to proto file generation3839**Output path rule:** Use `design/<feature>/api.md` if the user names a specific feature or change-id; default to `prd/API.md` otherwise.4041## Task Intake4243Supported task inputs:44451. Prompt-only: infer entities and use cases, then state assumptions explicitly.462. Folder input: inspect only the provided folders; prefer scaffold-standard structure (`proto/`, `internal/`, `api/`) when present.473. Requirement + mock demo: treat requirement docs as business truth, mock payloads as response-shape truth, and Ent schema as implementation reference rather than contract mirror.4849## Progressive Reference Loading5051Do not load every reference by default. Load the smallest set that can support the current decision.5253### Start Here54551. [references/repo-proto-conventions-reference.md](references/repo-proto-conventions-reference.md)56 Use for package style, route namespace strategy, pagination defaults, reuse policy, naming compatibility, and topology rules.5758### Load Only When Needed59601. Final output shape selection or final formatting:61 [references/proto-output-template.md](references/proto-output-template.md)62 Then load exactly one template:63 - [references/proto-output-condensed-template.md](references/proto-output-condensed-template.md)64 - [references/proto-output-full-template.md](references/proto-output-full-template.md)652. Service routes, path templates, or backend portability:66 [references/router-conflict-reference.md](references/router-conflict-reference.md)673. HTTP method, binding, body, response shaping, or server-streaming SSE:68 [references/go-sphere-api-definitions-reference.md](references/go-sphere-api-definitions-reference.md)694. Error enums, `sphere.errors`, or runtime error behavior:70 [references/go-sphere-error-handling-reference.md](references/go-sphere-error-handling-reference.md)715. Package layout, codegen pipeline, or runtime assumptions:72 [references/protocol-and-codegen-reference.md](references/protocol-and-codegen-reference.md)73 [references/proto-packages-and-runtime-reference.md](references/proto-packages-and-runtime-reference.md)7475### Final Gate76771. [references/go-sphere-api-definitions-checklist.md](references/go-sphere-api-definitions-checklist.md)7879If any required check fails, stop and output `Validation Notes -> Blocking Issues` with corrected proposals.80Do not replace local references with external links in final outputs.8182## Core Decisions8384### File Mode8586Classify each target proto file as one of:87881. `service proto`: contains a `service` definition.892. `message-only proto`: contains messages or enums only.9091Mode handling:92931. `service proto` must satisfy service-only topology, route, and error-placement rules.942. `message-only proto` is allowed and must record service-only exemptions explicitly.953. Both modes must still satisfy naming, import, runtime, and codegen compatibility checks.9697### Reuse Order9899Default reuse priority:1001011. Reuse `entpb` when it already satisfies external contract needs.1022. Reuse or extract `shared.v1` messages for cross-service usage.1033. Create custom DTO or VO only when contract shaping requires it.104105Use custom DTO or VO only when at least one condition is true:1061071. Sensitive or internal fields must be hidden.1082. Cross-aggregate composition is required.1093. External contract stability must be isolated from storage model changes.110111### Error Placement Default1121131. Keep service-specific business errors in the same proto file as the owning `service`.1142. Reuse or create shared errors only for cross-service semantics.1153. For `message-only proto`, skip service-local error placement rules but still validate runtime and import compatibility.116117## Workflow1181191. Classify each target file by mode.1202. Read scaffold conventions first and choose package style, service prefix, and compatibility constraints before drafting.1213. Decide reuse (`entpb`, `shared.v1`, custom DTO or VO`) before finalizing message shapes.1224. For `service proto`, define business use cases, unary/server-streaming transport shape, HTTP bindings, route-safe paths, and error enums.1235. For `message-only proto`, draft messages and enums only, then record service-only exemptions in validation notes.1246. Load detailed HTTP, error, router, or runtime references only when the draft actually depends on them.1257. Choose the deliverable shape late:126 - use the condensed template for straightforward CRUD with clear reuse and routing;127 - use the full template for custom business logic, multiple services, complex routing, or heavy validation notes.1288. Run the final checklist before delivery.129130## Non-Negotiables131132Keep these principles in mind throughout the task. Detailed rule text lives in the references and checklist.1331341. Design business capability first; avoid table-mirror public contracts.1352. List APIs require pagination; batch APIs are preferred over repeated single reads.1363. Prefer not to use `oneof` in HTTP-exposed request or response messages. Tags land on wrapper structs; generated handlers bind the parent request, so QUERY/URI/HEADER oneof members are not filled. JSON codecs also handle oneof poorly.1374. Keep error contracts machine-readable and stable.1385. Do not leak sensitive or storage-only fields into external contracts.1396. Keep routes conflict-safe; when backend is unknown, design for the Gin-safe subset first. Generated handlers use `httpx`, not `*gin.Context`.1407. Add concise `//` business comments for exposed `service/rpc`, core messages, and key enum values.1418. Map only `returns (stream Reply)` methods to SSE. Client-streaming and bidirectional methods are not supported by `protoc-gen-sphere`'s HTTP transport.1429. Treat stream completion, failure, cancellation, optional resume behavior, and lazy-vs-eager commit needs as explicit API-contract decisions. Streaming events always carry the whole reply message; do not use `response_body`.143144## Mandatory Pre-Output Checklist145146BEFORE writing the final proto file, you MUST verify all of the following:147148### Package Naming Check149- [ ] Package name follows scaffold convention: `dash.v1` for generic, or `{module}.v1` for domain-specific (e.g., `user.v1`, `order.v1`, `article.v1`)150- [ ] Package declaration is in the format `package {name}.v1;`151152### HTTP Binding Check153- [ ] Every RPC method has `option (google.api.http)` annotation154- [ ] HTTP method (get/post/put/delete) matches the operation semantics155- [ ] Route path follows REST conventions with proper path parameters156- [ ] Every streaming method is server-streaming only (`returns (stream Reply)`), has no `response_body`, and documents terminal/interruption semantics157158### Error Handling Check159- [ ] Service proto files MUST include a service-local error enum (e.g., `ArticleError`, `OrderError`, `AuthError`)160- [ ] Error enum uses `(sphere.errors.options)` annotation with proper status codes161- [ ] At minimum, include `NOT_FOUND` and `INVALID_PARAMETER` error codes162163### Field Type Check164- [ ] ID fields use `int64` (not `string`)165- [ ] Timestamps use `google.protobuf.Timestamp`166- [ ] Pagination uses `page`/`page_size` with `total_size`/`total_page` in response167168### Validation Check169- [ ] Required fields have `(buf.validate.field)` constraints170- [ ] String fields have `min_len` or `min_bytes` where appropriate171- [ ] Numeric fields have `gte`/`lte` bounds where appropriate172173### Reuse Check174- [ ] Consider using entpb messages when they match contract needs175- [ ] Consider using shared.v1 for cross-service messages176177If ANY check fails, fix the proto file before delivering. Do not output proto files that fail these checks.178179## Output180181Use [references/proto-output-template.md](references/proto-output-template.md) only as the template selector.182Before final formatting, load exactly one of:1831841. [references/proto-output-condensed-template.md](references/proto-output-condensed-template.md)1852. [references/proto-output-full-template.md](references/proto-output-full-template.md)