Self-hosted e-commerce platform for atproto bazaar.whereditgo.diamonds
README.md

Bazaar #

bazaar logo

Note: Set up for auto-deploy on tangled.sh spindle.

Setting up Cloudflare R2 #

Bazaar needs one R2 bucket per environment. It holds inventory bytes and the Litestream SQLite backups (under a litestream/ prefix). The bucket is created once, by hand — nothing in CI creates or modifies it, so a deploy can never rename or delete your storage.

These are manual steps in the Cloudflare dashboard:

  • Make a Cloudflare account.
  • Go to the R2 dashboard and subscribe to the R2 service.
  • Create a bucket. bazaar-prod is the convention (bazaar-stg for staging), but any name works — the app reads whatever you set as R2_BUCKET_NAME.
  • Create an S3 API token under R2 → Manage R2 API Tokens, with Object Read & Write on that bucket. This is not the same thing as an account-level Cloudflare API token.
  • Note your Account ID from the dashboard sidebar (not the Zone ID).

If you would rather do it from a terminal than the dashboard, the bucket step is:

npx wrangler r2 bucket create bazaar-prod

The token still has to be minted in the dashboard. Keep the access key id and secret — they go into the Fly runtime secrets below as R2_ACCESS_KEY_ID / R2_SECRET_ACCESS_KEY.

Setting up secrets #

Deploys run as spindle workflows (.tangled/workflows/). Make sure every secret they need is set before the first run — each workflow checks for its secrets and stops if any is missing.

Tangled repository secrets (repo Settings → Secrets). Production uses the plain names; staging has its own _STG copy of each:

  • FLY_APP_NAME / FLY_APP_NAME_STG — your Fly app names. fly.toml and fly.stg.toml carry placeholders so the repo does not name anyone's deployment; the real name is passed with --app at deploy time. Locally, set FLY_APP instead.
  • FLY_API_TOKEN / FLY_API_TOKEN_STG — a deploy token scoped to that one app: fly tokens create deploy -a <app>. Not an org-wide or personal token: Tangled secrets are readable by every workflow, including pull-request test runs, so an app-scoped token keeps a leaked staging token away from production. Wrong/missing token → unauthorized.
  • VITE_MERCHANT_DID / VITE_MERCHANT_DID_STG — build-arg baked into the client bundle at image build time. Must equal that app's MERCHANT_DID runtime secret below.

The R2 credentials are not Tangled secrets — CI never touches R2. They are Fly runtime secrets; see the next section.

When deploys run:

  • Staging deploys on every push to the staging branch.
  • Production deploys only when you push a v* tag, and only if the tagged commit is on main: git tag vX.Y.Z main && git push origin vX.Y.Z. Pushing to main deploys nothing.
  • Pushes and pull requests to main run the tests.

Setting up Fly runtime secrets (server env) #

The Tangled secrets above are CI/deploy-only — the running app never reads them. Server env vars (packages/server/.env.example) must be set separately on each Fly app:

fly secrets set KEY=value -a <your-app>

At minimum:

  • MERCHANT_DID — store owner DID, required for /api/merchant/*
  • APP_URL — the public HTTPS origin the store is served from (e.g. https://store.example.com, or the app's fly.dev hostname), no trailing path. OAuth's client-metadata and redirect URLs are built from it; it defaults to http://127.0.0.1:3000, so sign-in cannot work in production without it.
  • Storefront signing identity — from make storefront-key (see below): STOREFRONT_DID, STOREFRONT_PRIVATE_KEY, STOREFRONT_KID, STOREFRONT_PUBLIC_MULTIBASE. These build the DID document served at /.well-known/did.json, which is how anyone verifies a receipt your store issued. If they are unset the app still starts, serves a DID document with no verificationMethod, and signs receipts nobody can verify — one warning line at boot is the only signal. (STOREFRONT_KEY_HISTORY is added later, on key rotation.)
  • Cloudflare R2 — inventory uploads and Litestream DB backups share one credential set: CF_ACCOUNT_ID, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY, R2_BUCKET_NAME. All four are required together. Without them the app starts with no backups and prints a line saying so. After setting them, confirm Litestream is actually running via fly logs right after a restart (it prints its own startup lines) — don't just trust that the vars are set. On a blank volume (first boot, or a lost volume) the container restores the database from R2 before the app starts, and logs whether it found a backup.
  • Stripe — STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET for checkout. Alternatively, leave them unset and save the Stripe keys from the merchant dashboard; a key set in the environment takes precedence over one saved there.

See packages/server/.env.example for the full list of server env vars.

Create the storefront identity #

Your storefront is identified by a did:web: DID. AT Protocol resolves it by fetching https://<your-domain>/.well-known/did.json, which this app serves — so the domain in the DID must be the domain the store is reachable at.

npm i
make storefront-key DOMAIN=store.example.com

DOMAIN is the address your store is reachable at; pasting the URL straight from your browser works. This writes a key file under keys/ and prints the secrets to set:

fly secrets set -a <app> \
  STOREFRONT_DID=… STOREFRONT_KID=… STOREFRONT_PRIVATE_KEY=… STOREFRONT_PUBLIC_MULTIBASE=…

Set them in one command. Applying them separately leaves a window where the deployment has part of an identity, and receipts signed in it will not verify.

Confirm it worked by fetching https://<your-domain>/.well-known/did.json — it should list a verificationMethod whose fragment matches your STOREFRONT_KID.

Your key files #

keys/ holds one file per key. Keep them. They are what lets a later rotation rebuild STOREFRONT_KEY_HISTORY; without them you cannot prove past receipts came from your store.

They contain private keys in plain text. They are gitignored and excluded from Docker builds, but keep them out of shared folders and backups, and delete any you are sure you no longer need.

Re-running make storefront-key with key files present re-prints the secrets without generating anything — use it when setting up a new deployment from the same identity.

Rotating the key #

make storefront-key-rotate

A new key becomes active; the old one is marked retired — still listed in the DID document and still trusted for receipts it already signed. You get an updated block including STOREFRONT_KEY_HISTORY; set all of it together.

Revoking a key #

make storefront-key-revoke KID=storefront-key-2026-09-16

Use this when a key leaked, not when rotating on schedule. A revoked key is dropped from the DID document's verificationMethod (its key-history entry stays, marked revoked), and receipts naming it are rejected outright — including ones that were signed legitimately before the leak. Rotate first; the active key cannot be revoked.

Setting up OAuth #

OAuth needs APP_URL set to the public HTTPS origin your store is served from (see above). The app's fly.dev hostname works; a custom domain is optional. To use one registered elsewhere, add a certificate for it on your Fly app (fly certs add <domain>) and create the DNS records it asks for, then set APP_URL to that domain. The storefront's did:web identity must use the same domain the store is reached at.

Allowing multipart uploads direct to R2 #

Files over 8 MB upload in parts. The browser first tries sending each part straight to R2, which is faster; if the bucket's CORS rules don't allow your store's origin, that upload falls back to going through the server. To enable direct uploads, add a CORS rule on the bucket allowing PUT from your store's origin. Smaller files always go through the server.

Licence #

Bazaar is licensed under the MIT License — the application and the lexicons alike. See LICENSE.

Use it, modify it, self-host it, run a commercial store on it, or build a competing client, indexer or storefront against its lexicons. Keep the copyright notice; nothing else is asked.

Contributions are accepted under the same licence; see CONTRIBUTING.md.