A monorepo, short for monolithic repository, is a single version control repository that holds the source code of many distinct projects, such as applications, services and shared libraries, under one history and one set of tooling. In programming and among development tools, it is a repository strategy, not an architecture: a monorepo can contain dozens of independently deployed microservices.
The opposite approach is the polyrepo (or multi-repo), in which each project lives in its own repository. The choice affects how teams share code, review changes, run builds and coordinate releases, and it determines which build tools and version control features become essential.
How a monorepo is organized
A monorepo groups projects into a predictable directory layout, typically folders such as apps/, services/ and packages/ or libs/. Each project keeps its own build definition, while the repository root holds shared configuration for linters, code formatters, continuous integration and dependency versions.
Internal libraries are consumed directly from source rather than as published packages. A change to a shared library and to all of its callers can therefore land in one atomic commit and one pull request, which is the central advantage of the model.
| Component | Purpose | Common examples |
|---|---|---|
| Workspace manager | Links local packages and installs dependencies once | npm, pnpm or Yarn workspaces |
| Build system | Builds and tests only what a change affects | Bazel, Nx, Turborepo, Pants |
| Dependency graph | Records which projects depend on which | Generated by the build system |
| Ownership file | Maps directories to responsible reviewers | CODEOWNERS file |
| Remote cache | Reuses build outputs across machines | Shared cache server or service |
Monorepo compared with polyrepo
The monorepo and the polyrepo trade coordination cost for isolation. A monorepo makes cross-project changes cheap and keeps versions consistent, while a polyrepo gives each team independent permissions, release cycles and tooling at the price of harder integration.
| Aspect | Monorepo | Polyrepo |
|---|---|---|
| Cross-project change | One commit and one review | Coordinated changes across several repositories |
| Dependency versions | Usually one version per library | Each repository pins its own versions |
| Code discovery | Search across all code at once | Requires knowing which repository to open |
| Access control | Coarse by default, directory rules needed | Natural per-repository permissions |
| Build tooling | Needs graph-aware, incremental builds | Simple per-project pipelines suffice |
| Clone and checkout size | Grows with the whole organization | Small and fast per repository |
A frequent misconception is that a monorepo forces monolithic deployment. Deployment units remain independent; only the source history is shared. Conversely, a polyrepo does not guarantee loose coupling, because services can still depend on each other through shared packages and APIs.
Some organizations choose a hybrid model: a few domain monorepos, each owned by a group of related teams, instead of one repository for the entire company. This keeps atomic changes within a domain while limiting repository size and preserving clear ownership boundaries between unrelated products.
Build and version control techniques at scale
A large monorepo stays fast only when tooling avoids rebuilding and retesting everything on every change. The build system computes the affected projects from the dependency graph and the changed files, then runs tasks only for those projects and their dependents.
- Incremental builds: outputs are reused when inputs have not changed, based on content hashes.
- Remote caching: one machine’s build results serve every developer and CI runner.
- Sparse checkout: Git checks out only the directories a developer needs.
- Partial clone: Git downloads file contents on demand instead of the full history of every file.
- Hermetic builds: declared inputs and pinned toolchains make results reproducible, which is the precondition for safe caching.
- File system monitoring: a background watcher keeps
git statusfast in very large working trees.
Branching discipline matters as much as tooling. Most monorepo teams use trunk-based development with short-lived Git branches and feature flags, because long-lived branches accumulate merge conflicts quickly when hundreds of developers commit to the same trunk.
When a monorepo is the right choice
A monorepo fits best when projects share substantial code and change together frequently. It fits poorly when projects are unrelated, owned by separate organizations or subject to strict confidentiality boundaries.
| Situation | Recommended choice | Reason |
|---|---|---|
| Frontend and backend share types and libraries | Monorepo | Atomic changes keep both sides in sync |
| Many small services built by one platform team | Monorepo | Consistent tooling and dependency versions |
| Open-source project with external contributors per module | Polyrepo or hybrid | Separate permissions and release cadence |
| Code under different licenses or legal restrictions | Polyrepo | Clear access and distribution boundaries |
| Small team without build engineering capacity | Small monorepo with simple workspaces | Benefits appear before scaling problems |
Limitations and common pitfalls
A monorepo moves complexity from coordination into tooling and governance. Without investment in both, the benefits erode as the repository grows.
- Slow continuous integration when pipelines run every test for every commit instead of affected targets only.
- Uncontrolled coupling, because importing another team’s internal code is trivially easy without enforced module boundaries; visibility rules in the build system or lint rules that forbid deep imports keep the dependency graph intentional.
- Single-version friction: upgrading one shared dependency may require fixing dozens of projects at once.
- Noisy history and reviews, which ownership files and path-based notifications must filter.
- Tooling limits in IDEs, language servers and Git hosting when the repository reaches millions of files.
Migration itself carries risk. Merging existing repositories with tools that preserve commit history keeps blame and audit trails intact, while importing only a snapshot is faster but loses the provenance of every line. Teams usually migrate one project at a time and keep the old repository read-only for reference.
Understanding it simply
Imagine a company that keeps every department’s documents in one shared filing cabinet instead of separate cabinets in separate rooms. Anyone can find related papers quickly, and one update can fix the same mistake everywhere at once.
The cost is that the cabinet needs good labels, clear owners and a fast index, or it becomes slow and confusing. A monorepo is that shared cabinet for software code.
Applied in practice
A software company with twelve developers maintains a web app, a mobile app, a public API and a shared design library in four separate repositories. Every change to the shared data types requires three coordinated pull requests, and versions regularly fall out of sync.
The team moves all four projects into one monorepo with pnpm workspaces and Turborepo. A single pull request now updates the shared types and every caller, and the pipeline uses affected-project detection and remote caching. The average CI run drops from about 25 minutes to under 8 minutes, and release-day version mismatches stop occurring entirely.