...

/

Module Code Organization

Module Code Organization

Learn efficient module code organization with protocol buffer APIs, composition root files, and internal packages to prevent unintended imports.

Each of the modules that makes up our application exposes a protocol buffer API and a small module file that contains the composition root for the module code. The modules also have their internal packages to keep unintentional imports from being made between the modules.

Press + to interact
Internal package import rules
Internal package import rules

The above figure illustrates how the multiple internal packages help us manage our relationships and control the dependencies between the modules:

  • /root/internal: This package can be imported by /root and any package found in the directory tree under it.

  • /root/pkg-b/internal: This package can only be imported by ...