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).
Layerr Architecture
Section titled “Layerr Architecture”| # | Layer | What it does | Key files / Communities |
|---|---|---|---|
| 1 | Intent Classification | Determines what the incoming request is asking for | orchestration/orchestrator.ts |
| 2 | Workload Analysis | Scans the codebase to infer language, stack, complexity | repo/intelligence/scanner.ts, repo/intelligence/profiler.ts |
| 3 | Workspace Profiles | Holds per-workspace preferences, provider configs, budgets | src/features/workspaces/health/WorkspaceHealthView.tsx |
| 4 | Strategy Engine | Chooses the orchestration strategy (cost, speed, quality, balanced) | routing/enrichment.ts |
| 5 | Scoring | Scores candidate providers and models against the workload | evaluation/quality/engine.ts |
| 6 | Execution | Sends the request and handles streaming responses | server.ts (all routes flow through here) |
| 7 | Explainability | Explains why a model was chosen, with structured rationales | explainability/explainer.ts |
| 8 | Replay | Records every decision, allows trace comparison and replay | replay/comparator.ts, storage/replay.ts |
| 9 | Adaptive Learning | Learns from outcomes and adapts future routing decisions | src/features/intelligence/hooks.ts |
| 10 | Quality Evaluation | Benchmarks, calibrations, coding validators | evaluation/calibration/engine.ts, evaluation/coding/validators.ts |
| 11 | Economics | Cost dashboards, savings computation, budget protection | src/features/providers/economics/ProviderEconomicsOverlay.tsx |
| 12 | Entitlements & Governance | Access control, license management, guardrails, rate limits | security/rotation/engine.ts |
Top Functional Communities
Section titled “Top Functional Communities”These are the largest auto-detected clusters in the codebase:
| Community | Symbols | Cohesion | Description |
|---|---|---|---|
| Secrets | 96 | 0.87 | Credential management, key rotation, provider auth |
| Hooks | 78 | 0.98 | React hooks for data fetching and UI state |
| Intelligence | 70 | 0.71 | Adaptive learning, calibration, workspace health |
| Economics | 35 | 0.83 | Cost tracking, savings, budget pressure |
| Motion | 32 | 0.90 | Animation and UI motion preferences |
| Licensing | 29 | 0.80 | License activation, validation, snapshots |
| RateLimit | 29 | 0.84 | Per-provider rate limiting |
| Providers | 24 | 0.81 | Provider registration, resolution, health |
| Insights | 21 | 0.94 | Analytics and intelligence dashboards |
| Reliability | 21 | 0.91 | Fallback chains, retry logic, circuit breakers |
| Telemetry | 21 | 0.91 | Metrics, traces, observability |
| Scoring | 19 | 0.77 | Quality scoring, grading, confidence |
| Coding | 19 | 0.98 | Coding-specific evaluation and validators |
| Sessions | 18 | 0.87 | Session management and state |
| Explainability | 17 | 0.90 | Decision explanations and rationale building |
| Rotation | 17 | 0.81 | Secret rotation scheduling |
| Storage | 17 | 0.98 | Persistence layer for traces and replay |
| Workload | 17 | 0.89 | Workload analysis and classification |
Request Flow
Section titled “Request Flow”When a request hits /v1/chat/completions:
- Gateway (
server.ts) receives the request, validates auth - Intent Classification determines language, stack, security scope
- Workload Analysis scans the project context via
repo/intelligence/scanner.ts - Strategy Engine picks a strategy (cost-optimized, quality-first, etc.)
- Scoring runs
evaluation/quality/engine.tsto score candidates - Provider Resolution resolves the best provider chain (
orchestration/fallback.ts) - Execution proxies to the chosen model
- Explainability builds a structured rationale (
explainability/explainer.ts) - Replay stores the trace (
storage/replay.ts) - 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.