Monorepository architecture
There are several benefits to using a mono repository for your project, but the most fundamental one is that it allows you to see the full codebase of your organization without having to locate and clone a slew of separate repositories. As a result of this, your frontend and backend code, the UI and utility libraries and documentation may all be shared with other developers via the same repository.
Splitting massive codebases into distinct versioned packages is incredibly valuable for code sharing. Making changes across many repositories, on the other hand, is confusing and prone to error, and testing across repositories becomes quite hard very quickly.
Some projects may arrange their codebases into multi-package repositories to address these (and other) issues. React, Angular, and many more projects create all of their packages in a single repository.
Rather than having separate repositories for each project, we use a mono-repo to centralize all of the related code repositories under one umbrella. This improves reusability, code sharing, and code refactoring and development teams can communicate more effectively.
Dependency management with monorepos
The real power, though, lies in dependency management. Monorepo tools may even help you to examine your project's complete dependency hierarchy, including all sub-projects, so that if someone makes a breaking change to a shared library, all related code will be easy to track down and update.
A mono repository can deduplicate third-party dependencies amongst many applications. Using a mono repo makes it much easier to perform continuous integration and DevOps operations since your code is already unified. However, when more apps and features are implemented, the size of monorepos becomes increasingly problematic.
Monorepos at scale
In order to maintain a mono repository at scale, the correct tools are extremely important, which is why Facebook developed Buck, Microsoft created Rush, and Google created Bazel. We're fortunate in that there are other options available. Workspaces may be easily defined by using the existing package management tools like yarn or npm.
Tools like these let you create a root-level package.json
file that serves as the basis for all of your project's nested workspaces, including apps and packages. Because it dedupes Node modules, you only need to install the same package once if you have the same package loaded in several apps. Another helpful feature is the ability to orchestrate scripts, which makes it possible to develop and test several apps at the same time. But if you're building an open source project that releases a lot of distinct packages, you'll probably want to check out lerna, a tool that can streamline the process of a multi-package repository.
Monorepos with lerna
Lerna is a tool for streamlining the process of managing multi-package repositories using git and npm. It gives you the option of managing your project in one of two forms:
- In fixed method, all package versions are kept at the same number.
- In independent method, each package may have its own version.
-
Date: