Skip to content

Repositories and monorepos

How to split code into repositories, structure a monorepo, assign ownership of code, and protect the branch that everyone integrates into. Integrating into trunk at least daily (TEST-3) and automated tests for dependency rules (TEST-4) are in Testing and delivery; team boundaries and Conway's law are in Principles; release branches and tags are in Versioning and releases. For workflow files on GitHub, also follow GitHub Actions.

Entries are sorted by score from 1 to 10 (criteria): 9โ€“10 start here or strongly recommended, 6โ€“8 recommended, 1โ€“5 further reading or conditional.

Adopted references

Key rules

Repository layout

Branches, ownership and review

How to enforce

Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.

  • 7 Nx enforce-module-boundaries rule (JavaScript and TypeScript): a lint rule that checks imports between projects against tag-based constraints, and flags circular dependencies between projects. Partly checks REPO-2.
  • 6 OpenSSF Scorecard checks: Branch-Protection scores the default and release branches' protection settings, and Code-Review checks that recent changes were reviewed before they merged; the highest Branch-Protection tiers also require review from code owners. Checks REPO-5, and partly REPO-6.
  • 6 dependency-cruiser (JavaScript and TypeScript): forbidden rules with group matching stop one package from importing another's internals, and fail CI on violations. Partly checks REPO-2.
  • 6 Import Linter independence contracts (Python): fail when modules that should be independent import each other, even indirectly. Partly checks REPO-2.
  • 5 Syncpack lint (JavaScript): fails CI when packages in a monorepo use different versions of the same dependency. Sherif's multiple-dependency-versions rule does the same. Partly checks REPO-1.
  • 4 turbo boundaries (experimental): reports imports of files outside a package's directory and of packages it doesn't declare as dependencies, and checks tag rules. Partly checks REPO-2.

Tutorials and further reading

  • 6 Crafting your repository (Turborepo): a guide, meant to be read in order, to structuring a JavaScript monorepo, managing dependencies, creating internal packages, and setting up tasks, caching and CI.
  • 6 Workspace (pnpm): setting up a multi-package workspace, and the workspace: protocol that links internal packages from the repository instead of a registry.
  • 5 Improving monorepo performance (GitLab): why large repositories get slow in Git, and how to keep clones and CI fast.