Skip to main content

Architecture

LARouter is a monorepo with three main components: a Hono-based API server, a React WebUI dashboard, and an MCP tool server.

System Diagram

Request Flow

When a request arrives at /v1/chat/completions:

  1. Auth Middleware — Validates bearer token, resolves project context
  2. Classifier — Heuristic analysis → confidence check → optional AI fallback
  3. Tier Router — Maps the classified tier to a specific model from the project's routing policy
  4. Executor — Sends the request to the selected provider (local or cloud)
  5. Streaming — If SSE, streams chunks back to the client in real-time
  6. Token Tracker — Records usage (input/output tokens, cost, project, model)

Directory Structure

LARouter/
├── backend/ ← Hono API server (Bun runtime)
│ ├── src/
│ │ ├── index.ts ← Entry point + graceful shutdown
│ │ ├── server.ts ← Hono routes + proxy handler
│ │ ├── classifier.ts ← Heuristic request classifier
│ │ ├── ai-classifier.ts← AI fallback classifier
│ │ ├── router.ts ← Tier → model mapping
│ │ ├── executor.ts ← Provider execution + escalation
│ │ ├── token-tracker.ts← Per-project billing
│ │ ├── projects.ts ← Multi-tenant project manager
│ │ ├── model-manager.ts← Download + llama-server lifecycle
│ │ ├── mcp-server.ts ← MCP tool server
│ │ ├── cli.ts ← Admin CLI
│ │ ├── auth.ts ← Bearer token middleware
│ │ ├── config.ts ← Configuration loader
│ │ ├── models.ts ← Provider registry
│ │ ├── logger.ts ← SQLite logging
│ │ └── streaming.ts ← SSE passthrough
│ └── config/
│ └── default.json ← Default tier mappings

├── frontend/ ← React WebUI dashboard
│ ├── src/
│ │ ├── main.tsx ← App entry + router + sidebar
│ │ ├── pages/ ← Overview, Models, Projects, Usage, Settings
│ │ ├── lib/ ← API client
│ │ └── styles.css ← Design tokens + components
│ └── vite.config.ts

├── documents/ ← This documentation site
│ ├── docs/ ← Markdown source files
│ └── website/ ← Docusaurus 3.10 config

└── models/ ← Downloaded model files (gitignored)

Ports

ServicePortDescription
Backend API18790Hono server — proxy + admin API
Frontend WebUI5174Vite dev server — React dashboard
MCP SSE18791MCP tool server (SSE transport)
llama-server8001+Local model inference (auto-assigned)
Docs3002Docusaurus documentation site