Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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)

PrincipleGoogle’s PracticeOur Application
Single Repo95% of code in one placeAll 400 repos → 1 mono-repo
Trunk-BasedDirect commits to mainPre-commit review, small changes
Code OwnershipOWNERS files per workspaceCODEOWNERS per component
Build SystemBazel (incremental)Bazel/Turborepo/Nx based on stack
Automation24K automated commits/dayAI agents + automation
AccessDefault open, exceptions restrictedOpen 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 TaskOutput
Freshness checkActivity score
Dependency mappingDependency graph
Code quality scanQuality metrics
Usage analysisImport/deployment count
Merge recommendationKeep/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)

StepAction
1Pre-migration check (deps, conflicts)
2Code transfer (preserve git history)
3Integration (update builds, fix imports)
4Validation (CI/CD, tests, smoke)
5Cutover (archive old repo)

Deliverable: migration-runbook.md (refined from pilot)


Phase 4: Bulk Migration (Week 4-8)

Remaining ~380 repos in batches

PriorityReposDuration
P0 (core products)~503-5 days
P1 (platform)~1005-7 days
P2-P3 (tools, libs)~1507-10 days
P4-P5 (cleanup)~1002-3 days

Phase 5: AI Enablement (Week 8+)

Closed-loop development

CapabilityDescription
AI Code GenerationFeature development, bug fixes
AI Code ReviewAutomated PR review
AI Test GenerationCoverage-guided test creation
AI RefactoringCross-component optimization
AI DeploymentAuto-scaling, multi-region routing
AI Progress TrackingSprint planning, task estimation

Deliverable: ai-dev-loop-spec.md, ai-first-methodology.md


Success Metrics

MetricCurrent6 Months12 Months
AI-completed features0%20%50%
AI-identified optimizations0100/week500/week
AI-deployed changes0%10%40%
Human time on routine tasks60%30%10%
Build time (incremental)N/A<5 min<3 min
PR review timeN/A<4 hours<2 hours

Resource Requirements

Infrastructure

ResourceMinimumRecommended
CPU8 cores16+ cores
Memory16 GB32+ GB
Storage100 GB SSD500 GB+ SSD
Network1 Gbps10 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

RiskImpactMitigation
Data lossHighFull backups before each batch
DowntimeHighParallel run (old + new)
Broken buildsMediumComprehensive tests, canary deploys
Team disruptionMediumGradual migration, training
Performance degradationMediumIncremental builds, caching
Rollback neededLowKeep old repos read-only 30 days

Open Questions (Need Answers)

  1. Tech Stack: What languages/frameworks are in the 400 repos?

    • Determines build system choice (Bazel vs Turborepo vs Nx)
  2. Current CI/CD: What’s the existing pipeline?

    • Affects migration complexity
  3. Team Structure: How many engineers? How organized?

    • Affects CODEOWNERS design
  4. Deployment: How are services currently deployed?

    • Affects infra design
  5. 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.mdDONE
  • codeowners-template.mdDONE
  • build-system-evaluation.md

Conclusion

This project is not just about consolidating code. It’s about:

  1. Building the foundation for AI to own the full engineering lifecycle
  2. Learning from Google’s playbook (2B LOC proven)
  3. Going beyond Google with AI-first decision automation
  4. 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