Skip to content
21giftsPublic

About

Backend service + canonical project docs for 21.gifts — a peer-to-peer Bitcoin Lightning donation platform with NOSTR-native communication

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

21.gifts — api

Docker Hub Image size (beta) Image size (latest) Pulls License: MIT

Backend service for 21.gifts — a peer-to-peer Bitcoin Lightning donation platform with NOSTR as the invisible communication substrate.

This repository is the canonical home for project-level documentation (see CONCEPT.md). The implemented HTTP surface is documented in SPEC.md. The frontend lives at 21gifts/app.

21.gifts stands on three convictions: giving is a duty of every Christian; the best gift travels from one person to another with no middleman; Bitcoin is the most effective money available today. The argument is in CONCEPT.md (Convictions) and on 21.gifts/about.

🐳 Docker images

Pre-built images are published to Docker Hub on every push to develop (:beta), staging (:staging), and main (:latest).

Tag Source Deploy target Public URL
21gifts/api:beta develop DEV https://dev-api.21.gifts
21gifts/api:staging staging staging https://staging-api.21.gifts
21gifts/api:latest main PRD https://api.21.gifts

Pull and run locally:

docker run --rm -p 3000:3000 21gifts/api:beta
# → http://localhost:3000/healthz

Full image list and history: hub.docker.com/r/21gifts/api.

What this service does

The api is the "thick server" in a thin-client / thick-server architecture. It handles everything that doesn't have to run client-side:

  • NOSTR fan-out — accepts signed events from clients, verifies signatures, publishes to the shared nostr.space relay
  • NOSTR aggregation — subscribes to the relay, indexes events, exposes paginated reads
  • LN-Address resolution + caching — LUD-16 endpoints health-checked and normalized
  • Discovery — recent campaigns, ordering, future categories / search
  • Anti-abuse — rate-limiting, spam scoring, malformed-event rejection

It explicitly does not hold keys or sign events for the non-custodial target (v1 signs custodial identities server-side). Guest Donate LNURL-pay is paid in the browser; for a member's wallet address this api forwards the LNURL metadata and invoice callback, so it sees the amount and the invoice, but it never pays or holds funds. Fond payouts are the exception (POST /fond/payouts/:id/invoice fetches a recipient BOLT11, this api still does not pay).

Stack

Layer Choice
Runtime Bun ≥ 1.4.4
Language TypeScript (strict)
Framework Hono
Test runner Vitest + @vitest/coverage-v8
Lint ESLint (flat config) + Prettier
Validation Zod

All non-trivial functions ship with TSDoc. Coverage is hard-gated at 100% (lines, branches, functions, statements) on the activated surface — CI red otherwise.

Quick start

git clone https://github.com/21gifts/api.git
cd api
bun install
MEDIA_DIR="$(mktemp -d)" bun run dev    # → http://localhost:3000/healthz

Local checks (the same gates CI runs)

bun run typecheck       # tsc --noEmit
bun run lint            # eslint + prettier --check
bun run handbook:check  # every function and HTTP endpoint must be documented
bun run e2e:check       # every HTTP endpoint request and Function: <Name> title
bun run test:coverage   # vitest with 100% threshold
# Postgres driver (Bun test, not Vitest); fails if DATABASE_URL is missing
DATABASE_URL=postgres://gifts:gifts@127.0.0.1:5432/gifts bun run test:postgres
bun run build           # bun build to dist/
bun run e2e             # Playwright against bun src/index.ts

Runtime configuration

Variable Required Purpose
MEDIA_DIR yes Directory for forum video files. Missing or blank → process does not boot. Image/Compose pin /data/media. Not a secret.
WEBAUTHN_RP_ID For passkey login WebAuthn RP ID (21.gifts / dev.21.gifts / staging.21.gifts / localhost). Missing → passkey routes return 500; process still boots. Not a secret.
WEBAUTHN_RP_NAME no Human-readable RP name (default 21.gifts).
CORS_ALLOWED_ORIGINS no Comma-separated browser origins. Passkey finish allows those whose hostname is the RP ID or app.<rpId> only.
LOGINS_OPEN_DEFAULT no Login switch until an operator sets it: open (default) or closed. Any other value stops the boot. Not a secret.
RECOVERY_SHARE_REQUIRED_FROM no First UTC day (YYYY-MM-DD) a grant or moderator payout needs the 21.gifts recovery share. Unset or blank → not required yet. A value that is not a calendar day stops the boot. Not a secret.
APP_BUILD_REQUIRED no App build id that session-creating requests must send in X-App-Build. Unset or blank → no check. Not a secret.

Documentation

Doc Purpose
docs/shop-identity.md Every shop gets its own NOSTR identity and page /{npub}, shared with OpenCryptoPay (S1, S2, S3 and S5 implemented; S4, the page, is in the app)
CONCEPT.md Project vision, architecture, principles, decisions
SPEC.md Implemented HTTP surface (request/response contracts)
FLOWS.md Core UI journeys (sign-in → profile → donate → recurring → message)
docs/social-recovery.md Optional securing of the account, required for grant payouts from RECOVERY_SHARE_REQUIRED_FROM: 12 words split 2-of-3 between two people, whose shares the api keeps only as boxes it cannot open, and a 21.gifts backup (implemented; the routes are in SPEC.md)
docs/shop-stablecoin-payment.md Shop QR stays OpenCryptoPay; USDT or USDC on fixed EVM chains goes to Orchestra, which pays one BOLT11 to the shop (implemented; stablecoin rows only when the four shop payment variables resolve)
scripts/shop-staging-e2e/ Live staging harness for one shop stablecoin payment and the return of those sats to the paying account. Dated runs live in records/. Not part of CI. It does not close the release checks.
docs/wallet-release-payouts.md Daily payouts across the in-app wallet release: who is paid today, why each keeps being paid on the wallet only, and what release day needs
docs/handbook/ Mandatory: every function and HTTP endpoint
CONTRIBUTING.md Dev setup, conventions, workflow
SECURITY.md Reporting vulnerabilities

License

MIT — see LICENSE.

About

Backend service + canonical project docs for 21.gifts — a peer-to-peer Bitcoin Lightning donation platform with NOSTR-native communication

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages