Recommendation: Local Generators
For the most robust and reproducible open-source workflow, we recommend using local generators. While it is possible to use remote plugins hosted by the Buf Schema Registry (BSR), using local plugins ensures your build pipeline is self-contained, runs offline, and is not subject to external rate limiting for unauthenticated users. This approach requires a one-time installation of the necessary generator plugins on your dev, build machine or CI environment.1. Install Prerequisites
You need the Buf CLI and the specific language generator plugins installed locally in your development environment and on your CI/CD agents.Install Buf CLI
Follow the official Buf installation guide for your OS.Install Generator plugins
Run the following commands to install the plugins for TypeScript, Go, and OpenAPI. TypeScript/JavaScript (via npm):2. Configure Buf
Create two configuration files in the root of your project (next to yourservices/ directory).
buf.yaml (Module Configuration)
This file defines your project as a Buf module and tells Buf where to find your proto files.
This example uses the Buf v2 configuration format. If you are migrating from v1, run
buf config migrate to update your configuration automatically. See the Buf v1 to v2 migration guide for details.buf.gen.yaml (Generation Targets)
This file tells Buf which plugins to run and where to output the generated code.
Update the Go Package Path: Replace
github.com/your-org/your-repo below with the actual module path for your Go project. This ensures imports work correctly in the generated Go code. local key tells Buf to use the locally installed plugin binary directly. For npm-installed plugins, use the full path to the binary in node_modules/.bin.
3. Run Generation
Run the following command in your project root to generate all artifacts:.proto files in your services/ directory (based on the setup in Define Contracts) and run the configured plugins.
Output Structure
You will see a newgen/ directory with your distributable artifacts:
4. Distribution Strategy & CI/CD Integration
Once these artifacts are generated, you need a strategy for distributing them to your consumers. This entire workflow should be automated within your CI/CD pipeline to run on every commit, merge or release.Strategy A: Monorepo (recommended for internal teams)
Best when producers and consumers are owned by the same organization. Check the entiregen/ directory into your version control system.
-
CI/CD: Your CI pipeline should run
wgc grpc-service generatefollowed bybuf generateto ensure thegen/folder is always in sync with your operation definitions. -
Consumers: Your internal applications import the SDKs directly from the file path (e.g.
import from ../../packages/sdk/gen/ts). - Pros: Easiest setup, atomic updates across services and consumers.
Strategy B: Polyrepo / Publishing
Best when APIs are consumed by external teams or third parties. Do not check thegen/ folder into version control. Instead, use CI/CD to generate and publish the artifacts.
-
CI/CD: Your pipeline runs the generation commands and then publishes the output to package registries.
-
TypeScript: Publish
gen/tsto npm as@your-org/sdk. -
Go: Push
gen/goto a separate Git repository that acts as a Go module. -
OpenAPI: Upload
service.openapi.yamlto your developer portal or host it on S3.
-
TypeScript: Publish
-
Consumers: Use standard tools (
npm install, go get) and semantic versioning. - Pros: Decouples producers and consumers, standard versioning for public consumption.