Skip to content

Architecture Overview

Layerr is not a router. It is an orchestration runtime, a self-hosted brain between your coding agents and every LLM provider. The system is built from 1,090 source files organized into 715 functional communities (auto-detected clusters of tightly coupled code).

Architecture Overview

#LayerWhat it doesKey files / Communities
1Intent ClassificationDetermines what the incoming request is asking fororchestration/orchestrator.ts
2Workload AnalysisScans the codebase to infer language, stack, complexityrepo/intelligence/scanner.ts, repo/intelligence/profiler.ts
3Workspace ProfilesHolds per-workspace preferences, provider configs, budgetssrc/features/workspaces/health/WorkspaceHealthView.tsx
4Strategy EngineChooses the orchestration strategy (cost, speed, quality, balanced)routing/enrichment.ts
5ScoringScores candidate providers and models against the workloadevaluation/quality/engine.ts
6ExecutionSends the request and handles streaming responsesserver.ts (all routes flow through here)
7ExplainabilityExplains why a model was chosen, with structured rationalesexplainability/explainer.ts
8ReplayRecords every decision, allows trace comparison and replayreplay/comparator.ts, storage/replay.ts
9Adaptive LearningLearns from outcomes and adapts future routing decisionssrc/features/intelligence/hooks.ts
10Quality EvaluationBenchmarks, calibrations, coding validatorsevaluation/calibration/engine.ts, evaluation/coding/validators.ts
11EconomicsCost dashboards, savings computation, budget protectionsrc/features/providers/economics/ProviderEconomicsOverlay.tsx
12Entitlements & GovernanceAccess control, license management, guardrails, rate limitssecurity/rotation/engine.ts

These are the largest auto-detected clusters in the codebase:

CommunitySymbolsCohesionDescription
Secrets960.87Credential management, key rotation, provider auth
Hooks780.98React hooks for data fetching and UI state
Intelligence700.71Adaptive learning, calibration, workspace health
Economics350.83Cost tracking, savings, budget pressure
Motion320.90Animation and UI motion preferences
Licensing290.80License activation, validation, snapshots
RateLimit290.84Per-provider rate limiting
Providers240.81Provider registration, resolution, health
Insights210.94Analytics and intelligence dashboards
Reliability210.91Fallback chains, retry logic, circuit breakers
Telemetry210.91Metrics, traces, observability
Scoring190.77Quality scoring, grading, confidence
Coding190.98Coding-specific evaluation and validators
Sessions180.87Session management and state
Explainability170.90Decision explanations and rationale building
Rotation170.81Secret rotation scheduling
Storage170.98Persistence layer for traces and replay
Workload170.89Workload analysis and classification

When a request hits /v1/chat/completions:

  1. Gateway (server.ts) receives the request, validates auth
  2. Intent Classification determines language, stack, security scope
  3. Workload Analysis scans the project context via repo/intelligence/scanner.ts
  4. Strategy Engine picks a strategy (cost-optimized, quality-first, etc.)
  5. Scoring runs evaluation/quality/engine.ts to score candidates
  6. Provider Resolution resolves the best provider chain (orchestration/fallback.ts)
  7. Execution proxies to the chosen model
  8. Explainability builds a structured rationale (explainability/explainer.ts)
  9. Replay stores the trace (storage/replay.ts)
  10. Adaptive Learning feeds the outcome back into future scoring (src/features/intelligence/hooks.ts)

All of this happens in a single request cycle, with full observability at every step.