PABCD Initiative Documentation Hub pabcd_initiative codexclaw cli-jaw

Monorepo Tooling — Turborepo vs Nx (2026)

Source: dev-scaffolding/references/monorepo-tooling.md

Monorepo Tooling — Turborepo vs Nx (2026)

Last reviewed: 2026-06-16

Applies to: Turborepo 2.x, Nx 21.x

When to read: Setting up or optimizing a monorepo build system

Canonical owner: dev-scaffolding

Cross-ref: dev-architecture (module boundaries, dependency rules), dev-devops (CI optimization)

1. Decision Table: Turborepo vs Nx

FactorTurborepo 2.xNx 21.x
PhilosophyBuild orchestrator — minimal, fast, zero-config startFull platform — graph analysis, code generation, migrations
Setup complexityLow — npx turbo init, works with existing package.json scriptsMedium — npx create-nx-workspace, opinionated project structure
Task graphInferred from package.json scripts + turbo.json pipelineExplicit project graph with project.json or inferred from package.json
Remote cacheVercel Remote Cache (free tier) or self-hosted (Turborepo server)Nx Cloud (free tier) or self-hosted (Nx Powerpack)
Code generationNone built-in — use custom scriptsBuilt-in generators (nx generate), community plugins
MigrationsManual — update turbo.json and scriptsAutomated migrations (nx migrate) across framework versions
IDE supportStandard — relies on TypeScript project referencesNx Console extension for VSCode/WebStorm
Affected analysisBasic — file hash comparisonAdvanced — project graph + file dependency analysis
Bundle size impactNone — CLI tool only, not in app bundleNone — CLI tool only
CommunityVercel ecosystem, simpler communityLarger plugin ecosystem, enterprise adoption

Decision guide:

SituationChooseWhy
Small-medium monorepo (2-10 packages), existing npm scriptsTurborepoMinimal config, works with existing setup
Large monorepo (10+ packages), need code generation and migrationsNxFull platform features justify the complexity
Vercel deploymentTurborepoNative integration, zero-config remote cache
Enterprise with strict dependency boundariesNxModule boundary enforcement, project graph constraints
AI agent operating on monorepoEither — see §2Both support affected filtering; Nx gives richer graph data

2. Task Graph for AI Agents

AI agents benefit from predictable, deterministic task execution:

CapabilityHow to UseTurborepoNx
Run only affectedturbo run test --filter=...[HEAD~1]nx affected -t testBoth support; Nx is more granular
Dependency graphturbo run build --graphnx graphBoth generate; Nx provides interactive UI
Parallel executionAutomatic based on graphAutomatic based on graphBoth parallelize independent tasks
Cache hit detectionturbo run build --drynx run-many -t build --dry-runCheck cache status before running
Task targetingturbo run test --filter=@scope/pkgnx run @scope/pkg:testTarget specific package tasks

Rules for AI agents working in monorepos:

  • Always use --affected or --filter to scope work — never run all tasks across all packages.
  • Check cache status with dry-run before executing — avoid redundant work.
  • Use the dependency graph to determine build order — do not guess.
  • When modifying shared packages, verify downstream consumers with affected analysis.
# Turborepo: run tests only for packages affected by recent changes
turbo run test --filter=...[HEAD~1]

# Nx: same concept
nx affected -t test --base=HEAD~1

# Turborepo: visualize task graph
turbo run build --graph

# Nx: interactive dependency graph
nx graph

3. Synthetic Monorepos (Nx)

Nx can manage projects that are not traditional npm workspaces:

Use CaseSetupWhen Useful
Polyglot repo (TS + Python + Go)Nx with custom executors per languageCI orchestration across language boundaries
Non-package directories as projectsproject.json in each directoryLegacy repos being incrementally monorepo-ified
Virtual packagesnx.json defines implicit dependenciesDocumentation, infrastructure-as-code alongside app code

Rules:

  • Use synthetic projects only when the alternative is a custom build system.
  • Each synthetic project must have explicit targets in project.json — implicit conventions break for non-standard layouts.
  • Test that nx affected correctly identifies synthetic project dependencies before relying on it.

4. CI Optimization

TechniqueTurborepoNxImpact
Remote cacheTURBO_TOKEN + TURBO_TEAM env varsNX_CLOUD_ACCESS_TOKEN env var60-90% CI time reduction on cache hit
Affected only--filter=...[base..head]--base=base --head=headSkip unchanged packages entirely
Parallel tasksDefault (based on CPU cores)--parallel=NSaturate CI runner CPU
Distributed executionVercel Remote Cache shares across runnersNx Agents distribute tasks across machinesFor very large monorepos (50+ packages)
# GitHub Actions — Turborepo with remote cache
- name: Build affected
  run: turbo run build test lint --filter=...[origin/main...HEAD]
  env:
    TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
    TURBO_TEAM: ${{ vars.TURBO_TEAM }}

# GitHub Actions — Nx with affected
- name: Build affected
  run: npx nx affected -t build test lint --base=origin/main
  env:
    NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

Rules:

  • Always set up remote cache — local-only cache does not help CI.
  • CI must use affected filtering with the merge base as reference.
  • Cache keys must include OS, Node version, and lockfile hash.
  • Periodically verify cache correctness by running a full build (weekly or on release branches).

5. Anti-Patterns

BannedSymptomFix
Running all tasks in CI30-minute CI on a 2-line changeUse affected / --filter (§4)
No remote cacheEvery CI run rebuilds from scratchConfigure Vercel/Nx Cloud or self-hosted cache (§4)
Circular package dependenciesBuild fails unpredictably, task graph errorsEnforce boundaries with @nx/enforce-module-boundaries or turbo pipeline ordering
Mixing Turborepo and Nx in same repoConflicting task runners, cache confusionChoose one — see §1 decision table
* dependencies between workspace packagesPhantom version resolution, non-deterministic buildsUse workspace:* protocol or exact version pins

Pre-flight

  • [ ] Monorepo tool chosen with documented rationale (§1)
  • [ ] Remote cache configured and verified in CI (§4)
  • [ ] affected filtering used in CI pipeline — no full-repo runs on PRs (§4)
  • [ ] Package dependency graph has no circular dependencies
  • [ ] AI agents use affected/filter and dry-run before executing tasks (§2)