***

title: Integration Patterns
subtitle: Recommended backend patterns for `@gwop/sdk`
slug: integration-patterns/overview
-----------------------------------

These patterns show the smallest production-minded backend shape for a Gwop integration:

* one shared SDK client
* thin app-owned adapters around Gwop
* local JWT verification with cached JWKS
* webhook-driven state transitions
* app-owned routes, persistence, and entitlements

## Architecture

```text
Agent -> app routes -> app services -> thin Gwop adapters -> @gwop/sdk -> Gwop
```

Your backend owns the API surface and business rules. Gwop owns identity, invoices, sessions, JWKS, and webhook signatures.

## Design rules

1. Bootstrap the SDK once and share it.
2. Keep auth, invoice, and webhook code in app-owned adapters so upstream details stay isolated.
3. Verify JWTs locally, then use `sid` for a live session check when revocation matters.
4. Store both merchant and public invoice IDs.
5. Trust webhook state transitions only after verifying the raw request body.

<Note>
  These patterns are demonstrated end-to-end in the [Agentrouter sample app](https://github.com/gwop-io/agentrouter-demo), a headless LLM store built on `@gwop/sdk`.
</Note>

## Next pages

<CardGroup cols={2}>
  <Card title="Shared SDK Client" icon="duotone plug-circle-bolt" href="/integration-patterns/shared-client">
    Bootstrap one client and keep identity request options explicit
  </Card>

  <Card title="Wallet Auth" icon="duotone wallet" href="/integration-patterns/wallet-auth">
    Create challenges, exchange them for JWTs, and manage sessions
  </Card>

  <Card title="JWT Verification" icon="duotone badge-check" href="/integration-patterns/jwt-verification">
    Verify access tokens locally and refresh JWKS on key rotation
  </Card>

  <Card title="Subscription Checkout" icon="duotone file-invoice-dollar" href="/integration-patterns/subscription-checkout">
    Create invoices and carry both IDs through your app model
  </Card>

  <Card title="Webhook Verification" icon="duotone bell" href="/integration-patterns/webhook-verification">
    Validate signed deliveries before mutating local state
  </Card>
</CardGroup>
