Skip to main content

Architecture

The shape: a modular core with purpose-split deployables​

The platform is not a microservice mesh, and that is a decision, not an omission. It is a pnpm monorepo that produces six deployables, and the boundaries between them are drawn where operational behavior differs — how a process scales and how it fails — never one-service-per-entity:

  • api scales horizontally. It holds no provider connection and no singleton state, so replicas are interchangeable.
  • feed runs as exactly one instance. A RabbitMQ queue delivers each message to a single consumer — a second replica would not double throughput, it would split the provider stream in half.
  • admin is a separate process so back-office traffic and player traffic never compete, and so its capability model stays physically apart from the player-facing API.
  • cdn, site and docs are delivery concerns: static nginx or a Next.js renderer, no business logic.

Inside api, the architecture is clean / hexagonal: one NestJS module per domain feature, each owning its own Mongoose schema, dependencies injected via constructors, and external concerns behind ports (see the section on player ownership below). Code shared between apps lives in workspace packages — an app never imports another app's src/.

Why not microservices​

The honest classification: business domains (betting, wallet, settlement, cashout) live together in api as modules, the processes communicate through the database rather than over a service mesh, and the whole platform deploys as one compose stack. That disqualifies it as "microservices" — deliberately.

The cost microservices would add. This platform is sold to be self-hosted. A microservice split hands every buyer the full distributed tab: an orchestrator, inter-service networking and auth, distributed tracing, and eventual consistency across services — for money movements, where eventual consistency is not an inconvenience but a correctness risk. A bet, its wallet debit and its settlement belong in one transactional boundary; splitting them across services trades a function call for a saga.

The benefit microservices promise, already captured. The reasons teams reach for microservices are independent scaling, failure isolation and independent deployability — and the six-process split already delivers the ones that matter here: the api scales horizontally today; a feed crash loses no bets and touches no wallet; the back-office deploys and fails apart from player traffic. What remains inside api is exactly the part that benefits from staying together.

The escape hatch is real. Module boundaries are enforced (a module owns its schema; apps share code only through packages; integrations sit behind ports), so extracting a module into its own service later is a mechanical refactor, not an excavation. The architecture keeps that option open without making every buyer pay for it on day one.

If your team's standard requires one-service-per-domain, this codebase will read as a modular monolith with service-grade boundaries — which is what it is, on purpose.

Multi-tenancy​

One deployment serves many operators (casinos), each identified by a tenant UUID:

  • Mandatory tenant scoping. Every tenant-scoped query goes through a Mongoose plugin that filters and stamps the tenant automatically. There is no hand-rolled tenant filter to forget.
  • Per-tenant database routing. A tenant can carry its own MongoDB URI: its high-traffic collections (players, bets, wallet transactions, sessions) are then answered by its own server, while shared collections (tenants, roles, the sports catalog, settlement facts) stay on the platform database. Big operators get isolation; small ones share infrastructure.
  • White-label everything: the site renders each operator's published content on the operator's own domain from one deployment, and the widget bundle is configuration-agnostic — one build serves every tenant.

The casino owns the player​

The operator authenticates its players, holds their balance and verifies who they are. The platform receives players and takes bets: it never issues a credential, never holds money and never asks for a document.

That is one decision, not a setting. Auth and wallet are each a port with one adapter, both pointed at the operator: the API validates a player's bearer by calling the operator's own profile endpoint, and every movement — stake, payout, refund, cashout — is a call to the operator's transaction endpoint. The platform keeps its own ledger of what it asked for and what came back, which is what makes a movement idempotent and what a player's history reads from.

Data flow: the feed decides nothing about money​

LSports (RabbitMQ) ──► feed ──► MongoDB ──► api ──► players
│ │
│ ├─ fixtures / events (catalog, feed-owned)
│ └─ settlement_facts (facts, feed-recorded)
└─ never touches a wallet
  • The feed consumes, normalizes and persists: it writes the catalog and records settlement as facts. It never touches a wallet — a data provider decides nothing about money.
  • The api applies those facts to wallets (settlement, cashout), and serves every reader from the persisted catalog. It never connects to the provider — which is exactly what keeps it horizontally scalable.

Authorization: capabilities, not booleans​

Back-office access is capability-based. Every privileged action is a named capability; roles bundle capabilities and inherit from one another; grants can never exceed what the granting user holds. The capability catalog is generated at build time by scanning the code for @RequiresCapability decorations and synced at boot — the catalog cannot drift from the handlers that enforce it. Five roles ship seeded, in two chains (platform staff and operator staff); custom roles are created in the back-office.

Admin identity is JWT-based and belongs to the back-office alone: the API enforces no capability of its own, because everything a back-office principal decides is decided in the back-office.

Object storage​

One auto-provisioned S3 bucket whose prefixes are the access levels: media, content and assets. Uploads and downloads go through presigned URLs; MIME types are verified server-side. Works against MinIO in development and any S3-compatible service in production.

Operational guarantees​

  • The compose stack deliberately runs no database in production — the platform is one concern, the database another; they meet through a connection string.
  • Deploys follow the push: each environment tracks its branch and rebuilds on every push to it. The full test + build suite runs before the push, not after.
  • The platform starts empty: the first administrator is created by the back-office onboarding screen on first boot. No credentials ever travel through configuration.