How thinkwatchproject/thinkwatch works
ThinkWatch is a self-hosted organizational gateway for AI model APIs and MCP tools, with an admin API and web console. The main request path authenticates callers, applies access, budget and rate-limit checks, inspects and transforms traffic, selects an upstream, then records usage and audit events. The README documents major capabilities such as identity, guards, routing, cost reporting and MCP; source excerpts show parts of the AI gateway wiring. Unsampled subsystems and integrations are represented only where the README supports their role.
Main entry points: generate.rs AI request pipeline · app.rs HTTP application · proxy.rs MCP request proxy · logger.rs Audit logging
Components 28
Entry and identity
- HTTP application
crates/server/src/app.rs - Request authentication
crates/server/src/middleware/auth_guard.rs - Identity and tokens
crates/auth/src/oidc.rs - Session issuance
crates/server/src/services/session_service.rs
AI gateway
- AI request pipeline
crates/gateway/src/proxy/generate.rs - Budget and limits
crates/gateway/src/proxy/pipeline.rs - Security guards
crates/gateway/src/content_filter.rs - Secrets and privacy
crates/gateway/src/redaction.rs - Model routing
crates/gateway/src/proxy/routing.rs - Route registry
crates/gateway/src/router.rs - Provider transport
crates/gateway/src/proxy/transport.rs
MCP gateway
- MCP request proxy
crates/mcp-gateway/src/proxy.rs - MCP server registry
crates/mcp-gateway/src/registry.rs - MCP transport
crates/mcp-gateway/src/transport/streamable_http.rs
Administration and reporting
- Management console
web/src/App.tsx - Admin API
crates/server/src/handlers/mod.rs - Usage and cost accounting
crates/gateway/src/usage_estimate.rs - Analytics and chargeback
crates/server/src/handlers/analytics.rs
State and audit
- Application repositories
crates/server/src/services/model_repository.rs - PostgreSQL
- Redis
- Audit logging
crates/common/src/audit/logger.rs - ClickHouse audit store
crates/common/src/audit/clickhouse.rs - Audit forwarders
crates/common/src/audit/forwarders.rs
Other components
- AI clients
- Admin browser
- AI providers
- MCP servers
Connections 30
- AI clients → HTTP application: send requests
README.md - Admin browser → Management console: manage gateway
README.md - Management console → HTTP application: call admin API
README.md - HTTP application → Request authentication: authenticates routes
crates/server/src/app.rs - Request authentication → Identity and tokens: validates identity
crates/server/src/middleware/auth_guard.rs - HTTP application → Session issuance: issues sessions
crates/server/src/services/session_service.rs - HTTP application → AI request pipeline: routes AI surfaces
crates/server/src/app.rs - AI request pipeline → Budget and limits: checks access and limits
crates/gateway/src/proxy/pipeline.rs - AI request pipeline → Security guards: filters content
crates/gateway/src/proxy/generate.rs - AI request pipeline → Secrets and privacy: redacts payloads
crates/gateway/src/proxy/generate.rs - AI request pipeline → Model routing: selects route
crates/gateway/src/proxy/generate.rs - Model routing → Route registry: chooses candidates
crates/gateway/src/proxy/routing.rs - Model routing → Redis: reads affinity
crates/gateway/src/proxy/routing.rs - AI request pipeline → Provider transport: sends request
crates/gateway/src/proxy/generate.rs - Provider transport → AI providers: forwards request
README.md - AI request pipeline → Usage and cost accounting: estimates usage
crates/gateway/src/proxy/generate.rs - HTTP application → MCP request proxy: routes MCP calls
- MCP request proxy → MCP server registry: resolves servers
- MCP request proxy → MCP transport: dispatches calls
- MCP transport → MCP servers: forwards tool calls
README.md - Management console → Admin API: manages configuration
README.md - Admin API → Application repositories: reads and writes
- Application repositories → PostgreSQL: persists records
README.md - Budget and limits → Redis: checks counters
crates/gateway/src/proxy/pipeline.rs - Usage and cost accounting → Audit logging: records usage
README.md - MCP request proxy → Audit logging: records tool calls
README.md - Audit logging → ClickHouse audit store: writes events
README.md - Audit logging → Audit forwarders: forwards events
README.md - Admin API → Analytics and chargeback: serves reports
- Analytics and chargeback → ClickHouse audit store: queries audit data
README.md