Technical Deep Dive
System Architecture
A three-component Node.js monorepo designed for enterprise scale โ with Express API,
React UI, and MCP knowledge server working together as a unified platform.
System Design
Three-Component Platform
AgentWatch is a monorepo containing three independent Node.js applications that work together as a complete LLM management platform.
๐
Web Browser
Dashboard UI
๐ป
API Clients
SDKs / HTTP
๐ง
IDE Extensions
VS Code / JetBrains
All traffic flows through AgentWatch
AgentWatch Platform (Port 8787)
โก
Express API Server
REST + Proxy
๐
Auth & RBAC
JWT + Roles
๐ก๏ธ
DLP Engine
30+ patterns
๐
Metrics Collector
Prometheus
Routes to best available provider
๐ฃOpenRouter
100+ models
โ๏ธCustom
Any OpenAI endpoint
Main Server ยท Port 8787
Express API Server
- LLM proxy handler with provider routing
- JWT auth & RBAC middleware
- DLP scanning engine
- Response caching
- Prometheus metrics collection
- Multi-tenant billing via Stripe
Web UI ยท Vite / Static
React Admin Dashboard
- React 18.3 + TypeScript SPA
- Real-time observability dashboards
- Provider management UI
- Budget & team management
- Compliance configuration
- Knowledge graph visualization
MCP Server ยท Port 4000
Knowledge Extractor
- Repository ingestion pipeline
- Tree-sitter AST parsing
- Semgrep security scanning
- Trivy infrastructure scanning
- LanceDB vector store
- Semantic code search API
Technology
Technology Stack
Built on proven, production-ready technologies with a TypeScript-first codebase.
Main Server
| Runtime | Node.js 24+ |
| Language | TypeScript |
| Framework | Express.js |
| Database | SQLite 3 / PostgreSQL |
| ORM | Prisma |
| Auth | JWT + bcrypt |
| HTTP Client | Axios |
| Queue | PQueue |
| Tokens | js-tiktoken |
| Billing | Stripe SDK |
Web UI
| Framework | React 18.3 |
| Language | TypeScript |
| Build Tool | Vite |
| Styling | TailwindCSS |
| State | TanStack Query |
| Routing | React Router |
| Charts | Recharts |
| Graphs | Cytoscape, vis-network |
| Icons | Lucide React |
| Forms | React Hook Form |
MCP Server
| Runtime | Node.js |
| Protocol | MCP SDK |
| Vector DB | LanceDB |
| Key-Value | LevelDB |
| Parser | Tree-sitter |
| SAST | Semgrep |
| Infra Scan | Trivy |
| CLI | Commander.js |
| Embeddings | OpenAI text-embedding |
| Graph | Custom symbol graph |
Request Lifecycle
How a Request is Processed
Every LLM request goes through a multi-stage processing pipeline with auth, DLP, routing, and usage recording.
๐จ
1. Request In
POST /v1/chat
๐
2. Auth Check
Validate API key
๐
3. Quota Check
Budget & rate limits
๐ก๏ธ
4. DLP Scan
30+ data patterns
๐พ
5. Cache Check
Identical requests
๐
6. Route
Provider selection
โ๏ธ
7. LLM Call
With retry logic
๐
8. Log & Meter
Async recording
Application Services
What Runs at Runtime
- Authentication Service: JWT tokens, RBAC, password policies
- LLM Proxy Service: Request routing, provider selection, failover
- Compliance Service: DLP scanning, guardrails, audit logging
- Billing Service: Token counting, budget enforcement, Stripe sync
- Knowledge Service: MCP proxy, repository indexing
Design Patterns
Key Architectural Decisions
- Circuit Breaker: Prevent cascading failures across providers
- Retry with Backoff: Handle transient network errors gracefully
- Request Queue: Backpressure management under load
- Connection Pool: Efficient HTTP keep-alive connections
- Async Recording: Non-blocking usage tracking doesn't add latency
Data Model
Database Schema
SQLite for development, PostgreSQL for production. Full Prisma ORM with migrations.
Core Entities
| Table | Purpose | Key Fields |
| organizations | SaaS billing tenant | name, slug, stripe_customer_id |
| teams | Org sub-groups | name, org_id, budget |
| users | Authentication | email, password_hash, role, org_id |
| tenants | API consumer | api_key, rate_limit, budgets |
| providers | LLM providers | name, base_url, status |
| api_keys | Provider keys | encrypted_key, concurrency_limit |
Usage & Compliance
| Table | Purpose | Key Fields |
| usage_records | Request log | tokens, cost, model, latency |
| audit_logs | Compliance trail | action, user_id, ip_address |
| conversations | Chat history | messages, dlp_events, risk_score |
| subscription_plans | SaaS tiers | features, limits, stripe_price_id |
| org_roles | RBAC roles | name, permissions |
| models | Model catalog | model_id, pricing, context_window |
๐๏ธ
Dual-database support: SQLite (via @internal/prisma-sqlite) for development
and PostgreSQL (via @prisma/client) for production.
Two separate Prisma schemas with the same model structure ensure smooth migration.
Security Architecture
Security by Design
Security isn't a feature โ it's the foundation. Every layer of the stack is designed with security in mind.
๐
Key Encryption
AES-256-GCM encryption for all provider API keys at rest. Random IVs and HMAC authentication tags.
๐ซ
JWT Sessions
24-hour JWT tokens with organization context, role claims, and super-admin flag embedded.
๐
IDOR Prevention
Organization ID always sourced from JWT, never from request body or params. Super admin override via header only.
๐
Security Headers
Full CSP, HSTS, X-Frame-Options, and other security headers set on every response.
Operations
Deployment & Scaling
From a single Docker Compose command to full Kubernetes at scale โ AgentWatch fits your operational model.
Quick Start
Docker Compose
docker-compose up -d
โ agentwatch:8787
โ mcp-server:4000
โ PostgreSQL database
Production
Kubernetes
- Helm chart for K8s deployment
- Horizontal Pod Autoscaling (HPA)
- Liveness & readiness probes
- ConfigMap + Secrets management
- PersistentVolume for SQLite
- Service mesh compatible (Istio)
Configuration
Environment Variables
DATABASE_URL โ DB connection string
JWT_SECRET โ Token signing key
ENCRYPTION_KEY โ Key encryption
STRIPE_SECRET_KEY โ Billing
HTTPS_PROXY โ Enterprise proxy
PORT โ Default 8787
See How It Compares
Compare AgentWatch against LiteLLM, Helicone, Portkey, and Kong.