Architecture

πŸ—οΈ 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

ServiceStackPortRole
FrontendNext.js 15, React 19, Tailwind CSS 4, Clerk3000Dashboard UI
API GatewayFastAPI, LiteLLM, SQLAlchemy (async), Alembic8000Core gateway
Token ValidatorGo, pgx8081Fast-path key validation
DatabasePostgreSQL 155434Persistent 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 client

Data Models

User

  • id β€” Clerk user ID
  • default_model β€” saved LLM preference
  • strict_budget β€” enforce hard token limits
  • auto_purge_sensitive β€” delete sensitive logs after 24h

VirtualKey

  • key β€” hashed API key string
  • user_id β€” owner
  • token_limit β€” max tokens
  • tokens_used β€” running total
  • expires_at β€” optional expiry
  • is_active β€” revocation flag

RequestLog

  • model β€” which model handled the request
  • intent_category β€” classified intent
  • risk_level β€” low / medium / high
  • prompt_tokens, completion_tokens, total_tokens
  • latency_ms β€” end-to-end latency
  • status_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