Skip to content

@tank/monorepo-mastery

1.0.0

Monorepo architecture, tooling, and operations for any language or scale. Covers orchestrator selection (Nx, Turborepo, Bazel, Rush, Moon, Pants, Buck2), workspace managers (pnpm, Cargo, Go, uv, Gradle), polyglot patterns, CI/CD optimization, scaling, migration, and versioning. Triggers: monorepo, Nx, Turborepo, Bazel, Rush, Moon, Pants, pnpm workspaces, cargo workspaces, go.work, polyglot monorepo, affected builds, remote cache, changesets, monorepo CI, monorepo migration, sparse checkout.


name: "@tank/monorepo-mastery" description: "Monorepo architecture, tooling, and operations for any language or scale. Covers orchestrator selection (Nx, Turborepo, Bazel, Rush, Moon, Pants, Buck2), workspace managers (pnpm, Cargo, Go, uv, Gradle), polyglot patterns, CI/CD optimization, scaling, migration, and versioning. Triggers: monorepo, Nx, Turborepo, Bazel, Rush, Moon, Pants, pnpm workspaces, cargo workspaces, go.work, polyglot monorepo, affected builds, remote cache, changesets, monorepo CI, monorepo migration, sparse checkout."

Monorepo Mastery

Architect, build, and operate monorepos at any scale, in any language.

Core Philosophy

  1. Tooling is the entire game. A monorepo without proper tooling is worse than polyrepo. Invest in orchestration, caching, and affected detection before scaling.
  2. Start simple, scale deliberately. Begin with a workspace manager + lightweight orchestrator. Add complexity only when CI time or team size demands it.
  3. Affected-only everything. Build, test, lint, and deploy only what changed. Full pipeline runs on every PR are the number one monorepo anti-pattern.
  4. Cache aggressively, invalidate precisely. Content-addressed caching with correct input hashing is the foundation of monorepo performance.
  5. Boundaries prevent chaos. Enforce module boundaries, dependency direction, and ownership rules from day one. Architectural drift in a monorepo is exponentially harder to fix than in polyrepo.

Quick-Start

"I need to set up a new monorepo"

StepActionReference
1Detect existing signals (package.json, Cargo.toml, go.mod, etc.)This file
2Choose workspace manager for your language(s)references/workspace-managers.md
3Choose orchestrator based on scale and language needsreferences/tool-selection.md
4Configure CI with affected-only builds and cachingreferences/ci-cd-patterns.md
5Set up versioning and publishing if neededreferences/versioning-and-publishing.md

"My monorepo CI is too slow"

StepAction
1Enable affected-only builds (Nx affected, Turbo --filter, Pants --changed-since)
2Add remote caching (Vercel Remote Cache, Nx Cloud, Bazel RE API)
3Optimize git operations (shallow clone, sparse checkout)
4Parallelize independent tasks
-> See references/scaling-and-performance.md and references/ci-cd-patterns.md

"I want to consolidate polyrepos into a monorepo"

StepAction
1Audit repos: dependencies, CI, ownership
2Choose migration strategy (git subtree, git-filter-repo, strangler fig)
3Set up target monorepo with workspace config
4Migrate incrementally, one repo at a time
5Verify CI parity before cutting over
-> See references/migration-guide.md

"I have a multi-language monorepo"

StepAction
1Choose repo structure pattern (domain-first, language-first, hybrid)
2Set up cross-language contracts (protobuf, OpenAPI)
3Choose polyglot orchestrator (Bazel, Pants, Moon)
4Configure shared tooling (Lefthook, .editorconfig, CODEOWNERS)
-> See references/polyglot-patterns.md

Project Detection

Before recommending tools, check for existing signals:

SignalIndicatesFiles to Check
turbo.jsonTurboreporoot
nx.jsonNxroot
rush.jsonRushroot
.moon/workspace.ymlMoon.moon/
pants.tomlPantsroot
MODULE.bazel or WORKSPACEBazelroot
pnpm-workspace.yamlpnpm workspacesroot
Cargo.toml with [workspace]Cargo workspacesroot
go.workGo workspacesroot
[tool.uv.workspace]uv workspacespyproject.toml
settings.gradle.kts with includeGradle multi-projectroot

Decision Trees

Orchestrator Selection (Quick)

SignalRecommendation
JS/TS only, <20 packages, want simplicityTurborepo
JS/TS, 20+ packages, need code gen + pluginsNx
JS/TS enterprise, strict dep governanceRush
Publishing many npm packagesLerna (or Changesets)
Python-heavy, with Go/Java/DockerPants
JS/TS + Rust/Go/Python, medium scaleMoon
True polyglot, 100+ engineersBazel
Meta ecosystem, maximum extensibilityBuck2
JVM only (Java/Kotlin/Scala)Gradle

Workspace Manager Selection (JS)

SignalRecommendation
Default for new projects 2026pnpm
Need zero-install, offline CIYarn Berry (PnP)
Fastest runtime + managerBun
Minimal setup, small teamnpm

Versioning Strategy

SignalStrategy
Libraries consumed independentlyIndependent (Changesets)
Framework with tight couplingFixed/locked (Lerna)
Mix of bothHybrid (grouped Changesets)

Anti-Patterns

Don'tDo InsteadWhy
Run all tests on every PRUse affected detectionCI time scales linearly with repo size
Skip remote cachingEnable from day oneLocal-only caching wastes CI compute
Allow unrestricted importsEnforce module boundariesPrevents spaghetti dependencies
Manual version bumpsUse Changesets or conventional commitsHuman error, forgotten changelogs
Full git clone in CIShallow clone + sparse checkoutClone time dominates in large repos
One giant packageSplit by domain/concernDefeats purpose of monorepo tooling

Reference Files

FileContents
references/tool-selection.mdOrchestrator comparison (Nx, Turborepo, Bazel, Rush, Moon, Pants, Buck2, Gradle), decision matrices, feature comparison, migration complexity
references/workspace-managers.mdWorkspace managers for all languages (pnpm, npm, Yarn, Bun, Cargo, Go, uv, Gradle, .NET, CMake/Conan), config examples, comparison tables
references/polyglot-patterns.mdMulti-language repo structure, cross-language deps (protobuf, OpenAPI), shared tooling, CODEOWNERS, real-world examples (Google, Meta, Uber)
references/ci-cd-patterns.mdGitHub Actions, GitLab CI, CircleCI monorepo patterns, affected-only CI, remote caching setup, merge queues, workflow examples
references/scaling-and-performance.mdGit performance (sparse checkout, Scalar, Sapling), build caching, affected detection algorithms, incremental builds, scale thresholds
references/migration-guide.mdPolyrepo-to-monorepo (git subtree, git-filter-repo), monorepo-to-polyrepo extraction, tool migrations, incremental migration strategy
references/versioning-and-publishing.mdChangesets, Lerna, semantic-release, publishing to npm/PyPI/crates.io, dependency management (Renovate, Sherif, module boundaries)

Command Palette

Search skills, docs, and navigate Tank