Skip to main content

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 named org_<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)
Redis is optional. When it is not configured, caching and event delivery stay inside one API process, which is only correct for a single instance.

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_token cookies (or __Secure-igris.session_token in 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

The {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

  1. Authenticates the API key and resolves the connection (slug → provider + encrypted credential)
  2. Checks the connection’s model allowlist, if it has one
  3. Evaluates policies (allow / deny / alert / redact) against the model and endpoint, including content guards and token limits
  4. Checks rate limits (requests / tokens / dollars, Redis counters)
  5. Forwards the request to the upstream provider with credential injection
  6. Streams the response to the client via a single-pass tee (client stream + accumulator)
  7. Writes an audit event with token counts, cost, and model after the response completes
  8. 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 the openai-compatible provider (requires customBaseUrl).

Enablement

The LLM Gateway is feature-flagged. Set LLM_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 UTC ARCHIVE_CRON_HOUR_UTC (default 03:00). For each organization it:
  1. Finds days in audit_events older than the plan’s retention days plus a 1-day buffer
  2. Serializes each day’s events as gzip NDJSON
  3. Writes the file to S3 with a deterministic key ({orgId}/{YYYY-MM}/{YYYY-MM-DD}.ndjson.gz) — idempotent overwrite
  4. In a single Postgres transaction: inserts a manifest row into audit_archives, then deletes the archived rows from audit_events
Rows that were restored from an archive (restored_from_archive_id IS NOT NULL) are excluded from future archiving.

Key implications

  • audit_events does not grow unboundedly in Postgres
  • Restored rows are marked with restored_from_archive_id so 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:
  1. Request arrives at /v1/mcp/:slug as a JSON-RPC request
  2. Auth check — validate the Bearer API key. Session cookies are not accepted here
  3. Connection resolution — the key identifies the organization, and the slug identifies the connection and its upstream URL
  4. Kill-switch check — if the connection’s session is suspended, the call is rejected
  5. Session tracking — the call is attached to a session, which is recorded in proxy_sessions
  6. 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, and sampling/createMessage
  7. 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_deny webhook
    • redact — mask matches in the arguments, then forward
  8. Anomaly check — the anomaly detector looks for rate spikes and destructive patterns. A hit is stored as an anomaly event and streamed as an SSE anomaly event
  9. Audit write and SSE — the event is written to audit_events and a tool_call event 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 — not drizzle-kit). The API refuses to start if any migration fails.
Igris is a fully managed cloud service — no self-hosted deployment is required.