Architecture
Igris is a monorepo with two primary services (an API server and a web dashboard), a PostgreSQL database, and a Redis layer.Monorepo layout
System Overview
Components
API Server (Hono)
The backend runs on Hono and listens on port 3100. It handles:- MCP Gateway (
/v1/mcp/:slug) — intercept MCP tool calls, evaluate policies, forward to upstream. Authenticates with a Bearer API key only (see Proxy Flow) - LLM Gateway (
/llm/:slug/*) — OpenAI-compatible API proxy for 60 LLM providers (see LLM Gateway below) - REST API (
/api/v1/*) — policies, connections, sessions, audit events, incidents, webhooks, API keys, members, billing, and the dashboard data endpoints. Authenticates with a session cookie or a Bearer API key - Auth (
/api/auth/*) — Better Auth endpoints for session management - SSE (
/api/v1/events) — org-scoped event stream (see Real-time events)
Web Frontend (Next.js)
The dashboard runs on Next.js on port 3200 and provides:- Dashboards: Overview, Observe (risk heat map), and LLM Cost
- Monitor: Incidents and the Audit Trail (which streams live updates)
- Govern: Policies and Connections
- Settings: organization, members, API keys, webhooks, and billing
Database (Neon PostgreSQL)
All persistent state lives in Neon PostgreSQL. The schema is managed by Drizzle ORM with migrations applied on startup.Per-organization schemas
Igris isolates tenants by schema. Each organization gets its own Postgres schema namedorg_<slug>, created when the organization is provisioned. Every request runs against its organization’s schema, so one organization’s rows are never in the same table as another’s.
Tables in each organization schema:
Public-schema migrations run with Drizzle’s migrator at API startup. Per-organization migrations run against every organization schema. The API refuses to start if either fails.
Cache (Upstash Redis)
Upstash Redis handles:- Policy cache — policies cached for 30 seconds to avoid DB lookups on every call
- Rate limiting — fixed-window counters for the rate limits on LLM policy rules. MCP rules have no rate limits
- SSE pub/sub — fan-out of events across API instances, so each client sees events emitted on any instance
- Kill-switch cache — a 3-second shared cache of session suspension status, so the gateway does not read the database on every call (the database is the source of truth)
Authentication (Better Auth)
Better Auth provides:- Email/password login, plus GitHub and Google OAuth when configured
- Organization-scoped sessions with role-based access control and per-member permission overrides (see Roles and permissions)
- API keys for programmatic access. A key acts with its creator’s current role
- Session tokens stored as
igris.session_tokencookies (or__Secure-igris.session_tokenin production)
LLM Gateway
The LLM Gateway is an OpenAI-compatible API proxy mounted at/llm/:slug/*. It routes requests through Igris connections so every LLM call is governed, audited, and cost-tracked alongside your MCP traffic.
Route shape
{connection-slug} identifies the Igris connection that holds the upstream provider credential. No model-prefix routing is used in the URL — the provider is determined by the provider field on the connection record.
Authentication
Bearer API key only (Authorization: Bearer ig_...). Wildcard CORS (*) is applied so browser-based clients can call the gateway directly. Session cookies are not accepted on gateway routes. The same applies to the MCP gateway at /v1/mcp/:slug.
What the gateway does on each request
- Authenticates the API key and resolves the connection (slug → provider + encrypted credential)
- Checks the connection’s model allowlist, if it has one
- Evaluates policies (allow / deny / alert / redact) against the model and endpoint, including content guards and token limits
- Checks rate limits (requests / tokens / dollars, Redis counters)
- Forwards the request to the upstream provider with credential injection
- Streams the response to the client via a single-pass tee (client stream + accumulator)
- Writes an audit event with token counts, cost, and model after the response completes
- Updates the LLM anomaly detector asynchronously (cost spike, token burn, error rate, model shift, response length)
Provider support
60 providers are registered, including OpenAI, Anthropic, Google Gemini, Groq, Mistral, DeepSeek, Cohere, and self-hosted models via theopenai-compatible provider (requires customBaseUrl).
Enablement
The LLM Gateway is feature-flagged. SetLLM_GATEWAY_ENABLED=false to disable it; requests to /llm/* will return 404.
S3 Audit Archive
Audit events are retained in Postgres up to the plan’s retention limit, then archived to S3 Standard-IA and deleted from Postgres.Archive job
A daily cron runs at UTCARCHIVE_CRON_HOUR_UTC (default 03:00). For each organization it:
- Finds days in
audit_eventsolder than the plan’s retention days plus a 1-day buffer - Serializes each day’s events as gzip NDJSON
- Writes the file to S3 with a deterministic key (
{orgId}/{YYYY-MM}/{YYYY-MM-DD}.ndjson.gz) — idempotent overwrite - In a single Postgres transaction: inserts a manifest row into
audit_archives, then deletes the archived rows fromaudit_events
restored_from_archive_id IS NOT NULL) are excluded from future archiving.
Key implications
audit_eventsdoes not grow unboundedly in Postgres- Restored rows are marked with
restored_from_archive_idso they are not re-archived - The audit trail stays complete: archived events can be restored on plans that include restore (see Audit Trail)
Proxy Flow
When an MCP client calls a tool through the Igris proxy:- Request arrives at
/v1/mcp/:slugas a JSON-RPC request - Auth check — validate the Bearer API key. Session cookies are not accepted here
- Connection resolution — the key identifies the organization, and the slug identifies the connection and its upstream URL
- Kill-switch check — if the connection’s session is suspended, the call is rejected
- Session tracking — the call is attached to a session, which is recorded in
proxy_sessions - Policy evaluation — load rules from cache (or the database on a miss) and evaluate them in order against the tool name and conditions. Policies apply to
tools/call,resources/read, andsampling/createMessage - Action execution:
- allow — forward to upstream and log the event
- deny — return an error to the client and log the denial
- alert — forward to upstream, log the event, and dispatch the
policy_denywebhook - redact — mask matches in the arguments, then forward
- Anomaly check — the anomaly detector looks for rate spikes and destructive patterns. A hit is stored as an
anomalyevent and streamed as an SSEanomalyevent - Audit write and SSE — the event is written to
audit_eventsand atool_callevent is pushed to connected clients
Deployment
The API deploys to EC2 via GitHub Actions:- API server runs as a systemd unit on EC2 (Ubuntu)
- Neon for managed PostgreSQL (serverless, auto-scaling)
- Upstash for managed Redis (serverless, per-request pricing)
- Migrations applied automatically at API startup via
drizzle-orm/postgres-js/migrator(programmatic — notdrizzle-kit). The API refuses to start if any migration fails.