Monorepos let multiple projects share code, dependencies, and tooling. At Google, everything lives in one monorepo. Here's how to do it at smaller scale.
Why Monorepo?
- Code sharing: Shared UI components, utilities, types across apps
- Atomic changes: Update a shared library and all consumers in one PR
- Consistent tooling: Same ESLint, TypeScript, test config everywhere
- Simplified dependencies: One node_modules, no version conflicts
pnpm Workspaces (Foundation)
Turborepo
Build system for monorepos. Caches task results and runs tasks in parallel.
Nx
More opinionated than Turborepo. Includes code generation, dependency graph visualization, and affected commands.
Comparison
| Feature | Turborepo | Nx |
|---|---|---|
| Setup complexity | Low | Medium |
| Caching | Local + Remote | Local + Nx Cloud |
| Code generation | No | Yes (powerful) |
| Dependency graph | Basic | Advanced + visualization |
| Plugin ecosystem | Minimal | Rich |
| Learning curve | Easy | Moderate |
When to Use a Monorepo
- Multiple apps sharing significant code
- Team ownership across packages
- Consistent versioning and deployment
When NOT to
- Single application
- Teams with very different tech stacks
- When CI/CD can't handle the scale