Monorepo

Also known as: monolithic repository

On this page 7

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.

ComponentPurposeCommon examples
Workspace managerLinks local packages and installs dependencies oncenpm, pnpm or Yarn workspaces
Build systemBuilds and tests only what a change affectsBazel, Nx, Turborepo, Pants
Dependency graphRecords which projects depend on whichGenerated by the build system
Ownership fileMaps directories to responsible reviewersCODEOWNERS file
Remote cacheReuses build outputs across machinesShared cache server or service
Typical building blocks of a monorepo

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.

AspectMonorepoPolyrepo
Cross-project changeOne commit and one reviewCoordinated changes across several repositories
Dependency versionsUsually one version per libraryEach repository pins its own versions
Code discoverySearch across all code at onceRequires knowing which repository to open
Access controlCoarse by default, directory rules neededNatural per-repository permissions
Build toolingNeeds graph-aware, incremental buildsSimple per-project pipelines suffice
Clone and checkout sizeGrows with the whole organizationSmall and fast per repository
Monorepo and polyrepo side by side

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 status fast 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.

SituationRecommended choiceReason
Frontend and backend share types and librariesMonorepoAtomic changes keep both sides in sync
Many small services built by one platform teamMonorepoConsistent tooling and dependency versions
Open-source project with external contributors per modulePolyrepo or hybridSeparate permissions and release cadence
Code under different licenses or legal restrictionsPolyrepoClear access and distribution boundaries
Small team without build engineering capacitySmall monorepo with simple workspacesBenefits appear before scaling problems
Decision guide for adopting a monorepo

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.