Mono-Repo Consolidation: Executive Summary
TiDB Agentic Engineering AI-First Initiative
The Vision
Build a mono-repo where AI can autonomously:
- Design system architecture
- Develop features end-to-end
- Test and validate changes
- Deploy and monitor services
- Iterate based on outcomes
This is not just code consolidation. This is building the foundation for General Relativity: AI owns the full engineering lifecycle.
The Problem
Current State: 400+ Repositories, ~39GB
├── Products: TiDB, TiDB Next-Gen
├── Platform: TiDB Cloud SaaS
├── DevOps: Operations tools
├── Forks: Third-party dependencies
└── Abandoned: Unused projects
Issues:
❌ AI cannot see full system context
❌ Cross-repo optimization is impossible
❌ Human coordination overhead scales with repo count
❌ Dependency hell across repos
❌ Inconsistent tooling and practices
The Solution
Target State: 1 Unified Mono-Repo
├── AI-readable structure
├── AI-optimizable boundaries
├── Automated build/test/deploy
├── Clear ownership (CODEOWNERS)
└── Trunk-based development
Google’s Playbook (2 Billion LOC Proven)
| Principle | Google’s Practice | Our Application |
|---|---|---|
| Single Repo | 95% of code in one place | All 400 repos → 1 mono-repo |
| Trunk-Based | Direct commits to main | Pre-commit review, small changes |
| Code Ownership | OWNERS files per workspace | CODEOWNERS per component |
| Build System | Bazel (incremental) | Bazel/Turborepo/Nx based on stack |
| Automation | 24K automated commits/day | AI agents + automation |
| Access | Default open, exceptions restricted | Open within engineering |
Key Insight: If monorepo works for Google at 2B LOC with 25K engineers, it can work for us.
Our AI Advantage
Google built their system before AI was mainstream. We have a unique advantage:
Google (Human-Centric Automation)
Humans: Write code, review, fix dependencies, deploy
Automation: Formatting, dependency updates, builds, tests
Us (AI-First)
AI Agents: Write code, review, fix dependencies, optimize builds, deploy decisions
Humans: Define problems, set priorities, review architecture, handle edge cases
We’re not just matching Google. We’re going beyond.
Three-Layer AI Development Model
┌─────────────────────────────────────────────────────────────┐
│ AI Capability Layers │
├─────────────────────────────────────────────────────────────┤
│ Micro │ Skills, MCP, Tools │ Current state │
│ │ (Efficiency in existing) │ │
├─────────────────────────────────────────────────────────────┤
│ Meso │ Feature lifecycle │ Phase 4.2 │
│ │ (AI drives design→deploy) │ │
├─────────────────────────────────────────────────────────────┤
│ Macro │ System architecture │ Phase 4.3 │
│ │ (AI reorganizes everything) │ │
├─────────────────────────────────────────────────────────────┤
│ General │ AI owns everything │ End state │
│ Relativity │ │
└─────────────────────────────────────────────────────────────┘
Project Phases
Phase 1: Repository Analysis (Week 1-2)
400+ AI Agents analyze all repos
| Agent Task | Output |
|---|---|
| Freshness check | Activity score |
| Dependency mapping | Dependency graph |
| Code quality scan | Quality metrics |
| Usage analysis | Import/deployment count |
| Merge recommendation | Keep/Migrate/Archive |
Deliverable: repo-analysis-report.md
Phase 2: Mono-Repo Design (Week 2-3)
Infrastructure setup
mono-repo/
├── products/ # TiDB, TiDB Next-Gen
├── platform/ # Cloud SaaS
├── devops/ # Operations
├── libs/ # Shared libraries
├── tools/ # Build/dev tools
└── infra/ # Infrastructure
Key Decisions:
- Build system (Bazel vs Turborepo vs Nx)
- CODEOWNERS structure
- CI/CD path-based triggering
- Branching model (trunk-based)
Deliverables: mono-repo-structure.md, codeowners-template.md, build-system-evaluation.md
Phase 3: Pilot Migration (Week 3-4)
10-20 repos (P0 priority)
| Step | Action |
|---|---|
| 1 | Pre-migration check (deps, conflicts) |
| 2 | Code transfer (preserve git history) |
| 3 | Integration (update builds, fix imports) |
| 4 | Validation (CI/CD, tests, smoke) |
| 5 | Cutover (archive old repo) |
Deliverable: migration-runbook.md (refined from pilot)
Phase 4: Bulk Migration (Week 4-8)
Remaining ~380 repos in batches
| Priority | Repos | Duration |
|---|---|---|
| P0 (core products) | ~50 | 3-5 days |
| P1 (platform) | ~100 | 5-7 days |
| P2-P3 (tools, libs) | ~150 | 7-10 days |
| P4-P5 (cleanup) | ~100 | 2-3 days |
Phase 5: AI Enablement (Week 8+)
Closed-loop development
| Capability | Description |
|---|---|
| AI Code Generation | Feature development, bug fixes |
| AI Code Review | Automated PR review |
| AI Test Generation | Coverage-guided test creation |
| AI Refactoring | Cross-component optimization |
| AI Deployment | Auto-scaling, multi-region routing |
| AI Progress Tracking | Sprint planning, task estimation |
Deliverable: ai-dev-loop-spec.md, ai-first-methodology.md
Success Metrics
| Metric | Current | 6 Months | 12 Months |
|---|---|---|---|
| AI-completed features | 0% | 20% | 50% |
| AI-identified optimizations | 0 | 100/week | 500/week |
| AI-deployed changes | 0% | 10% | 40% |
| Human time on routine tasks | 60% | 30% | 10% |
| Build time (incremental) | N/A | <5 min | <3 min |
| PR review time | N/A | <4 hours | <2 hours |
Resource Requirements
Infrastructure
| Resource | Minimum | Recommended |
|---|---|---|
| CPU | 8 cores | 16+ cores |
| Memory | 16 GB | 32+ GB |
| Storage | 100 GB SSD | 500 GB+ SSD |
| Network | 1 Gbps | 10 Gbps |
Tooling
- Build System: Bazel / Turborepo / Nx
- Code Search: Sourcegraph / Zoekt
- CI/CD: GitHub Actions / GitLab CI
- Agent Framework: Custom (Python/Go)
Team
- Project Lead: 1 FTE
- Build/Infra Engineer: 1-2 FTE
- AI/ML Engineer: 1-2 FTE
- Team Representatives: 0.2 FTE each (for migration decisions)
Risks & Mitigation
| Risk | Impact | Mitigation |
|---|---|---|
| Data loss | High | Full backups before each batch |
| Downtime | High | Parallel run (old + new) |
| Broken builds | Medium | Comprehensive tests, canary deploys |
| Team disruption | Medium | Gradual migration, training |
| Performance degradation | Medium | Incremental builds, caching |
| Rollback needed | Low | Keep old repos read-only 30 days |
Open Questions (Need Answers)
-
Tech Stack: What languages/frameworks are in the 400 repos?
- Determines build system choice (Bazel vs Turborepo vs Nx)
-
Current CI/CD: What’s the existing pipeline?
- Affects migration complexity
-
Team Structure: How many engineers? How organized?
- Affects CODEOWNERS design
-
Deployment: How are services currently deployed?
- Affects infra design
-
Agent Hosting: Where will 400 agents run?
- Local cluster? Cloud? Hybrid?
Next Steps (Planning Phase: 1-2 Days)
Day 1: Analysis Framework
- Set up distributed agent infrastructure
- Define analysis metrics and scoring
- Create repo inventory (list all 400 repos)
- Run pilot analysis on 10 repos
Day 2: Mono-Repo Design
- Finalize directory structure
- Design build system architecture
- Plan migration tooling
- Create detailed migration runbook
Deliverables
-
repo-analysis-report.md -
mono-repo-structure.md -
migration-runbook.md -
ai-dev-loop-spec.md -
ai-first-methodology.md -
ai-capability-maturity.md -
google-monorepo-lessons.md✅ DONE -
codeowners-template.md✅ DONE -
build-system-evaluation.md
Conclusion
This project is not just about consolidating code. It’s about:
- Building the foundation for AI to own the full engineering lifecycle
- Learning from Google’s playbook (2B LOC proven)
- Going beyond Google with AI-first decision automation
- Enabling Agentic Engineering at scale
The goal is not to help humans do AI work. The goal is to have AI do the work, and humans define what matters.
Prepared for: TiDB Agentic Engineering AI-First Initiative Last updated: Planning Phase