ποΈ Architecture
IntentScope is composed of four services that work together to provide intelligent, observable LLM routing.
System Diagram
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Next.js Frontend (port 3000) β
β Dashboard β API Keys β Playground β Analytics β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β Clerk JWT
ββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ
β FastAPI Gateway (port 8000) β
β Auth β Intent Analysis β Budget β Model Router β
ββββββββββ¬ββββββββββββββββββββββββββ¬βββββββββββββββββββ
β β
ββββββΌβββββ ββββββββββΌβββββββββββββββ
β Postgres β β Groq / Mistral / Ollamaβ
β (5434) β β LLM Providers β
ββββββ²βββββ βββββββββββββββββββββββββ
β
ββββββ΄ββββββββββ
β Go Validator β
β (port 8081) β
ββββββββββββββββServices
| Service | Stack | Port | Role |
|---|---|---|---|
| Frontend | Next.js 15, React 19, Tailwind CSS 4, Clerk | 3000 | Dashboard UI |
| API Gateway | FastAPI, LiteLLM, SQLAlchemy (async), Alembic | 8000 | Core gateway |
| Token Validator | Go, pgx | 8081 | Fast-path key validation |
| Database | PostgreSQL 15 | 5434 | Persistent storage |
Request Lifecycle
Every request through IntentScope follows this pipeline:
1. Client sends POST /v1/chat/completions
β
2. verify_virtual_key βββ checks DB / Go validator
β
3. analyze_intent βββ Mistral classifies the prompt
β category + risk_level + estimated_tokens
4. check_budget βββ enforces token limits per key
β
5. determine_target_model βββ Groq / Mistral / Ollama
β light or heavy tier based on intent
6. acompletion (LiteLLM) βββ actual LLM call
β
7. record_usage + log βββ writes to Postgres
β
8. Return response to clientData Models
User
idβ Clerk user IDdefault_modelβ saved LLM preferencestrict_budgetβ enforce hard token limitsauto_purge_sensitiveβ delete sensitive logs after 24h
VirtualKey
keyβ hashed API key stringuser_idβ ownertoken_limitβ max tokenstokens_usedβ running totalexpires_atβ optional expiryis_activeβ revocation flag
RequestLog
modelβ which model handled the requestintent_categoryβ classified intentrisk_levelβ low / medium / highprompt_tokens,completion_tokens,total_tokenslatency_msβ end-to-end latencystatus_code
Directory Structure
intent-scope/
βββ frontend/ # Next.js 15 dashboard
β βββ src/app/dashboard/ # Overview, Keys, Playground, Usage, Settings
β
βββ backend-python/ # FastAPI gateway
β βββ app/
β βββ core/ # Auth, database, security
β βββ models/ # ORM models
β βββ routers/ # REST endpoints
β βββ schemas/ # Pydantic schemas
β βββ services/ # intent_analyzer, budget, model_router
β
βββ backend-go/ # Token validator
β βββ main.go # /validate endpoint
β
βββ docs/ # This documentation site
βββ docker-compose.yml # Dev infra
βββ docker-compose.prod.yml # Production stack