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:
- Auth Middleware — Validates bearer token, resolves project context
- Classifier — Heuristic analysis → confidence check → optional AI fallback
- Tier Router — Maps the classified tier to a specific model from the project's routing policy
- Executor — Sends the request to the selected provider (local or cloud)
- Streaming — If SSE, streams chunks back to the client in real-time
- 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