MOE-Agents Architecture: C4 Model (C4 → C1)
System: Multi-tenant AI Agent Platform with CODITECT-CORE orchestration
Scope: Multi-Organization → Multi-Team → Multi-User → Multi-Project
LLM Providers: Gemini, Claude-Code, Codex, Kimi, Git (State Backup)
C4 Level 4: Code (Implementation Classes)
C4 Level 3: Component Diagram (CODITECT-CORE Internals)
C4 Level 2: Container Diagram (System Architecture)
C4 Level 1: System Context Diagram
Data Flow Diagrams
Flow 1: Multi-Tenant Session Initialization
Flow 2: Multi-LLM Routing with Fallback
Flow 3: Git State Backup & Recovery
Flow 4: Multi-Team Resource Isolation
Multi-Tenancy Data Model
Key Architectural Decisions
| Decision | Rationale |
|---|---|
| CODITECT-CORE as Router | Single control plane for multi-LLM orchestration with fallback chains |
| Per-tenant GCS/R2 prefix | /{org}/{team}/{user}/{project}/ - physical isolation, easy backup |
| Durable Objects for Coordination | Strong consistency for session locks, git operations, quota tracking |
| Git as State Backup | Versioned, portable, audit-friendly; every session checkpoint = git commit |
| Circuit Breaker per Provider | Automatic failover: Claude → Gemini → Kimi → Codex |
| MCP for Tool Integration | Standard protocol for agent tools (file, shell, web, db) |
Deployment Topology
┌─────────────────────────────────────────────────────────────────┐
│ Cloudflare Edge │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
│ │ Workers │ │ WebSocket │ │ Durable Objects │ │
│ │ (API) │ │ (Streams) │ │ (Sessions/Locks/State) │ │
│ └──────┬──────┘ └──────┬──────┘ └─────────────────────────┘ │
│ │ │ │
│ ┌──────▼────────────────▼──────┐ ┌─────────────────────────┐ │
│ │ CODITECT-CORE │ │ R2 / GCS │ │
│ │ (Orchestrator Logic) │ │ (Project Storage) │ │
│ └──────┬────────────────┬──────┘ └─────────────────────────┘ │
└─────────┼────────────────┼──────────────────────────────────────┘
│ │
▼ ▼
┌─────────────────────────────────────────────────────────────────┐
│ Ephemeral Compute │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Sandbox 1 │ │ Sandbox 2 │ │ Sandbox N │ (Per-user) │
│ │ (Claude) │ │ (Gemini) │ │ (Kimi) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ External Providers │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Anthropic│ │ Google │ │ OpenAI │ │ Moonshot │ │
│ │ Claude │ │ Gemini │ │ Codex │ │ Kimi │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ State Backup (Git) │
│ GitHub / GitLab / Bitbucket (per-tenant repos) │
└─────────────────────────────────────────────────────────────────┘