Should you put all your frontend projects in one repository or spread them across many? This is the first architectural decision every growing frontend team faces. The answer determines how you share code, run CI/CD, manage dependencies, onboard developers, and scale your organization. Get it wrong and you spend years fighting your own tooling.
MonorepoPolyrepoRepository ArchitectureCI/CD
What Are We Building?
A monorepo is a single repository that contains multiple distinct projects — usually a set of applications and shared libraries. A polyrepo (or multirepo) is the traditional approach where each project lives in its own repository. This is not just a technical distinction — it is an organizational strategy that shapes how teams collaborate, how fast they ship, and how much code they share.
The debate has intensified in the last five years. Companies like Google, Meta, and Microsoft famously run monorepos with billions of lines of code. At the same time, most open-source projects and many startups use polyrepos. The right answer depends on team size, product cohesion, and tooling maturity.
This article walks through both architectures from first principles. We will examine the tooling landscape (Turborepo, Nx, pnpm workspaces, Lerna), analyze CI/CD implications, explore migration strategies, and build a decision framework you can apply to your own organization.
Key Insight
Monorepo is not a tool. It is an organizational strategy enabled by tools. The same principle applies to polyrepo. The question is not "which tool to use" — it is "how does your team prefer to coordinate?" The architecture is a reflection of your team's collaboration model.
1 · Requirements & Scoping
Before choosing sides, define what you need from your repository architecture. These requirements are the lens through which every tradeoff should be evaluated.
Functional requirements
Code sharing: Shared UI components, utility functions, TypeScript types, and configuration files must be consumable across projects without friction.
Dependency management: A single source of truth for third-party package versions. Avoid the diamond dependency problem where two projects depend on incompatible versions of the same library.
Atomic refactoring: When you change a shared API, all consumers must update together. No two-week migration cycles with breaking changes across repositories.
Independent deployability: Teams must deploy their changes without waiting for other teams or triggering unrelated deployments.
Developer onboarding: A new developer should be productive in minutes, not hours. One clone, one install, one build command.
Non-functional requirements
CI/CD speed: Build and test times must scale sub-linearly with the number of projects. A change to one app should not trigger a full rebuild of every app.
Scaling: The architecture must support 1 team with 2 apps up to 15 teams with 50+ apps. Path-based ownership must be possible.
Tooling maturity: The tooling ecosystem must be stable and well-documented. Bleeding-edge tools introduce risk for production infrastructure.
Git history clarity: Developers must be able to understand the history of a specific project without noise from unrelated changes.
Storage and clone time: A full clone should not exceed practical limits. For large monorepos, partial clone support is required.
Tip
The single most important requirement is atomic refactoring. If you find yourself saying "we can't rename that function because it would break the other team's repo", you have outgrown polyrepo. Monorepo eliminates this problem entirely — a rename touches all callers in one commit.
2 · Architecture — Monorepo Deep Dive
A monorepo is a single git repository that contains multiple independently-deployable projects. The key architectural insight is that you separate project boundaries from repository boundaries. All code lives in one repo; project boundaries are enforced by directory structure, tooling configuration, and CODEOWNERS files.
Figure 1 — Monorepo architecture: all apps and packages in one repository, connected via pnpm workspaces and orchestrated by Turborepo's dependency graph.
Workspace configuration
The monorepo is powered by a workspace manager. pnpm, yarn, and npm all support workspaces — a mechanism for linking local packages without publishing them to a registry. pnpm is the fastest growing option because of its content-addressable storage and strict dependency isolation.
The magic is workspace:* protocol. When an app depends on @repo/ui, pnpm resolves it to the local package in packages/ui. No registry lookup, no version negotiation, no publish step. The link is resolved at install time and the consuming project always gets the latest local version.
Code sharing: Workspace aliases make every package available to every app without publishing. A change to@repo/ui is immediately visible to all consumers. No version bumps, no npm publish, no manual update in the consuming project.
Dependency management: A single lockfile (pnpm-lock.yaml) ensures every project uses the same version of every dependency. The diamond dependency problem — where App A needs React 18.2 and App B needs React 18.3 — is visible immediately and can be resolved in one place.
Atomic refactoring: Rename a function, change a type, update an API — every consumer in the monorepo is updated in the same commit. TypeScript catches mismatches at compile time across the entire repo.
Note
Monorepo does not mean monolith. It meanssingle repository, not single application. Each project in the monorepo should be independently deployable, independently testable, and independently owned. Tooling like Turborepo and CODEOWNERS enforce these boundaries at the repository level.
3 · Architecture — Polyrepo Deep Dive
Polyrepo is the default: one repository per project. Each team clones, builds, tests, and deploys independently. Shared code is published as npm packages that consumers install and version separately.
Figure 2 — Polyrepo architecture: each app in its own repository with independent CI/CD. Shared code is published to npm and versioned independently.
The package publishing workflow
In polyrepo, sharing code means publishing and consuming packages. A shared UI library lives in its own repository with its own CI/CD pipeline. When the maintainers make a change, they publish a new version to npm (or a private registry). Each consuming app then updates its dependency declaration and deploys.
This workflow — develop → test → build → publish → consume — is the fundamental unit of friction in a polyrepo setup. The publish step alone introduces a coordination cost that monorepo eliminates. Every shared change requires a version bump, a changelog entry, and a consumer update.
When polyrepo wins
Team autonomy: Each team controls its own tech stack, release schedule, and tooling configuration. No need to align with other teams on dependency versions or build tools.
Git history clarity: The commit log of a polyrepo contains only changes to that project. No noise from other teams' work. This makes code review and bisecting simpler.
CI/CD independence: A push to one repository triggers exactly one pipeline. No wasted builds on unrelated projects. No complex affected-project detection.
Scaling to many teams: Beyond 10-15 teams, coordination in a monorepo becomes a significant overhead. Polyrepo lets teams move independently without centralized governance.
The hidden costs
Duplicate dependencies: Each repo has its ownnode_modules. If three apps use React, React is downloaded, stored, and built three times. Disk usage grows linearly with the number of repos.
Version drift: Over time, different repos end up on different versions of shared dependencies. The design system package drifts from v2.1 in one app to v2.4 in another. Breaking changes cascade across repos.
Cross-repo refactoring: Changing a shared API means: update shared package → publish → update consumer A → publish → update consumer B → publish. This takes hours or days instead of minutes.
Onboarding friction: A new developer needs to clone N repos, install each one, configure each IDE workspace, and learn each project's unique setup. This multiplies onboarding time.
Warning
The worst-case scenario for polyrepo is version fragmentation. Team A updates the shared UI library to v3 with breaking changes. Team B is too busy to update. Team C depends on Team B's work. Soon you have three incompatible versions of the same library, and the cost of synchronizing becomes higher than the cost of moving to a monorepo. This is the "polyrepo trap."
4 · Tooling Landscape
The tooling ecosystem determines whether a monorepo is a productivity booster or a productivity sink. Here is the landscape as I see it in 2026.
Package managers
Feature
pnpm
Yarn Berry
npm workspaces
Content-addressable storage
✅
❌
❌
Strict dependency isolation
✅
⚠️ PnP
❌
Plug'n'Play
❌
✅
❌
Install speed (cold)
Fastest
Fast
Moderate
Adoption
Growing
Mature
Built-in
Task orchestrators
A package manager handles installs. A task orchestrator handles builds, tests, and other scripts. The orchestrator understands the dependency graph between projects and runs tasks in the correct order with maximum parallelism.
Turborepo
Turborepo is the most popular monorepo orchestrator for the JavaScript ecosystem. It uses a turbo.jsonfile to define the task dependency graph and caches task outputs by input hash. If nothing changed, the cached output is restored in milliseconds.
Key features: parallel execution, remote caching (via Vercel), task pipelines with dependsOn, and output pruning for deployment. Turborepo is framework-agnostic — it works with any project that has npm scripts.
Nx
Nx is the more feature-rich alternative. Beyond task orchestration, Nx provides code generation, dependency graph visualization, affected-project detection, and integrated tooling for specific frameworks (Next.js, Angular, NestJS). Nx Cloud offers distributed task execution across multiple machines.
The tradeoff: Nx has a steeper learning curve and more opinionated structure. Turborepo is simpler but lacks code generation and distributed execution (without Vercel). For most frontend teams, Turborepo + pnpm is the sweet spot — it handles 80% of the use case with minimal configuration.
Lerna (legacy)
Lerna was the original monorepo tool for JavaScript. It pioneered the workspace concept but has been largely superseded by Turborepo and Nx. Lerna 8+ integrates with Nx under the hood. I recommend Turborepo or Nx for new projects — Lerna is primarily relevant for maintaining legacy monorepos.
pnpm workspaces (chosen)
Fastest installs, strict isolation, content-addressable store. Best for large monorepos with many shared packages.
More features (code gen, distributed execution), steeper learning curve. Better for enterprises with complex build needs.
Yarn Berry (viable alternative)
PnP mode eliminates node_modules entirely. Good for very large repos. Less ecosystem compatibility.
5 · CI/CD & Deployment
CI/CD is where the monorepo vs polyrepo tradeoff becomes concrete. The pipeline design directly impacts developer productivity and deployment frequency.
Figure 3 — Build pipeline and developer workflow comparison. Monorepo enables selective builds and atomic refactoring; polyrepo requires full CI runs and version bump coordination.
Monorepo CI/CD
A monorepo CI pipeline uses the task orchestrator's affected-project detection. When a developer pushes a change to apps/web, only the web app and its dependencies are rebuilt. The other apps use cached outputs from the previous run.
The key insight: a single CI workflow handles all projects. The orchestrator (Turborepo or Nx) decides what to run based on what changed. The workflow definition is simple because the complexity lives in the task graph, not in the pipeline configuration.
Polyrepo CI/CD
Each polyrepo has its own CI pipeline. The pipeline is simple per-repo — checkout, install, build, test, deploy — but the overhead multiplies. Each repo needs its own CI configuration, its own secret management, and its own monitoring.
example.yaml
# .github/workflows/web.yml (Polyrepo — web-app)
name: Deploy Web
on:
push:
branches: [main]
pull_request:
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm test
- run: npm run build
- run: npx wrangler deploy
# .github/workflows/admin.yml (Polyrepo — admin-panel)
name: Deploy Admin
on:
push:
branches: [main]
pull_request:
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm test
- run: npm run build
- run: npx wrangler deploy
The advantage: each team owns their pipeline end-to-end. They can add steps, change deploy targets, and adjust timing without coordinating with other teams. The disadvantage: duplicated configuration across N repositories, and cross-repo changes require multiple pull requests across multiple CI runs.
Path-based ownership with CODEOWNERS
One common objection to monorepo is losing team autonomy. CODEOWNERS solves this: each directory can have an owning team that must approve changes. GitHub enforces this at the pull request level.
example.text
# .github/CODEOWNERS — path-based ownership in monorepo
# Default owners
* @core-platform-team
# Apps owned by specific teams
/apps/web/ @team-web
/apps/admin/ @team-admin
/apps/docs/ @team-docs
/apps/api/ @team-api
# Shared packages
/packages/ui/ @design-system-team
/packages/auth/ @security-team
/packages/config/ @platform-team
# CI config requires platform team review
/.github/workflows/ @platform-team
# Docs owned by docs team
/docs/ @docs-team
Note
CODEOWNERS is the monorepo's answer to "but my team needs autonomy." Combined with branch protection rules that require CODEOWNER approval per directory, it gives teams the same governance they would have with a separate repo — without the cross-repo coordination cost.
6 · Migration Strategy
Migrating from polyrepo to monorepo (or vice versa) is a significant engineering effort. A migration typically takes 8-12 weeks for a medium-size organization. Here is the phased approach I recommend based on real migrations at companies like Sentry and Shopify.
example.text
// Phase 1: Audit (Week 1-2)
// - Map all dependencies between projects
// - Identify shared packages (ui, auth, utils)
// - List duplicate dependencies across repos
//
// Phase 2: Scaffold (Week 3-4)
// - Create monorepo root with pnpm-workspace.yaml
// - Import packages into packages/ directory
// - Configure Turborepo with remote caching
//
// Phase 3: Migrate Apps (Week 5-8)
// - Move one app at a time into apps/
// - Replace npm package refs with workspace:*
// - Validate CI/CD still works per app
//
// Phase 4: Consolidate CI (Week 9-10)
// - Unify CI into single workflow
// - Configure CODEOWNERS for path-based ownership
// - Set up affected-project detection
//
// Phase 5: Cleanup (Week 11-12)
// - Archive old repositories (read-only)
// - Update docs, onboarding guides
// - Remove old npm publish pipelines
Key migration principles
Keep the old repos working: During the migration, existing CI/CD pipelines continue to run. The monorepo absorbs projects one at a time.
Preserve git history: Use git filter-repo to transplant history into the monorepo. Losing history breaks blame, bisect, and audit capabilities.
Start with shared packages: Migratepackages/ first. Once shared packages are in the monorepo, apps can switch from npm registry refs toworkspace:* refs.
Migrate one app at a time: Do not attempt a big-bang migration. Each app migration is a separate pull request with its own validation and rollback plan.
Set up ownership early: Configure CODEOWNERS before the first app is migrated. Teams must see that their ownership boundaries are preserved.
Common migration pitfalls
Surface-area explosion: A monorepo with 50+ projects can overwhelm IDE performance. Configure workspace settings to exclude unrelated projects from TypeScript's scope.
CI timeout: If affected-project detection is not configured correctly, every CI run builds everything. Start with Turborepo's filter options and validate with turbo build --dry-run.
Secret sprawl: Different apps need different secrets. Centralize secret management (GitHub Environments, Vault, Doppler) early in the migration.
Team resistance: The biggest barrier is not technical — it is organizational. Teams fear losing autonomy. Invest in CODEOWNERS, path-based CI, and clear SLAs before starting the migration.
Warning
Do not attempt a monorepo migration if your organization is mid-reorg, mid-fundraise, or mid-crunch. The migration requires organizational bandwidth and psychological safety. Pick a period of stability. The monorepo will still be there in six months.
7 · Performance & Optimization
Performance in a repository context is about developer experience: how fast can you clone, install, build, and run tests? Both architectures have performance characteristics that change with scale.
Monorepo performance challenges
Clone time: A monorepo with years of history and large binary assets can be slow to clone. Solutions: shallow clone (--depth 1), sparse checkout, or Git's partial clone protocol (--filter=blob:none).
Install time: pnpm's content-addressable store helps — packages are stored once globally and linked. Cold installs are still proportional to the total dependency set, but subsequent installs are near-instant.
IDE performance: TypeScript's --noUncheckedIndexedAccessand project references help the language server scope its analysis to relevant files. Configure excludein root tsconfig.json.
CI queue times: With a single CI pipeline, pushes from different teams queue behind each other. Parallelize at the task level (Turborepo's --concurrency) and consider remote caching to reduce build times.
Optimization strategies
Remote caching is the single highest-impact optimization for monorepo CI. Turborepo's remote cache (via Vercel) or Nx Cloud stores build outputs and restores them on cache hits. A CI run that rebuilds 5 unchanged apps goes from 5 minutes to 30 seconds.
Partial cloning for CI jobs that only need a subset of the repo. GitHub Actions supports fetch-depth: 0for full history or sparse-checkout for specific paths.
Task granularity: Break down build tasks so the orchestrator can run them in parallel. Turborepo's dependency graph automatically identifies parallel paths — but you need to define the tasks with appropriate granularity.
Polyrepo performance profile
Polyrepo is simpler to optimize because each repo is smaller. Clone times are fast, installs are scoped to one project's dependencies, and IDE performance is excellent. The performance cost is hidden: duplicated storage (N copies of the same dependencies across N repos) and developer context-switching (moving between repos, each requiring a new install).
Tradeoff table
Dimension
Monorepo
Polyrepo
Clone time
Slower (larger repo, more history)
Faster (smaller, focused repos)
Install time
Slower cold start, fast subsequent (store cache)
Fast per-repo, duplicated across repos
CI speed
Selective builds, cached outputs
Full build per repo, no cross-repo cache
Disk usage
Lower (shared dependencies)
Higher (N copies of same deps)
IDE responsiveness
Slower with many projects (needs config)
Fast (single project scope)
8 · Security Considerations
Repository architecture affects your security posture in several ways — from dependency management to access control to CI/CD integrity.
Dependency supply chain: In a monorepo, a single lockfile means one source of truth for dependency versions. Security scanners (Dependabot, Snyk) scan once and find all vulnerabilities. In polyrepo, each repo has its own lockfile. A vulnerability in lodash must be patched across N repositories independently.
Access control: Monorepo uses GitHub's CODEOWNERS and branch protection for access control. Polyrepo uses repository-level permissions. The polyrepo model is simpler: give a team access to their repo and they control everything. The monorepo model requires more nuanced permission management.
Secret management: Monorepo needs careful secret scoping. Not every CI job needs production deploy keys. Use GitHub Environments to scope secrets to specific deployment jobs. Polyrepo is simpler: each repo has its own secrets with clear boundaries.
Audit trail: Monorepo provides a single audit log — every change to every project in one timeline. This is valuable for compliance (SOC2, SOX). Polyrepo requires aggregating audit logs across repositories.
Leak surface: A compromised CI token in a monorepo exposes all projects. Mitigate with least-privilege secrets, short-lived tokens, and separate deploy environments. In polyrepo, a leak is scoped to one repo — but that also means more tokens to manage.
Tip
For monorepos, configure separate deploy environments in GitHub Actions. Each environment has its own secrets and protection rules. The web app deployment job uses the "production-web" environment; the admin deployment uses "production-admin." A leaked web deploy key cannot be used to deploy the admin app.
9 · Testing Strategy
Repository architecture strongly influences test strategy. The key difference is how you decide what to test on each change.
Monorepo testing
Affected-project testing: Turborepo and Nx determine which projects are affected by a change and run only their tests. A change to packages/uiruns UI tests plus tests of all apps that depend on UI.
Unified test configuration: Shared Vitest or Jest configs ensure consistent testing standards across all projects. No per-repo test setup drift.
Collective coverage thresholds: Enforce coverage requirements across the entire codebase, not per-repo. Teams cannot lower their standards in isolation.
Polyrepo testing
Simple, predictable: Every push runs the full test suite for that repo. No affected-project analysis needed.
No cross-repo test coverage: A change to the shared UI library is tested in the UI repo. The consuming apps do not automatically retest — they pick up the new version on their next deploy.
Independent test infrastructure: Each repo can use different test runners, reporters, and coverage targets. Flexibility at the cost of consistency.
The monorepo approach catches integration bugs earlier. When@repo/ui changes a component API, the monorepo's affected-project detection immediately runs the consumer app's tests and catches the breakage. In polyrepo, the breakage is discovered only when the consumer manually updates the dependency — which could be weeks later.
10 · Decision Framework
Here is the raw tradeoff comparison and the decision framework I use when advising teams.
Figure 4 — Decision tree for choosing between monorepo and polyrepo. The answer depends on team size, code sharing needs, and product cohesion.
Most SaaS products benefit enormously from monorepo. The shared auth, design system, and API client are the backbone of the product. Atomic refactoring lets you move fast without breaking things.
Independent products, different stacks → Polyrepo
If your apps target different user bases, have different brands, or use fundamentally different tech stacks, polyrepo gives teams the freedom they need. The sharing benefits of monorepo are minimal when apps don't share logic.
Large org (10+ teams) → Hybrid
Keep the core product suite in a monorepo. Let auxiliary products (docs, marketing, blog) live in polyrepos. The core monorepo publishes packages that the edge polyrepos consume.
Open-source projects → Polyrepo (usually)
Open-source projects benefit from polyrepo because contributors want to work on one project without cloning the entire organization's codebase. Exceptions exist (React, Babel) but they are rare.
Start with monorepo, split when it hurts
If you are starting a new project, default to monorepo. It is easier to split a monorepo into polyrepos later than to merge polyrepos into a monorepo. The cost of splitting is a week of tooling work. The cost of merging is months of migration.
Key Insight
The 80/20 rule applies here: 80% of the value of monorepo comes from sharing three things — auth, design system, and TypeScript types. If your projects do not share at least these three, monorepo may not be worth the overhead. Start with a shared packages repo and add apps as the need grows.
Hybrid approach (most common in practice)
In practice, most large organizations settle on a hybrid model. The core product suite lives in a monorepo; auxiliary products live in independent repos. The monorepo publishes packages to a private registry that the polyrepos consume.
example.text
# Hybrid Model: monorepo for core, polyrepo for edge
# ┌─────────────────────────────────────────┐
# │ Monorepo (github.com/org/core) │
# │ apps/web · apps/admin · apps/api │
# │ packages/ui · packages/auth · packages/config │
# │ Shared CI, shared deps, atomic deploys │
# └─────────────────────────────────────────┘
#
# ┌─────────────────────────────────────────┐
# │ Polyrepo (independent repos) │
# │ github.com/org/landing-page │
# │ github.com/org/blog │
# │ github.com/org/docs │
# │ Each team owns their stack & deploy │
# └─────────────────────────────────────────┘
#
# Core monorepo publishes @org/ui to npm
# Edge polyrepos consume @org/ui as dep
# No reverse dependency from polyrepo → monorepo
The hybrid model gives you the best of both worlds: atomic refactoring within the core suite, and full autonomy for edge products. The key rule is no reverse dependencies— polyrepos depend on the monorepo's published packages, never the other way around.
11 · Key Takeaways
Monorepo is not a tool — it is an organizational strategy. The tools (pnpm, Turborepo, Nx) enable the strategy. Start with the organizational model, then pick tools that fit.
Atomic refactoring is the killer feature.Being able to rename a function, change a type, or update an API across all consumers in one commit eliminates an entire class of coordination overhead. If you need this, choose monorepo.
Code sharing in polyrepo is not free. Every shared change requires: develop → test → publish → bump → consume. This friction causes teams to stop sharing over time, leading to code duplication and drift.
CODEOWNERS preserves team autonomy in monorepos.Path-based ownership with required reviews gives teams the same governance as separate repos — without the cross-repo coordination cost.
Hybrid is the most common production pattern.Monorepo for the core suite (auth, design system, primary apps) + polyrepo for auxiliary products (docs, marketing, legacy projects). No reverse dependencies.
Start with monorepo, split when it hurts.Splitting is a week of work. Merging is months. Default to monorepo and extract projects as they outgrow the coordination model.
The tooling ecosystem is mature. pnpm + Turborepo handles 80% of monorepo use cases. Nx adds code generation and distributed execution for complex needs. Either choice is production-ready.
Consider the human factor. The best architecture fails if the team does not buy into it. Involve engineers in the decision, address autonomy concerns early, and invest in onboarding documentation.
The monorepo vs polyrepo decision is not a technical problem — it is a people problem with technical consequences. The right answer depends on how your teams collaborate, how much they share, and how fast they need to move. There is no universal truth, but there is a framework for making the decision deliberately.