Use this page together with the Self-Hosting guide, which shows you how to configure DATABASE_URL, run prisma migrate deploy, and inspect the database in production.
Reference for the OFFER-HUB database schema — every Prisma model, its fields, relationships, and how the tables fit together.
OFFER-HUB persists all state in a PostgreSQL database driven by Prisma. This page is the reference for the exact schema that a self-hosting participant hits directly when running migrations, inspecting seed data, or debugging. Every model, field, and relationship below is verified against the canonical packages/database/prisma/schema.prisma in the OFFER-HUB Orchestrator repository.
Use this page together with the Self-Hosting guide, which shows you how to configure DATABASE_URL, run prisma migrate deploy, and inspect the database in production.
Two tables carry critical invariants: balances.available / balances.reserved and wallets.secret_encrypted. Never update balance values or decrypt wallet secrets directly in SQL — always go through the API's BalanceService and WalletService. Downstream financial bugs and unrecoverable funds are the cost of bypassing them.
The following ER diagram shows every table and how they reference each other. Currency amounts are stored as decimal strings ("100.00"), not floats, to preserve exact precision in financial arithmetic.
Core PostgreSQL relationships defined by the Prisma schema.
The schema has 14 models. Models whose status follows a transition map link to their lifecycle in State Machines.
Public resources use prefixed IDs so you can tell what an ID points to at a glance, for example ord_V1StGXR8Z5jdHi6B3mEv0aBcDeFgHiJk. The prefixes are defined in packages/shared/src/constants/id-prefixes.ts and applied by generateId in packages/shared/src/utils/id-generator.ts, which appends a 32-character alphanumeric nanoid. The Prisma schema marks each prefixed @id with a // Prefixed ID: comment.
A few prefixes behave differently:
evt_ IDs belong to event bus payloads, not a table. EventBusService builds them as evt_ plus a 21-character nanoid.key_ is the API key's record ID. The raw key you send in Authorization embeds it as ohk_{env}_{key_id}_{random}.mkt_ is defined but unused. marketplaceId columns, such as the one on IdempotencyKey, store a plain string.Balance, Milestone, WebhookEvent and ProcessedTransaction use Prisma's cuid(), and IdempotencyKey uses uuid(). These IDs carry no prefix and are mostly internal, though milestone IDs do appear in order responses.
Each section lists the model's table name, the purpose it serves, and its key fields. Columns are rendered exactly as they appear in the Prisma schema, with the camelCase field name, its database column, type, and a short description.
A marketplace participant (buyer, seller, or both). User is the root of the identity graph — balances, wallets, top-ups, withdrawals, and orders all hang off it.
One row per user tracking spendable and reserved funds. available is immediately usable; reserved is held against an active order and is no longer spendable.
Invariant: available and reserved must only change through BalanceService (credit/debit/reserve/release), which enforces atomicity, minimum-balance checks, event emission, and audit logging.
Scoped credentials used to authenticate API calls via the Authorization: Bearer ohk_... header. Only the salted hash is stored — the raw key is shown once at creation.
Invisible Stellar wallet whose secret keypair is encrypted at rest with AES-256-GCM using WALLET_ENCRYPTION_KEY. Each user has one primary wallet.
Fiat on-ramp record (Airtm mode). Async flow driven by Airtm webhooks — see Deposits Guide.
The lifecycle root of a marketplace transaction. Funds move from the buyer's available balance into reserved, then on-chain via an escrow.
Links an order to its non-custodial Trustless Work/Soroban contract on Stellar. Exactly one escrow per order.
Optional sub-deliverables of an order, used when escrow terms require milestones.
Outbound funds transfer — either an Airtm payout or a direct Stellar payment. See Withdrawals Guide.
A dispute opened on an order which freezes its lifecycle until resolved. Resolution produces a ResolutionDecision.
Immutable, append-only record of state-changing actions for traceability and compliance.
Deduplicates inbound webhooks from external providers (Airtm, Trustless Work, Stellar) via a unique (provider, providerEventId) constraint.
Stores cached responses so retried requests return the same result instead of executing twice. Scoped per marketplace via marketplaceId.
DB-level deduplication safety net for on-chain Stellar deposits. Prevents double-crediting a balance when both the real-time monitor and the reconciliation worker observe the same payment.
The schema defines these enums. Request bodies and webhook payloads use UPPER_SNAKE_CASE values.
For self-hosters, the schema lives in packages/database/prisma/schema.prisma. Common operations:
Always take a database backup before running migrations in production. See the Self-Hosting guide for the full workflow.
Use the Prisma Studio GUI or standard SQL. For example, find a user's current balance:
Order, Escrow, and MilestoneDispute, TopUp, Withdrawal and MilestoneTopUp and ProcessedTransaction flowsWithdrawal flows