How hylmithecoder/router-ai works
AI Router exposes OpenAI-compatible and unified chat APIs, authenticates and enforces per-key quotas, selects upstream providers with failover, and records usage for administration. The dashboard manages keys, providers, and usage. The tree also contains a separate local ALPR inference service; its documented detection, OCR, and plate-format stages are shown independently because the sampled code does not establish a connection to the Rust gateway. The route and UI links reflect README capabilities; unsampled handler and frontend wiring is not expanded.
Main entry points: mod.rs HTTP Routes · router.rs Provider Router · chat.rs Chat Handlers · admin.rs Admin Handlers
Components 18
Gateway API
- Rust Server
src/server.rs - HTTP Routes
src/routes/mod.rs - Auth and Quota
src/middleware.rs - Chat Handlers
src/handlers/chat.rs - Vision Handler
src/handlers/vision.rs
AI Routing
- Provider Router
src/ai/router.rs - Provider Calls
src/ai/provider.rs - Usage Streaming
src/ai/usage_stream.rs - AI Providers
Admin and Storage
- Admin Handlers
src/handlers/admin.rs - SQLite Store
src/database/sqlite.rs
Dashboard
- Admin Dashboard
webui/app/pages/Dashboard.tsx - Dashboard API Client
webui/lib/api.ts
Local ALPR
- ALPR Service
python-alpr-local/server.py - Plate Detection OCR
python-alpr-local/engine.py - Plate Formatting
python-alpr-local/plate_format.py
Other components
- API Client
- Image Client
Connections 19
- API Client → HTTP Routes: sends requests
- Rust Server → HTTP Routes: serves
- HTTP Routes → Auth and Quota: applies auth
- HTTP Routes → Chat Handlers: dispatches chat
- HTTP Routes → Vision Handler: dispatches vision
- Chat Handlers → Provider Router: routes completion
- Vision Handler → Provider Router: routes vision
- Provider Router → Provider Calls: invokes
- Provider Calls → AI Providers: sends requests
- Provider Router → SQLite Store: records provider status
- HTTP Routes → Admin Handlers: dispatches admin
- Admin Handlers → SQLite Store: reads and writes
- Admin Handlers → Provider Router: manages providers
- Chat Handlers → SQLite Store: records usage
- Admin Dashboard → Dashboard API Client: requests admin data
- Dashboard API Client → HTTP Routes: calls admin API
- Image Client → ALPR Service: posts image
- ALPR Service → Plate Detection OCR: invokes inference
- Plate Detection OCR → Plate Formatting: parses candidates