@@ -17,32 +17,30 @@ This document provides a comprehensive technical overview of sebuf's architectur
1717
1818## System Overview
1919
20- sebuf is a collection of two specialized protoc plugins that work together to enable modern HTTP API development from protobuf definitions:
20+ sebuf is a collection of three specialized protoc plugins that work together to enable modern HTTP API development from protobuf definitions:
2121
2222```
23- ┌─────────────────────────────────────────────────────────────────┐
24- │ sebuf Toolkit │
25- ├─────────────────────────────┬───────────────────────────────────┤
26- │ protoc-gen-go-http │ protoc-gen-openapiv3 │
27- │ │ │
28- │ │ │
29- │ ┌─────────────────────────┐ │ ┌─────────────────────────────────┐ │
30- │ │HTTP Handlers │ │ │ OpenAPI v3.1 │ │
31- │ │ + Binding │ │ │ Specifications │ │
32- │ │ + Routing │ │ │ + Validation Rules │ │
33- │ │ + Validation │ │ │ + Header Parameters │ │
34- │ └─────────────────────────┘ │ └─────────────────────────────────┘ │
35- └─────────────────────────────┴───────────────────────────────────┘
36- │
37- ▼
38- ┌─────────────────────────────────────────────────────────────────┐
39- │ Standard Go HTTP Stack │
40- │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
41- │ │ net/http │ │ Gin/Echo/ │ │ Client Libraries │ │
42- │ │ │ │ Chi/Fiber │ │ (Generated from │ │
43- │ │ │ │ │ │ OpenAPI specs) │ │
44- │ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
45- └─────────────────────────────────────────────────────────────────┘
23+ ┌─────────────────────────────────────────────────────────────────────────────────┐
24+ │ sebuf Toolkit │
25+ ├─────────────────────────┬─────────────────────────┬─────────────────────────────┤
26+ │ protoc-gen-go-http │ protoc-gen-go-client │ protoc-gen-openapiv3 │
27+ │ │ │ │
28+ │ ┌─────────────────────┐ │ ┌─────────────────────┐ │ ┌─────────────────────────┐ │
29+ │ │HTTP Handlers │ │ │HTTP Clients │ │ │ OpenAPI v3.1 │ │
30+ │ │ + Binding │ │ │ + Type-safe calls │ │ │ Specifications │ │
31+ │ │ + Routing │ │ │ + Functional opts │ │ │ + Validation Rules │ │
32+ │ │ + Validation │ │ │ + Error handling │ │ │ + Header Parameters │ │
33+ │ └─────────────────────┘ │ └─────────────────────┘ │ └─────────────────────────┘ │
34+ └─────────────────────────┴─────────────────────────┴─────────────────────────────┘
35+ │
36+ ▼
37+ ┌─────────────────────────────────────────────────────────────────────────────────┐
38+ │ Standard Go HTTP Stack │
39+ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────────────────────┐ │
40+ │ │ net/http │ │ Gin/Echo/ │ │ Generated Type-Safe Clients │ │
41+ │ │ │ │ Chi/Fiber │ │ (Direct protobuf integration) │ │
42+ │ └─────────────────┘ └─────────────────┘ └─────────────────────────────────┘ │
43+ └─────────────────────────────────────────────────────────────────────────────────┘
4644```
4745
4846## Plugin Architecture
@@ -73,6 +71,7 @@ func main() {
7371| Plugin | Primary Function | Output | Dependencies |
7472| --------| -----------------| ---------| --------------|
7573| ` protoc-gen-go-http ` | Generate HTTP handlers, routing & validation | ` *_http*.pb.go ` | ` protoc-gen-go ` , sebuf annotations |
74+ | ` protoc-gen-go-client ` | Generate type-safe HTTP clients | ` *_client.pb.go ` | ` protoc-gen-go ` , sebuf annotations |
7675| ` protoc-gen-openapiv3 ` | Generate OpenAPI specifications | ` *.yaml ` , ` *.json ` | None (standalone) |
7776
7877## Code Generation Pipeline
@@ -84,10 +83,12 @@ graph TD
8483 A[.proto files] --> B[protoc compiler]
8584 B --> C[CodeGeneratorRequest]
8685 C --> D[protoc-gen-go]
86+ C --> E[protoc-gen-go-client]
8787 C --> F[protoc-gen-go-http]
8888 C --> G[protoc-gen-openapiv3]
89-
89+
9090 D --> H[.pb.go files]
91+ E --> I[*_client.pb.go]
9192 F --> J[*_http*.pb.go]
9293 G --> K[OpenAPI specs]
9394```
@@ -170,7 +171,48 @@ func (g *HTTPGenerator) Generate() error {
170171HTTP Request → Content -Type Detection → Binding Middleware → Service Method → Response Marshaling → HTTP Response
171172```
172173
173- ### 2. OpenAPI Generator
174+ ### 2. HTTP Client Generator
175+
176+ ** Location** : ` internal/clientgen/ `
177+
178+ ** Architecture** :
179+ ``` go
180+ type Generator struct {
181+ plugin *protogen.Plugin
182+ }
183+
184+ func (g *Generator ) Generate () error {
185+ for _ , file := range g.plugin .Files {
186+ // Generate client file for services
187+ // *_client.pb.go with interface and implementation
188+ g.generateClientFile (file)
189+ }
190+ }
191+ ```
192+
193+ ** Generated Components** :
194+
195+ 1 . ** Client Interface** - Type-safe client contract
196+ 2 . ** Client Implementation** - HTTP client with request/response handling
197+ 3 . ** Client Options** - Functional options for configuration
198+ 4 . ** Call Options** - Per-request customization options
199+ 5 . ** Header Helpers** - Generated from service/method header annotations
200+
201+ ** Request Flow** :
202+ ``` go
203+ // Generated client request pipeline
204+ Method Call → Build URL → Apply Headers → Serialize Body → HTTP Request → Deserialize Response → Return
205+ ```
206+
207+ ** Key Features** :
208+ - Functional options pattern for client configuration
209+ - Per-call options for request customization
210+ - Automatic path parameter substitution
211+ - Query parameter encoding for GET/DELETE
212+ - JSON and protobuf content type support
213+ - Typed error handling with ` ClientError `
214+
215+ ### 3. OpenAPI Generator
174216
175217** Location** : ` internal/openapiv3/ `
176218
@@ -185,12 +227,12 @@ type Generator struct {
185227func (g *Generator ) ProcessFile (file *protogen .File ) {
186228 // 1. Extract document metadata
187229 g.updateDocumentInfo (file)
188-
230+
189231 // 2. Process all messages → schemas
190232 for _ , message := range file.Messages {
191233 g.processMessage (message)
192234 }
193-
235+
194236 // 3. Process all services → paths
195237 for _ , service := range file.Services {
196238 g.processService (service)
0 commit comments