The protos
directory is structured to facilitate data modeling in a way that allows cross-language compatibility while maintaining a well-defined format for the Stellar ecosystem and downstream clients.
By defining clear .proto
specifications, we ensure:
- Cross-Language Code Generation: The same
.proto
files can be used to generate client libraries in Go, Python, Java, Rust, etc. - Consistent Data Representation: All downstream consumers (including Stellar-based applications) receive structured data in a well-defined format.
- Separation of Concerns: The
.proto
files define data models independently of any specific implementation logic. - Efficient Serialization: Protocol Buffers are lightweight and optimized for fast serialization/deserialization, making them ideal for large-scale data ingestion.
To maximize these benefits, the protos
directory is carefully organized to ensure clarity and maintainability.
The protos
directory follows a structured layout to ensure maintainability and clarity. The structure looks like this:
protos/
├── ingest/
│ ├── asset/
│ │ ├── asset.proto
│ ├── address/
│ │ ├── address.proto
│ ├── processors/
│ ├── token_transfer/
│ ├── token_transfer_event.proto
The generated Go code appears in the corresponding locations with the protos/
prefix stripped.
For example, the generated code for:
protos/processors/token_transfer/token_transfer_event.proto
will be generated under:
processors/token_transfer/token_transfer_event.pb.go
This structure is maintained to ensure Go packages align correctly with their corresponding .proto
files.
- The top-level include path for .proto files is
protos/
. - All imports inside
.proto
files must be relative to the top-levelprotos/
directory. - For e.g, in
protos/processors/token_transfer/token_transfer_event.proto
:Here,syntax = "proto3"; package token_transfer; import "google/protobuf/timestamp.proto"; import "ingest/address/address.proto"; import "ingest/asset/asset.proto";
address.proto
andasset.proto
are located at:protos/ingest/address/address.proto
andprotos/ingest/asset/asset.proto
-
Follow Directory Structure
- Organize
.proto
files into directories that match logical groupings. - Keep related
.proto
files together (e.g., All data models related to token_transfer should be underprotos/processors/token_transfer/
).
- Organize
-
Consistent Package Naming
- The
package
name inside each.proto
file should match the directory structure under which it appers. - For e.f, the package name for
protos/ingest/processor/token_transfer_event.proto
should be:syntax = "proto3"; package token_transfer;
- The
-
Generated Files
- Never edit the generated
.pb.go
files. - The go bindings from the
.proto
files are generated from the top level Makefileormake generate-proto
Always invoke these commands from the top-level directory.make regenerate-proto
- Never edit the generated
-
Helper Functions
- Any helper functions related to the generated protobuf structures should be placed in the same directory as the generated
.pb.go
files. - Ensure they use the same package name to maintain compatibility.
- Any helper functions related to the generated protobuf structures should be placed in the same directory as the generated
-
Checking in generateds
- Generated .pb.go files are committed to the repository.
- This ensures that clients using the package do not need to regenerate the bindings themselves when using the
ingest
package.