Polyrepo to Monorepo Migration Plan
Migrating from a polyrepo (multiple repositories) to a monorepo (single repository) streamlines development by enabling atomic commits across services/apps, easier refactoring, shared tooling, and reduced dependency hell. However, it requires careful planning to avoid disruptions. This plan assumes a mid-sized engineering team (20-100 devs) working on a JavaScript/TypeScript/Node.js/React ecosystem (common for polyrepos), but it's adaptable. Total timeline: 3-6 months, depending on repo count (e.g., 10-50 repos).
1. Pre-Migration Assessment (Weeks 1-2)
Goals: Understand current state, risks, and ROI.
2. Strategy & Tooling Selection (Weeks 3-4)
Monorepo Strategy:
- Structure:
monorepo/
├── apps/ # Deployable apps (e.g., web, api)
├── packages/ # Shared libs/utils
├── services/ # Microservices
├── tools/ # Scripts, configs
└── docs/
- Branching: Trunk-based dev; tags for releases.
- Versioning: Independent (each package has own version) via Changesets.
- Access Control: Path-based GitHub branch protection (e.g., teams own
/apps/team-a).
Recommended Tooling Stack (JS/TS-focused, scalable):
| Category | Tool | Why? | Alternatives |
|---|
| Workspaces | pnpm | Fast, disk-efficient symlinks; strict hoisting. | Yarn Berry, npm 7+. |
| Build Orchestration | Turborepo | Remote caching, task pipelining; Vercel-hosted. Free tier. | Nx (Angular-heavy), Bazel (scale 100+). |
| Package Publishing | Changesets | Automated versioning/changelogs/PRs. | Lerna (legacy). |
| Lint/TypeCheck/Test | ESLint + Biome; tsup (build); Vitest/Jest. Turborepo pipelines. | - | Prettier, SWC. |
| CI/CD | GitHub Actions | Smart caching via Turborepo; affected-only builds. | CircleCI, Jenkins (w/ Bazel). |
| IDE Support | VS Code w/ workspaces | Multi-root support. | WebStorm. |
| Monorepo Mgmt | Git submodules/mirrors initially; then squash. | - | git subtree. |
Setup Script (Run in new monorepo):
mkdir monorepo && cd monorepo
pnpm init
pnpm add -D turbo pnpm@latest changesets typescript
pnpm exec turbo init # Creates turbo.json
echo "extends: ['turbo']" > .pnpmrc # Strict mode
3. Migration Execution (Weeks 5-12)
Phased Approach: Gradual to minimize downtime. Migrate 2-5 repos/week.
| Phase | Steps | Duration | Rollback Plan |
|---|
| 0. Bootstrap | 1. Create empty monorepo repo.2. Set up GitHub org repo w/ protections.3. Init tooling (pnpm workspace, turbo.json).4. Mirror polyrepos as subfolders (git remote add; git subtree push). | 1 week | Delete repo. |
| 1. Pilot (High-Coupling Repos) | 1. Migrate 1-2 libs first (e.g., UI kit).2. Update imports (absolute: @myorg/ui).3. Run turbo run build test.4. Dual-publish (poly + mono). | 2 weeks | Revert subtree. |
| 2. Bulk Migrate | 1. Scripted: Use gh repo clone + rsync.2. Fix deps: pnpm install (hoists shared).3. Configure turbo.json pipelines:json<br>{ "pipeline": { "build": { "dependsOn": ["^build"], "outputs": [".next/**"] } } }<br>4. CI: Affected changes only (--filter=...). | 4 weeks | Keep polyrepos live. |
| 3. Cutover | 1. Announce deprecation.2. Redirect CI/CD to monorepo.3. Archive polyrepos (read-only).4. Update docs/URLs. | 1 week | Restore polyrepo webhooks. |
Automation Scripts:
- Migration: Custom Node.js script using
simple-git to clone/merge.
- PR Validation: GitHub Action w/
turbo run lint --filter=....
Common Pitfalls & Fixes:
- Node_modules bloat: pnpm --shamefully-hoist=false.
- Build cycles: Turbo detects; break w/ opaque outputs.
- Large repo: Git LFS for binaries; split if >10GB.
4. Adoption & Training (Ongoing, Weeks 6+)
Goals: 80% team proficiency in 1 month post-cutover.
| Activity | Details | Owner | Timeline |
|---|
| Kickoff | All-hands demo: "Why mono? Live refactor demo." | Tech Lead | Week 3 |
| Training | 1h workshops: Tooling deep-dive, VS Code setup.Async: Notion/Slack guides. | DevRel | Weeks 5-8 |
| Pilot Squads | 2-3 teams migrate first; they become champions. | Squad Leads | Weeks 5-10 |
| Guidelines | CONTRIBUTING.md: Folder ownership, PR templates, "affected:build" commands. | Docs Team | Week 4 |
| Feedback Loops | Weekly retro; Slack #monorepo channel.Track: DORA metrics (deploy freq, lead time). | EM | Bi-weekly |
| Incentives | Hackathons for mono-only features. | Leadership | Month 2+ |
Change Management:
- Resistance Handling: Address "my repo, my rules" via demos of cross-team refactors.
- Success Stories: Blog post after pilot ("Reduced deps sync from 1d to 1h").
5. Post-Migration Maintenance (Month 4+)
- Monitoring: Build times (Turborepo dashboard), repo size (git-sizer).
- Scaling: If >100 devs, evaluate Bazel for finer caching.
- Exit Criteria: 90% PRs in monorepo; polyrepos archived.
- Annual Review: Reassess if polyrepo subsets needed (e.g., per-product).
Estimated Cost: $0-5k (Turborepo Pro if needed; free for most). ROI: 2-3x faster iteration within 3 months.
This plan is executable—start with assessment today. Need customization (e.g., for Go/Python)? Provide repo details! 🚀