System shape
Single binary. Three stores. Fail closed.
TokenGuard is a Go HTTP service. The entry point wires config, optional guard dependencies, and an http.ServeMux. Ops UI stays embedded at /dashboard — this page is the map.
Client app
→TokenGuard
→LLM provider
402 / 409 / 400
Turso
Redis
Guard on → budget + loop preflight → upstream or block → settle usage into Turso
Data stores
- Turso (libSQL)Billing ledgerusers, api_keys, user_budgets, usage_events, model_prices
- Upstash Redis RESTLoop stateShort-TTL counters keyed by session + payload hash
- Pricing catalogCost estimateTurso model_prices + OpenRouter sync; optional pricing.json bootstrap
Packages
cmd/tokenguard— bootstrap, routes, shutdowninternal/proxy— reverse proxy, guard, providers, mgmtinternal/billing— Turso store, budgets, keys, usageinternal/cache— Upstash + loop circuit breakerinternal/models— pricing engine + OpenRouter syncweb/— product portal, operator console, and integrator docs (Next.js)
Full write-up: docs/ARCHITECTURE.md · How it works