Skip to Content
DevelopersHow Koomerce worksData model by area

2 min read

Data model by area

Tables grouped by area: platform, store setup, catalog, stock and buying, customers and carts, orders and money, shipping, online store, growth and messages, platform plumbing, and the apps' own tables.
To edit, open data-model.excalidraw in excalidraw.com, then save it back over the same file.

Rules every table follows

  • store_id and RLS. Every table except the platform ones has store_id uuid not null and the store_isolation policy (Stores and tenancy).
  • IDs are UUIDv7 made in the app (newId()), never sequences. The only counters are per store and explicit (store.next_order_number, store_counter, invoice_sequence).
  • Money is integer paise in *_paise columns.
  • Statuses are text with a CHECK, not Postgres enums, so adding one is a plain migration.
  • Secrets and phones are encrypted (AES-256-GCM) in the column, never stored plain.
  • References from a request are read under RLS before they are stored: foreign keys bypass RLS, so the database alone would accept another store’s id.

Where the schema lives

File (packages/db/src/)Area
schema.tsThe core: store, catalog, inventory, customers, carts, orders, payments, discounts, gift cards, roles, outbox
auth-schema.tsBetter Auth: user, session, account, organization, member, invitation, passkey
theme-schema.ts, content-schema.ts, metafield-schema.ts, market-schema.tsOnline store: themes, pages, menus, redirects, extra fields, content types, markets, catalogs, translations
shipping-schema.ts, delivery-schema.tsShipments, pickups, manifests, webhooks, wallets, zones, rates, profiles, delivery options
purchasing-schema.tsSuppliers, purchase orders, charges, receipts, inbound shipments, documents
returns-schema.ts, store-credit-schema.tsReturns, store credit accounts and entries
marketing-schema.ts, automation-schema.ts, pixel-schema.ts, inbox-schema.ts, rollout-schema.tsGrowth: sessions, campaigns, links, Web Vitals, workflows and runs, pixels, inbox, rollouts
ai-schema.ts, api-access-schema.tsAI settings, usage, proposed actions, bulk jobs; OAuth clients, grants, API activity
billing-schema.tsPlans, usage bills, plan payments, app purchases, AI credits, AutoPay
privacy-schema.ts, shopper-login-schema.tsCookie consent, data requests, privacy audit; shopper identities and passkeys
store-activity-schema.ts, store-data-schema.ts, bug-report-schema.ts, email-suppression-schema.ts, othersActivity log, exports, platform audit, bug reports, email suppression

Apps own their tables in their packages: plugin-gst-invoices/src/schema.ts (invoices), plugin-reviews, plugin-affiliates, plugin-back-in-stock, plugin-forms, plugin-growthbook, plugin-shopify-import. Their migrations live with everyone else’s in packages/db/drizzle/ (234 files, newest 0249_shipment_shared_order).

The order spine

cart ─► order ─┬─► order_line ├─► fulfillment_order (parcel, one location, one GSTIN) ─► fulfillment_order_line │ └─► shipment (+ shipment_shared_order when another order rides in the box) ├─► payment ◄── payment_event (webhooks, deduplicated) ├─► refund ─► store_credit_entry (when refunded as credit) ├─► return_request ─► return_request_line └─► invoice (GST app, one per parcel) ─► credit notes

Order statuses (payment_status, fulfillment_status, status) are derived by recomputeOrderStatuses; nothing else writes them.

Deeper

Data model overview has the main tables column by column, parcels, returns, purchasing and landed cost, retention, and how to add a table (schema, migration, apply_store_rls(), seed).

Was this helpful?
Last updated on