How taehoio/protoc-gen-go-ddl works
Project type and purpose
• This is an open‑source CLI tool: a Protocol Buffer compiler plugin written in Go (protoc-gen-go-ddl).
• Purpose: read .proto definitions and generate Data Definition Language (DDL) SQL statements and Go code stubs (DML interfaces) for supported datastores (currently MySQL, with planned MongoDB etc.).
File structure
• Top level:
• cmd/protoc-gen-marshal-input: a helper plugin (not the main one).
• main.go: entry point for protoc-gen-go-ddl.
• internal/ddl: core library—parsing protobuf descriptors, building DDL/DML AST, executing templates.
• internal/ddl/template: text/template files for SQL and Go code.
• protos: versioned .proto definitions for the plugin’s own FieldOptions and enums.
• gen/go: location of generated Go code when used via Buf or --go-ddl_out.
• testdata: sample protos and outputs for unit tests.
• Taskfile.yaml, buf.yaml, buf.gen.yaml, and GitHub actions: build, test, generate.
• Patterns & architecture:
• Single executable plugin.
• Separation of concerns:
– CLI layer (main.go, cmd/...)
– Core logic (internal/ddl)
– Codegen templates (internal/ddl/template)
– Protobuf definitions for plugin options (protos/...)
– Generated artifacts (gen/, testdata/gen/)
• Configuration & Deployment:
• Go module (go.mod, go.sum)
• buf plugin config (buf.gen.yaml)
• CI config (.github/workflows/ci.yml)
README for additional insights
• Describes plugin usage via Buf or direct protoc CLI.
• Defines supported datastores and data types.
• Illustrates code generation flow: proto → plugin → SQL + Go code.
• Shows DDL output and Go interface stubs for CRUD operations.
Detail
• Every logical step: proto parsing, AST creation, template execution.
• How testdata and CI fit in (optional sub‑component).