Skip to content
nexovia
All insights

Architecture

Monorepo vs polyrepo: how a growing product team should choose

A monorepo pays off when web, mobile and backend change together. Separate repositories win when teams, stacks or access rules really are independent.

The Nexovia team · · 6 min read

Count the changes that cross a boundary

The monorepo vs polyrepo debate is usually framed as a matter of taste. We treat it as a set of measurements, and the first one is simple: how often one change touches more than one codebase. If a new field on an order has to appear in the API, the web app and the mobile app, and those three live in three repositories, every such feature becomes three pull requests, three reviews and a release order to get right.

When that happens every week, a monorepo removes real work. When it happens twice a year, separate repositories cost you almost nothing and keep each codebase simple. The other measurements are about people and constraints: how many teams there are, whether parts of the product must deploy on their own schedule, which languages are involved and who is allowed to see what.

What a monorepo gives you, and what it costs

A monorepo is one Git repository holding several applications and the packages they share. It is not a monolith: each app still builds and deploys separately, and a product made of microservices can live in one repository or in one repository per service. The gain is that a change and everything it affects travel in one commit.

The gains are largest when the stack shares a language. A Next.js site, a React Native app and a Node backend can share real code. A Laravel API and a Swift app can share a repository, but not much else. With a shared language, the gains are concrete:

  • Shared types and schemas: the API contract lives in one package, imported by the backend, the web app and the mobile app. A breaking change fails the type check in the same pull request instead of in production.
  • Shared packages without publishing: a UI kit, validation rules or an API client are consumed straight from source, with no private registry and no version bumps.
  • Atomic refactors: rename a function and fix every caller in one reviewable change.
  • The costs: CI needs dedicated tooling to avoid building everything, access is all or nothing, a broken main branch blocks every team at once, and keeping one version of each shared dependency, which is what makes sharing easy, means every app upgrades at the same time.

Monorepo tooling: pnpm workspaces, Turborepo, Nx

For a TypeScript monorepo, the base layer is the package manager. With pnpm workspaces, a pnpm-workspace.yaml file lists the folders that contain packages, and an app depends on a local package through the workspace: protocol, so pnpm links it instead of downloading it. For a small team this alone is a working monorepo.

Once builds get slow, you add a task runner on top. Turborepo reads the dependency graph between packages, runs tasks in the right order and in parallel, and caches the output of each task under a hash of its inputs. Nx does the same and adds code generators, a project graph you can visualize, and a lint rule that enforces which packages may import which. Turborepo fits a repository with a handful of apps and packages; Nx fits one shared by many teams, where boundaries have to be enforced by tooling. A repository that mixes several languages may need a build system made for that case, such as Bazel, and that is a serious investment of its own.

Keeping a monorepo fast and owned

The classic objection to a monorepo is that CI builds everything on every commit. It does, if you leave it untouched. Both Turborepo and Nx can compare a branch with main and run tasks only for the packages that changed and the ones that depend on them: Nx calls this nx affected, and Turborepo offers an --affected flag and filters. Remote caching is the second half: if a teammate or an earlier CI run already built a package with identical inputs, the result is downloaded instead of rebuilt. Every task must declare all of its inputs, including environment variables, or the cache will serve stale results.

One repository does not mean everyone owns everything. On GitHub, a CODEOWNERS file maps paths to teams, and branch protection can require a review from the owner before a merge. Keep shared packages small and named after what they do: a package called utils or common is where unrelated code piles up.

What separate repositories give you, and what they cost

A polyrepo gives each codebase its own history, its own pipeline, its own access list and its own release rhythm. Its cost is coordination: shared code has to be published as versioned packages to a private registry, a cross-cutting change becomes a chain of pull requests merged in the right order, and the contract between repositories has to be tested on its own, with an OpenAPI specification or contract tests. Separate repositories are the better fit when:

  • The codebases share no code. A PHP backend and a native iOS app meet only at the API, and an OpenAPI specification is enough of a contract.
  • The product is made of services owned by different teams, each deployed on its own schedule and talking to the others through versioned APIs or a message queue.
  • Access must be restricted. Git cannot hide a folder from someone who can clone the repository, so an external contractor or a client team that should see one component needs its own repository.
  • A component has a life of its own: it is open source, sold separately, or audited under different compliance rules.
  • The existing setup already works: separate pipelines, deployment scripts and permissions are in place, and merging them would cost more than the coordination it saves.

What we look at before choosing for a project

We do not have a default layout. We decide per project, after reading the existing code and talking to the people who will work in it. The questions we go through:

  • Teams: how many there are, how they are split, and whether they change the same features together or work on separate parts of the product.
  • Deployment and scaling: whether each part must be released and scaled on its own, and how often each one ships.
  • Languages and runtimes: a single TypeScript stack shares code easily, while a Kotlin app, a Swift app and a Python service share little beyond the API contract.
  • Compliance and security: whether some code or some people must be kept apart, for an audit, a contractor or a client.
  • What already exists: the current repositories, CI configuration and deployment tooling, and the experience of the team with either layout.

Hybrid layouts and changing your mind later

The choice is not binary. One workable layout is a few repositories, each one a small monorepo: one for the TypeScript web app and its backend, one for the native mobile apps, one for a component that a client team works on. The boundaries follow the teams and the access rules rather than a principle.

Moving later is possible in both directions: merging repositories into a monorepo can preserve Git history, and extracting a folder into its own repository is a routine operation. Neither move is free, so decide based on how your changes and your teams work today, and not on how a much larger company organizes its code. We write the reasons down in an architecture decision record in the repository, so the next person can see what the choice was based on and when to revisit it.

Keep reading

Design, build and ship your project

Describe it in three lines. We reply with specific questions and a first take on how to proceed.