Monorepo(一个仓库用于多个项目/服务)和 polyrepo(每个项目一个单独的仓库)是在多个项目之间组织代码的两种策略。两者都有显著的权衡,影响协作、工具和扩展性——理解这些权衡有助于做出重要的架构决策。
Monorepo——一个仓库用于所有内容
Many projects/services/libraries in a SINGLE repository:
✓ SHARED code/libraries easy to use and refactor (one place, atomic changes)
✓ ATOMIC commits across projects (change an API and all its consumers together)
✓ Unified tooling, versioning, CI; consistent standards; easy cross-project visibility
✓ Simplified dependency management (one version of shared code)
✗ Repo can get HUGE (needs scaling tooling — sparse checkout, build caching)
✗ Needs sophisticated build/CI tooling (Nx, Turborepo, Bazel) to be efficient
✗ Broad access; CI must be smart (only build what changed)
→ Used by Google, Meta, etc. (with heavy tooling investment).
