Skip to content

Data Model — Index

Pointer page. The canonical sources are: - ../data-model/ — six Mermaid ER diagrams grouped by domain, with file:line citations into the Prisma schemas. - ebit-api/libs/_prisma/src/schema/ — actual Prisma schemas (split across three files).


Schema split

Prisma uses the prismaSchemaFolder + multiSchema preview features (declared in api.prisma:3). Three files map to three Postgres schemas inside one DB:

File Postgres schema Tables Owner app(s)
ebit-api/libs/_prisma/src/schema/api.prisma public ~50 models, 4 views, ~30 enums api, bo
ebit-api/libs/_prisma/src/schema/blackjack.prisma blackjack 8 models, 2 enums bj
ebit-api/libs/_prisma/src/schema/speed_roulette.prisma speed_roulette 3 models, 2 enums speed-roulette

Why a split (not three databases): cross-schema FKs (e.g., BlackjackBet.userIdUser.id) need to stay cheap. A split inside one DB keeps joins index-friendly while still letting each app version its own schema. See ADR-0006.

The seed entrypoint is ebit-api/libs/_prisma/src/seed/index.ts. All prisma commands are wrapped with env-cmd -f .env (or .env.test) — always use the npm scripts (db:migrate:dev, db:seed, db:reset, prisma:*:test) rather than calling npx prisma directly, or Prisma will miss the env file.


ER diagrams (by domain)

ERD Scope Key tables Doc
Auth & User Identity Registration, login, sessions, KYC, MFA, permissions, responsible gambling, fairness seeds User, UserSession, UserKyc, UserRole, UserFairnessSeeds ../data-model/erd-auth.md
Bet & Accounting Bets, transactions, balances, deposits, withdrawals, game catalogue, tips, rakeback Bet, Transaction, UserBalance, Deposit, Withdraw, GameIdentity ../data-model/erd-bet-accounting.md
Promo, Challenge & Affiliate Promo codes, deposit bonuses, challenges, leaderboards, affiliate referrals PromoCode, UserPromoCode, Challenge, Leaderboard, AffiliateCode ../data-model/erd-promo-challenge.md
Admin & Platform Admin audit logs, site config, chat, support, bots, third-party integrations AdminActionLog, SiteConfig, ChatRoom, BotsCasino ../data-model/erd-admin.md
Blackjack Multiplayer blackjack tables, games, hands, provably-fair seeds BlackjackTable, BlackjackGame, BlackjackBet ../data-model/erd-blackjack.md
Speed Roulette Speed roulette rounds, bets, EOS-based provable fairness SpeedRouletteGame, SpeedRouletteBet ../data-model/erd-speed-roulette.md

The catalogue lives in ../data-model/README.md — that's the right entry point if you want to browse all six diagrams in order.


Conventions from the schema

These are enforced consistently across all three Prisma files. From ../data-model/README.md:

  • @@map("snake_case") on every model/enum — Prisma model names are PascalCase, Postgres table names are snake_case.
  • @@schema("public" | "blackjack" | "speed_roulette") required on every model/enum because of multiSchema.
  • @map("snake_case") on every field — Prisma fields are camelCase, Postgres columns are snake_case.
  • Decimal for money — all monetary amounts use Decimal (Prisma) / numeric (Postgres). Never Float.
  • UUID PKs for high-write tablesBet, Transaction, Deposit, Withdraw use @default(uuid()). Low-write config tables use @default(autoincrement()).
  • Composite PKs for join tables — e.g., UserBalance(userId, currencyId), UserRole(userId, role).
  • Postgres viewsAffiliateAggregatedInfo, AffiliateStreamer, UserBalanceEvo, UserBalanceDbc, LeaderboardUserPositionView are view not model (read-only aggregations).

High-level entity diagram

A single top-level diagram showing how the six domains connect to User is not currently in ../data-model/. {{TBD}} — proposed addition: a Mermaid erDiagram with User at the centre and stub-relationships to Bet, BlackjackBet, SpeedRouletteBet, Transaction, UserKyc, UserPromoCode, AffiliateCode. Each per-domain ERD already shows User as a stub; consolidating into one cross-domain view would help new developers orient.

If you take this on, place it at ../data-model/erd-overview.md and link it from ../data-model/README.md.


How to read

Diagrams use Mermaid erDiagram syntax — render in any Mermaid-compatible viewer (GitHub, GitLab, VS Code, Obsidian).

  • PK = primary key
  • FK = foreign key
  • UK = unique constraint
  • ||--o{ = one-to-many
  • ||--o| = one-to-zero-or-one
  • }o--|| = many-to-one

The User model appears as a stub in multiple diagrams — only auth-relevant fields are shown in erd-auth.md; other ERDs show User with minimal fields to keep diagrams focused.


Recipes


See also

  • stack.md §2 — Prisma 7.x version + rationale.
  • architecture.md §"Repos and their relationship" — how the apps own which schema.
  • ADR-0006 — rationale for the split.
  • ../glossary.md — every domain term with file:line citation.