Capstone — Architecture (Component 15)

The architecture document for the Startup-Grade LLM Platform. Reuse the diagrams/ and the system-design template.

System overview

                         users (web / IDE / API)
                                  │
                    ┌─────────────▼──────────────┐
                    │  PRODUCT APP (owns workflow │   ← not a wrapper [15.03]
                    │  + system of record)        │
                    └─────────────┬──────────────┘
                                  │ OpenAI-compatible
                    ┌─────────────▼──────────────────────────────┐
                    │             GATEWAY                          │
                    │ auth · rate limit · ROUTER · FALLBACK        │
                    │ provider adapters · model registry           │
                    │ metering · cache · guardrails · audit        │
                    └───┬──────────────┬───────────────┬──────────┘
                        ▼              ▼               ▼
                   OpenAI/Anthropic  vLLM (GPU)   local (Ollama)
            features that call the gateway:
            ┌─────────┐  ┌─────────┐  ┌──────────┐  ┌──────────┐
            │  RAG    │  │  AGENT  │  │  CODING  │  │  EVAL    │
            └─────────┘  └─────────┘  └──────────┘  └──────────┘
            cross-cutting: observability · cost · security/isolation

(See diagrams/18 for the Mermaid version; diagrams/17 for the K8s deployment.)

Components & responsibilities

ComponentResponsibilityKey files
GatewayOne OpenAI-compatible entry; route/fallback/meter/guardgateway/server.py, router.py
Provider adaptersNormalize OpenAI/Anthropic/vLLM/local to one shapegateway/adapters/
Model registrymodel × provider × price × limits × capabilitiesgateway/registry.py
RAGingest → hybrid retrieve → rerank → grounded cite; per-tenant filterrag/
Agenttool-calling loop; trust boundary; approval; tracingagent/
Codingindex + symbol search + apply-patch + latency tierscoding/
Evalgolden set + scorers + judge + CI gateeval/
Productthe MVP workflow owning a system of recordproduct/
Observability/costtraces (correlation IDs), p95/p99, cost dashboardsgateway/metering.py, ui/

Key design decisions (record as ADRs)

DecisionChoiceWhy
InterfaceOpenAI-compatibleclients/tools interoperate; easy provider swap
Routingdifficulty/cost-based + fallbackmargin + resilience 8.05
KnowledgeRAG (not fine-tune)facts change; behavior via prompt 13.00
Servinghybrid API + self-hostcost/residency cheatsheet 05
StatePostgres + RLS, per-tenant vector namespacesisolation 14.04
Trust boundarymodel proposes, app executessafety 14.01

Data flow (one request, with correlation ID)

request (cid) → gateway auth/route → [RAG retrieve (tenant filter) | agent tool loop]
              → model call (provider/local) → guardrails (out) → response (streamed)
              → metering + audit log (cid)   [reconstructable end-to-end]

Cross-cutting concerns (always addressed)

  • Cost: per request/resolved-task/tenant; routing + caching (15.05).
  • Latency: TTFT/TPOT, p95 under load, streaming (12.06).
  • Reliability: fallback, retries, circuit breakers, timeouts (7.07).
  • Security: trust boundary, isolation, secrets, fail-closed guardrails, audit (SECURITY.md).

Scaling & failure modes

  • Bottlenecks: KV-cache/GPU (serving), vector DB (RAG), provider limits → mitigations in the runbook.
  • Failure modes: provider outage (fallback), injection (trust boundary), leak (isolation), cost spike (caps).