Architecture

Repository layout

apps/api          Fastify service: REST (/v1), OAuth (/oauth), MCP (/mcp), ACP (/acp), UCP (/ucp/v1), feeds (/feeds), discovery (/.well-known), admin API (/admin/api), webhooks, tasks, docs + admin static
apps/admin        React admin portal (built into apps/api/public/admin)
apps/docs         This documentation (built into apps/api/public/docs)
packages/core     Domain: catalog, pricing, quotes/checkouts/orders state machine, OAuth server, messaging, payments, tasks, admin; protocols/ (ACP, UCP with AP2, feeds, signing keys, idempotency, order webhooks)
packages/db       Drizzle schema + migrations (Postgres in the cloud, PGlite in tests/dev)
packages/snappy-client  Typed Snappy Public API v3 client, fixtures, contract test against the vendored OpenAPI spec
infra/terraform   bootstrap (projects, state, WIF) · modules/platform · envs/sandbox · envs/prod
.github/workflows ci (typecheck, tests, build, tofu validate) · deploy (sandbox on main, prod on approval) · infra (validate on PR, plan and apply on merge)

Runtime (per environment)

On prod, since November 2026, "Internet" below means Snappy's Twingate egress addresses: Cloud Armor refuses everything else except the two health checks. The diagrams show the paths as designed; agents, shoppers and webhook senders outside the network are refused at the prod load balancer; sandbox is public. See Operations.

                 ┌────────────────────────────── GCP project snappy-agents-<env> ──────────────────────────────┐
 Internet ─▶ Global HTTPS LB (managed cert, Cloud Armor) ─┬─▶ Cloud Run `agents-api`                      │
                       /admin/* ─▶ Identity-Aware Proxy ─┘   (same service; IAP JWT verified in-app)        │
                                                                     │  Direct VPC egress                     │
                                                      ┌──────────────┼───────────────┐                        │
                                                      ▼              ▼               ▼                        │
                                              Cloud SQL Postgres   Cloud Tasks   Secret Manager                │
                                              (private IP, VPC)    (push → /internal/tasks/*, OIDC)            │
                                                      ▲                                                        │
                                              Cloud Scheduler ─▶ /internal/tasks/expire-checkouts (5 min)      │
                                                              ─▶ /internal/tasks/expire-protocol-sessions (10 min) │
                 Cloud NAT (static IP) ◀─ outbound to api.snappy.com, api.stripe.com, sendgrid, twilio,         │
                                          platform webhook URLs (ACP, UCP) and Google's order endpoint          │
                 └─────────────────────────────────────────────────────────────────────────────────────────────┘

The same runtime as a chart, with the traffic that enters and leaves the project (see Workflows for every flow):

flowchart LR
  subgraph agents["Agent platforms"]
    muse["Meta Muse, Claude, ChatGPT or a partner agent"]
    platforms["ChatGPT Instant Checkout, Google AI Mode, Shopify agents: ACP, UCP"]
  end
  subgraph gcp["GCP project snappy-agents-sandbox or snappy-agents-prod"]
    lb["Global HTTPS load balancer, managed cert, Cloud Armor"]
    iap["Identity-Aware Proxy backend for /admin"]
    api["Cloud Run agents-api: /oauth, /v1, /mcp, /acp, /ucp/v1, /feeds, /webhooks, /internal/tasks, /admin, /docs"]
    sql[("Cloud SQL Postgres, private IP in the VPC")]
    tasks["Cloud Tasks queue"]
    sched["Cloud Scheduler: expire-checkouts every 5 min, expire-protocol-sessions every 10 min"]
    sm[("Secret Manager")]
    nat["Cloud NAT, static egress IP"]
  end
  subgraph ext["Third parties"]
    snappy["Snappy Public API v3"]
    stripe["Stripe Checkout"]
    sendgrid["SendGrid email"]
    twilio["Twilio SMS"]
    anthropic["Anthropic API, negotiation AI"]
  end
  shopper["Shopper browser: sign-in, consent, payment page"]
  ops["Operators, Google Workspace accounts"]
  muse -->|"OAuth 2.1 + PKCE, then REST /v1 or MCP /mcp"| lb
  platforms -->|"platform key or client_credentials: checkout sessions, feeds, discovery"| lb
  shopper --> lb
  ops -->|"/admin"| lb
  lb --> api
  lb -->|"/admin*"| iap --> api
  api --> sql
  api -->|"enqueue"| tasks
  tasks -->|"POST /internal/tasks/:task with OIDC"| api
  sched --> api
  api -->|"read latest, add versions"| sm
  api --> nat
  nat --> snappy
  nat --> stripe
  nat --> sendgrid
  nat --> twilio
  nat --> anthropic
  nat -->|"order webhooks: ACP HMAC, UCP RFC 9421 or Google API key"| platforms
  stripe -->|"/webhooks/stripe, signed"| lb
  snappy -->|"/webhooks/snappy, HMAC"| lb
  twilio -->|"/webhooks/twilio, STOP/START/HELP"| lb

Why these choices

Choice Reason
Opaque tokens instead of JWT One resource server; instant revocation; nothing to leak from a decoded token
Stripe Checkout (hosted) No PCI scope, no card data in the agent or the platform, Muse's "payment link" model
Quote → checkout split The user sees and approves the exact amount; the price cannot move between consent and charge
Snappy idempotencyKey = checkout id + item index Payment webhooks and task retries can never double-order, even for carts
Credentials via the admin portal into Secret Manager Operators rotate keys without a deploy; nothing secret in Terraform, CI or the database
IAP in front of /admin Google-managed sign-in restricted to the organisation; static admin assets never reach anonymous users
PGlite in tests Full Postgres semantics (unique indexes, JSON) in CI without a service container
Vendored Snappy OpenAPI + contract test Fixture mode stays honest when Snappy's contract changes
Protocol sessions on top of checkouts, not beside them ACP and UCP reuse pricing, order placement, refunds, notifications, support and the admin portal; the protocol layer only maps shapes, authenticates platforms and charges the delegated token
Delegated tokens charged server-side with an idempotent PaymentIntent No card data enters the service under ACP or UCP either; a retried complete replays instead of charging twice
Platform API keys hashed, webhook secrets encrypted, business keys in Secret Manager A database read-out yields no usable credential; the JWK Set is public by design and rotates with a 14-day overlap
Snappy Agents · agents.snappy.com · support@snappy.com