Self-hosting
Architecture & local development
How the gateway is put together, and how to run the stack locally.
The whole stack is Cloudflare-native: D1 (SQLite) for the database, R2 for digital-good files. Dev needs no external services; wrangler emulates both locally.
Components
- Gateway: a catch-all route (
/m/{slug}/…) resolves the merchant and product from the database and composes the mppx charge wrapper at request time (per-merchant recipient and amount). Per-merchantMppxinstances are cached. - Discovery:
GET /m/{slug}/openapi.jsonadvertises each offer withx-payment-info.offers[](amount, currency contract, network, recipient). - Products:
api_proxy(pay-per-request proxy to the builder's upstream API; auth header encrypted at rest, never exposed) anddigital_good(pay-per-download file). - Dashboard: Auth.js (GitHub/Google OAuth; dev login outside production), merchant/product CRUD, sales log.
- Marketplace: public listing of published merchants with agent snippets.
- Robinhood Chain rail: the Permit2-based x402 rail described in Robinhood Chain rail.
One Cloudflare Worker serves the human site (meshgateway.co) and the
machine surface (api.meshgateway.co: /m/* 402 endpoints, the aggregate
/openapi.json, /api/gas/sponsor), routed by hostname middleware.
Run it locally
npm install
cd apps/web
npx wrangler d1 migrations apply meshgateway-db --local
npx tsx scripts/seed-stocks.ts http://localhost:3000 # needs .env.local loaded
npx wrangler d1 execute meshgateway-db --local --file scripts/seed-stocks.generated.sql
cd ../.. && npm run devRequired environment is covered in Environment variables.
Schema changes
Edit the Drizzle schema (src/lib/db/schema.ts), run
npx drizzle-kit generate, then apply the migration:
npx wrangler d1 migrations apply meshgateway-db --local