Successfully implemented a unified build tool that generates gRPC server and client code for multiple programming languages from centralized Protocol Buffer definitions.
- Created
proto/directory containing shared Protocol Buffer definitions - Added
hero.protoandcalculator.protoas examples - Enables single source of truth for all language implementations
- Go: Uses
protoc-gen-goandprotoc-gen-go-grpcplugins - Python: Uses
grpcio-toolswith full type hint support (.pyi files) - TypeScript: Uses
ts-protowith both general and NestJS-specific variants - Rust: Uses
tonic-buildfor modern async gRPC implementation
- Command-line interface with options for specific languages or all at once
- Automatic dependency installation for each language
- Cross-platform Protocol Buffers compiler auto-installation
- Organized output directory structure
- Comprehensive error handling and user feedback
npm run build- Generate for all languagesnpm run build:go- Go-specific generationnpm run build:python- Python-specific generationnpm run build:typescript- TypeScript/NestJS generationnpm run build:rust- Rust-specific generation
generated/
├── go/ # Go server/client (.pb.go, _grpc.pb.go files)
├── python/ # Python server/client (.py, .pyi, _grpc.py files)
├── typescript/ # TypeScript interfaces and NestJS decorators
│ └── nestjs/ # NestJS-specific metadata and decorators
└── rust/ # Complete Rust project with Cargo.toml and tonic
- Single command generates code for all supported languages
- Consistent behavior across different platforms
- Automatic tool installation and dependency management
- Proper error handling and validation
- Comprehensive documentation and examples
- Support for all gRPC features (unary, streaming, bidirectional)
- Language-specific optimizations and best practices
- Clear CLI interface with help and list options
- Detailed progress reporting and error messages
- Automatic cleanup of build artifacts
- Comprehensive usage examples for each language
- Easy to add new languages by extending the generators object
- Modular structure allows for language-specific customizations
- Configuration-driven approach
# Generate for all languages
npm run build
# Generate for specific language
npm run build:python
# List supported languages
node codegen.js --list- Add
.protofiles to theproto/directory - Run
npm run build - Generated code appears in language-specific directories
- Go: Import generated packages
- Python: Import generated modules
- TypeScript/NestJS: Use generated interfaces and decorators
- Rust: Add generated crate as dependency
- Single Source of Truth: All languages use the same proto definitions
- Consistency: Generated code follows language-specific best practices
- Productivity: Developers can focus on business logic instead of gRPC boilerplate
- Maintainability: Changes to APIs are automatically propagated to all languages
- Quality: Generated code includes proper type definitions and error handling
codegen.js- Main build toolpackage.json- Node.js dependencies and scriptsproto/hero.proto- Hero service definitionproto/calculator.proto- Calculator service definitionBUILD.md- Build tool documentationEXAMPLES.md- Usage examples.gitignore- Ignore build artifactsgenerated/- Complete directory structure with generated code
README.md- Updated with new build tool information
The solution uses:
- Node.js for the build tool (cross-platform compatibility)
- Protocol Buffers compiler (auto-installed)
- Language-specific plugins (automatically managed)
- Structured output (organized by language)
- Error handling (graceful failure with helpful messages)
This implementation fully satisfies the requirement to "build tool can generate proto file to server and client for multiple language (typescript nestjs, go, python, rust). use same proto folder contain proto file and generate."