Resources

Architecture

How ulex is built: the request path, the Lambda and DynamoDB topology, the data model, the MCP server, the worker queues, the audit chain, and the six diagrams that explain it.

ulex is serverless, active-active multi-region (us-east-2 and us-west-2), and scales to zero. One API, 113 MCP tools, five Lambda functions, a DynamoDB Global Table, and an append-only hash-chained audit log.

#The request path

mermaid
flowchart LR
  Client["Agent / your app / a customer's IdP"]
  CF["CloudFront<br/>TLS 1.3, in-app shield"]
  APIGW["API Gateway<br/>HTTP API, JWT authorizer"]
  API["lambda:api<br/>Node 22 arm64, 1769 MB"]
  Proto["lambda:protocol<br/>OIDC · SAML · SCIM · JWT"]
  MCP["lambda:mcp<br/>Streamable HTTP + SSE"]
  Worker["lambda:worker<br/>jobs · sync · webhooks"]
  DDB[("DynamoDB<br/>ulexid, on-demand")]
  KMS["AWS KMS<br/>tenant-scoped envelope CMK"]
  SQS[["SQS<br/>jobs · webhooks · sync"]]
  Audit[("Audit chain<br/>append-only, sha256")]

  Client -->|HTTPS| CF -->|HTTPS| APIGW
  APIGW --> API
  APIGW --> Proto
  APIGW --> MCP
  API --> DDB
  Proto --> DDB
  MCP --> DDB
  API --> KMS
  Proto --> KMS
  API --> SQS
  SQS --> Worker --> DDB
  Worker --> KMS
  API --> Audit
  Proto --> Audit
  MCP --> Audit

Every mutation writes exactly one audit entry, on the request path, before the response is sent. If the audit append fails, the mutation fails.

#The Lambda fleet

mermaid
flowchart TB
  subgraph "Public"
    APIGW["API Gateway"]
  end
  subgraph "Compute"
    API["api<br/>1769 MB · 29 s · 3000 max"]
    PROTO["protocol<br/>1024 MB · 15 s · 500 max"]
    MCP["mcp<br/>1769 MB · 15 min · 200 max"]
    WORKER["worker<br/>2048 MB · 15 min · 100 max"]
    RECON["reconciler<br/>512 MB · 5 min · 5 max"]
  end
  subgraph "Data"
    DDB[("DynamoDB")]
    KMS["KMS"]
    SQS[["SQS + DLQ"]]
  end

  APIGW --> API
  APIGW --> PROTO
  APIGW --> MCP
  SQS --> WORKER
  EVENTBRIDGE["EventBridge<br/>scheduled"] --> RECON
  RECON --> DDB
  API --> DDB
  PROTO --> DDB
  MCP --> DDB
  WORKER --> DDB
  API --> KMS
  WORKER --> KMS
  API --> SQS
  MCP --> SQS

  classDef zero stroke-dasharray: 5 5
  style API stroke-dasharray: 5 5
  style MCP stroke-dasharray: 5 5

Every function has minimum: 0. There is no NAT gateway or idle cluster; compute and DynamoDB replication are metered per request and millisecond.

1,769 MB is not arbitrary: it is one byte under the 1,770 MB free-tier ceiling and the largest arm64 size that gets full CPU at that price. It is documented so nobody "fixes" it.

#Data model

One table per environment, single-table design.

mermaid
erDiagram
  TENANT ||--o{ APPLICATION : owns
  TENANT ||--o{ ORGANIZATION : owns
  TENANT ||--o{ USER : owns
  TENANT ||--o{ API_KEY : authenticates
  TENANT ||--o{ WEBHOOK : delivers
  TENANT ||--o{ AUDIT_EVENT : records
  ORGANIZATION ||--o{ DOMAIN : verifies
  ORGANIZATION ||--o{ MEMBERSHIP : has
  ORGANIZATION ||--o{ GROUP : contains
  ORGANIZATION ||--o{ CONNECTION : authenticates
  ORGANIZATION ||--o| DIRECTORY : syncs
  USER ||--o{ MEMBERSHIP : joins
  USER ||--o{ SESSION : opens
  USER ||--o{ REFRESH_TOKEN : holds
  USER ||--o{ PASSKEY : enrols
  USER ||--o{ MFA_FACTOR : enrols
  MEMBERSHIP }o--o{ GROUP : inherits
  CONNECTION ||--o{ AUTH_ATTEMPT : produces
  CONNECTION }o--|| DIRECTORY : linked
  DIRECTORY ||--o{ DIRECTORY_SYNC : runs
  APPLICATION ||--o{ SESSION : participates
  SESSION ||--o{ GRANT : issues
  APPLICATION ||--o{ DEPLOYMENT : deploys
  WEBHOOK ||--o{ WEBHOOK_DELIVERY : attempts

  TENANT { string id PK "ten_" }
  ORGANIZATION { string id PK "org_" }
  USER { string id PK "usr_" }
  MEMBERSHIP { string id PK "mem_" }
  CONNECTION { string id PK "con_" }

Three design decisions, each of which you will feel:

DecisionConsequence
users are tenant-globalone human, many customers, joined by memberships. GET /users?organization_id= narrows
sessions are per (user, tenant), not per applicationcross-app SSO is a consequence, not a feature. One cookie
the environment is derived from the credentialthere is no environment parameter anywhere. An agent cannot get it wrong

#The audit chain

mermaid
sequenceDiagram
  autonumber
  participant C as Client
  participant A as lambda:api
  participant D as DynamoDB
  participant K as KMS

  C->>A: POST /organizations
  A->>A: validate, authorize
  A->>K: GenerateDataKey()
  K-->>A: plaintext data key
  A->>D: PutItem RESOURCE (conditional: slug absent)
  D-->>A: created
  A->>D: PutItem AUDIT<br/>condition: sequence = 41
  alt sequence taken by a concurrent writer
    D--xA: ConditionalCheckFailed
    A->>D: PutItem AUDIT, sequence = 42
    D-->>A: appended
  else appended
    D-->>A: appended
  end
  A-->>C: 201 + audit event + request_id

entry_hash = sha256(previous_hash ‖ canonical_json(event_without_chain)).

Two writers cannot both take sequence 42, because the append is conditional on the previous sequence. A lost race retries at sequence + 1. The chain cannot fork, so it cannot be forked into a plausible-looking alternative history — and the DynamoDB policy grants PutItem on audit items and not UpdateItem or DeleteItem, so there is no application path to alter one.

Anyone can verify it:

bash
curl -sS -G "$BASE/audit-events/export" -H "$AUTH" -H "Accept: application/x-ndjson" \
  --data-urlencode 'format=ndjson' --data-urlencode 'since=2026-01-01T00:00:00.000Z' \
  --data-urlencode 'until=2026-06-30T23:59:59.000Z' -o audit.ndjson

#The MCP server

mermaid
flowchart TB
  Agent["Your agent"]
  subgraph "ulex:lambda:mcp"
    Route["Route by JSON-RPC method"]
    Tools["113 tool handlers"]
    Env["Resolve environment<br/>from the credential"]
    Scrub["Scrub every argument<br/>and every error"]
  end
  Core["@ulex/core<br/>schemas, enums, errors, ids"]
  DDB[("DynamoDB")]

  Agent -->|"POST /mcp<br/>Streamable HTTP"| Route
  Route -->|"tools/call"| Tools
  Route -->|"tools/list"| Tools
  Route -->|"initialize"| Env
  Tools --> Scrub --> Core
  Env --> Core
  Core --> DDB
  Scrub -->|"| error isError:true"| Agent

lambda:mcp is a thin translation layer over the same services the REST API uses. Every MCP tool returns the resource in both content[0].text and structuredContent, and a tool failure is a result.isError: true carrying the ulex envelope — not a JSON-RPC error. Every x-ulex-mcp-tool in openapi.json names the tool that wraps that operation, and both surfaces are generated from one manifest so they cannot drift.

The environment is resolved from the credential at the edge of the tool call and is never an argument. That is a structural property of the design, not a validation rule, and it is why the tools cannot be pointed at the wrong environment.

#Protocol surfaces

mermaid
flowchart LR
  subgraph "Human / client"
    Browser["Browser"]
    SP["Your app as SP"]
    IdP["Customer's IdP"]
    SCIMClient["Okta / Entra SCIM"]
    WebhookSink["Your webhook receiver"]
  end

  subgraph "ulex:lambda:protocol"
    OIDC["/oauth2/*<br/>authorize · token · userinfo<br/>introspect · revoke · keys"]
    SAML["/connections/id/saml/*<br/>login · acs · sso · slo"]
    SCIM["/scim/v2/*<br/>Users · Groups · Bulk · Patch"]
    HOOK["/webhooks/*<br/>HMAC-SHA256 delivery"]
    HOSTED["/auth/appId<br/>hosted UI"]
  end

  Core["@ulex/protocol"]
  DDB[("DynamoDB")]

  Browser --> OIDC
  Browser --> HOSTED
  SP --> OIDC
  SP -->|AuthnRequest| SAML
  IdP -->|SAMLResponse| SAML
  IdP -->|authorization_code| OIDC
  SCIMClient --> SCIM
  OIDC --> Core
  SAML --> Core
  SCIM --> Core
  HOOK --> Core
  HOSTED --> OIDC
  Core --> DDB
  Core -->|signed, retried| WebhookSink

@ulex/protocol implements OIDC, SAML 2.0, SCIM 2.0 and JWT verification as a library, with the Lambda as a thin adapter. That is why the same logic backs the REST endpoint, the MCP tool and the CLI.

#Directory sync and the worker

mermaid
flowchart LR
  Cron["EventBridge<br/>every 900 s"]
  Q1[["ulex-directory-sync"]]
  W["lambda:worker"]
  Up["Customer's directory<br/>SCIM or Graph"]
  DDB[("DynamoDB")]
  Q2[["ulex-webhooks"]]
  H["Delivery, 25/s, 8 attempts"]
  DLQ[["dead_lettered<br/>30 days"]]

  Cron --> Q1 --> W
  W -->|"SCIM GET /Users?filter=…"| Up
  Up --> W
  W -->|upsert by external_id| DDB
  W -->|mark run partial or succeeded| DDB
  W -->|dsync.user.* events| Q2 --> H
  H --> DDB
  H --> DLQ

A sync is a job, not a request. POST /directories/{id}/sync returns immediately and you poll for the terminal state. partial means some records failed and is reported as a failure by the API helper on purpose, because a directory that is 97% synced is a support ticket.

#Package layout

mermaid
flowchart LR
  CORE["core<br/>schemas · errors · ids<br/>no runtime dep but zod"]
  CRYPTO["crypto<br/>secrets · envelope encryption<br/>PKCE · JOSE · webhook signing"]
  PROTO["protocol<br/>OAuth 2.1 · OIDC<br/>SAML 2.0 · SCIM 2.0"]
  STORE["store<br/>in-memory (tests, local MCP)<br/>DynamoDB (hosted)"]
  AUTH["auth<br/>codes · tokens · sessions<br/>JIT provisioning"]
  MCP["mcp-server<br/>tool registry<br/>HTTP + stdio"]
  API["services/api<br/>REST · OAuth · SCIM · SAML · MCP"]
  CLI["cli<br/>the ulex binary"]
  INFRA["infra<br/>AWS CDK"]
  DOCS["docs<br/>this site"]

  CORE --> CRYPTO --> PROTO --> STORE --> AUTH --> MCP --> API
  CORE --> CLI
  CORE --> DOCS
  INFRA --> API
text
packages/
  core/         types, schemas, enums, ids, errors, scrubbing, ports
  crypto/       secrets, envelope encryption, PKCE, JOSE, webhook signing
  protocol/     OIDC, SAML 2.0, SCIM 2.0, JWT — a library
  store/        in-memory (tests, local MCP) and DynamoDB (hosted)
  auth/         the auth service: codes, tokens, sessions, JIT provisioning
  mcp-server/   the tool registry and the MCP transport
  cli/          the ulex binary
services/
  api/          the HTTP surface: REST, OAuth, SCIM, SAML, MCP, and the fixture IdP
infra/          AWS CDK
docs/           this site

The dependency direction is strictly one-way. core has no runtime dependency except zod, and CI fails if that breaks. It is what lets the domain model be imported by the CLI, the docs generator and the SDK without dragging anything in — and it is the single place a field name is defined, which is why the API, the MCP tool schema, the OpenAPI document and the SCIM mapping cannot disagree about it. packages/crypto is where secret handling lives, so there is exactly one implementation of envelope encryption, one PKCE verifier, and one webhook signer.

The MCP tool registry in packages/mcp-server/src/tools/index.ts is the single source for the tool surface: tools/list, ulex_list_tools, the ulex://tools resource and this documentation all derive from it. Adding a tool is one file plus one registry entry; nothing else changes.

#Data flow for one login

mermaid
sequenceDiagram
  autonumber
  participant A as Agent
  participant M as lambda:mcp
  participant P as lambda:protocol
  participant D as DynamoDB
  participant K as KMS

  A->>M: ulex_simulate_login {application_id, email}
  M->>P: authorize transaction
  P->>D: GET connection + org + domain
  D-->>P: con_… state: active, domains verified
  P->>D: resolve user by email (GSI1)
  D-->>P: usr_…
  P->>D: PutItem SESSION (ttl idle_expires_at)
  P->>D: PutItem GRANT (code_hash, code_challenge)
  P->>D: PutItem AUDIT authentication.succeeded
  P-->>M: session_id, grant_id, code, amr, acr
  M-->>A: structuredContent

  A->>M: ulex_exchange_code_for_tokens {code, code_verifier}
  M->>P: token endpoint
  P->>D: GET grant, verify PKCE, mark consumed
  P->>K: sign with the access_token key
  K-->>P: RS256 signature
  P->>D: PutItem REFRESH (token_hash, family_id, ttl)
  P-->>M: tokens
  M-->>A: access_token, refresh_token, id_token

Nothing here touches a browser, an MFA app, or DNS. That is the whole point.

#What this architecture buys

PropertyHow
scale to zeroevery Lambda has minimum: 0; DynamoDB is on-demand
an idle tenant costs almost nothingno provisioned capacity, no cluster, no fixed node
a cold start is invisible on RESTSnapStart restore plus warm DynamoDB; ~1.1 s
a 12,000-person directory does not page anyonethe sync is a queued Lambda with a 15-minute timeout
the audit log cannot be quietly editedconditional append, no update or delete in the IAM policy, object lock on archives
a signing key can rotate without an outageoverlapping retiring keys in the JWKS
an agent cannot escalate to another tenant or bypass simulator guardstenant isolation and allow_mocks are properties of the credential and tenant record, resolved before the tool runs

#What it costs

CostDriver
audit log writesone per mutation, never deleted, 7-year retention. The dominant cost
KMS Decrypt callsa client that caches its secrets badly shows up here
webhook retries8 invocations per failed delivery
Lambda millisecondsmetered; roughly 40 ms p50 per REST call

#Reference