2

What is the best practice to hold proto folder for multiple platform, such as backend, iOS, Android, and Web? I came up with 3 ideas. Which one would be the best? Do you know better ideas than them?

1st: Should I have all in 1 repository including proto folder?

2nd: Should I split all like proto repo, iOS repo, backend repo etc, and share proto folder as a git submodule?

3rd: Should I make independent proto folder for all repos?

Pytan
  • 1,138
  • 11
  • 28

2 Answers2

2

My recommendation is that you use one repository for your proto files and use something like git submodules to include it in other repositories. The reasons are the following:

  • Proto files generally change way less often than your code, so low overhead when using git submodules (no need to git pull all the time).

  • It prevents having different versions of your proto files which can lead to unexpected behaviours when field tags are mismatching.

  • Modularity. If later you decided to do another project (eg: Desktop app) with the same proto files, you would just add a submodule, not copy everything and make specific changes to your project.

Furthermore, proto files are design to be shared across different language by being able to add options for specific languages. If you use this submodule in a iOS project and generate code for Swift only the options for Swift will be taken into account, same for Kotlin/Java and same for JS.

Even though I believe this is the safest way to manage your proto files, that's only my recommendation. Different use cases might need different architecture.

Clément Jean
  • 1,735
  • 1
  • 14
  • 32
  • Is that damend Git submodule the only way? I tried and that doesn't work well. I cannot remember the exact commands to type again, again and again, when cloning the repository, when switching branches, etc., and I really want to avoid wrapper scripts as other developers will inflate them with lots of "necessary temporary" workarounds. – Eric Buist Mar 24 '23 at 14:15
  • @EricBuist I agree that the git submodules are not intuitive. Another consideration would be to do a monorepo where the apps depending on your schemas live in the same repo as your .proto files. – Clément Jean Mar 25 '23 at 05:50
0

Best way would be a Git repository with only the .proto files and some CI pipeline that would package wither the .proto files, either .proto+generated code, for consumption by other projects. The artifacts are language-specific so creating them is a lot of headache, requiring to deal with respective build and packaging systems, and often it requires a prebuild step copying the .proto files from the central place to the package-specific subdirectory. If that doesn't work, maybe the best would be to copy the .proto files in each Git repository but have a tool to synchronize them with some master Git repository. In all cases, this is a lot of boilerplate code each and every developer of large project will have to write and maintain, because more and more, it looks like things are well-tested for small projects on a single repository. I'm pretty sure Google has a solution in-house and other companies have their own in-house solution that they won't share for years or will have us pay for.

Eric Buist
  • 73
  • 5