Overview
The microservices-app project uses Protocol Buffers (protobuf) for defining service contracts and message schemas. Buf is used as the build system and schema registry for managing proto definitions.Directory Structure
All proto definitions are stored in theproto/ directory at the root of the repository:
buf.yaml Configuration
Thebuf.yaml file at the repository root configures buf’s behavior:
Configuration Details
- version: Uses buf v2 configuration format
- modules.path: Defines
proto/as the module root containing all proto files - lint.use: Applies the
STANDARDlint ruleset, which enforces Google’s proto style guide - breaking.use: Uses
FILElevel breaking change detection to ensure backward compatibility
Linting Proto Files
Buf automatically validates proto files against style and consistency rules:STANDARD lint rules enforce:
- Proper naming conventions (PascalCase for messages, snake_case for fields)
- Required package declarations
- Consistent file structure
- Comment formatting
Breaking Change Detection
To ensure backward compatibility, buf can detect breaking changes against a previous version:FILE breaking change strategy detects:
- Removed or renamed messages, fields, or services
- Changed field types or numbers
- Removed enum values
- Changed service method signatures
Combined Lint and Breaking Check
The repository provides a convenient command to run both checks:buf lint- Validates proto style and structurebuf breaking --against main- Checks for breaking changes
Proto File Naming Conventions
The project follows these conventions:- Package names:
<service>.v1(lowercase with version) - File structure:
proto/<service>/v1/<service>.proto - Go package option: Includes full import path with version suffix
Example Structure
For a service namedgreeter:
Version Management
All services usev1 versioning in their package names and directory structure. When introducing breaking changes:
- Create a new version directory:
proto/<service>/v2/ - Update package name:
package <service>.v2 - Update
go_packageoption to includev2 - Maintain both versions during migration
Next Steps
- Code Generation - Learn how to generate Go and TypeScript code from proto definitions
- Creating Services - Create new proto definitions and services