How okeson453/crash works
Purpose and entry points
This is a TypeScript/Node.js platform that automates observation and controlled participation in BC.Game Crash rounds, with operational control, accounting, analytics, and multi-tenant platform features. Runtime composition begins at src/index.ts, with dependency wiring in src/app/composition.ts and upgrade-specific wiring in src/app/spec-upgrade-wiring.ts. Configuration is loaded and validated before services start via src/config/loader.ts and src/config/schema.ts.
Control plane and lifecycle orchestration
The core runtime is an event-driven orchestrator governed by a deterministic state machine. src/core/orchestrator.ts coordinates lifecycle actions; src/core/state-machine/machine.ts and src/core/state-machine/guards.ts enforce permitted transitions and fail-safe conditions. src/core/session-supervisor.ts, recovery management, emergency stop, and instance locking isolate active sessions and prevent unsafe concurrent operation.
Eventing, jobs, and durability boundary
Domain components communicate through the event bus rather than direct control coupling: src/core/event-bus/bus.ts, src/core/event-bus/events.ts, and src/core/event-bus/outbox-publisher.ts. The persistent outbox/log boundary is backed by PostgreSQL, while Redis supports stream-based event transport and work dispatch in src/core/event-bus/streams/redis-streams-bus.ts and src/core/job-queue/index.ts. This supports recovery and deferred worker execution.
Game/browser acquisition boundary
Game state is acquired through adapters and browser automation. src/game/adapter.ts and src/game/adapters/aggregator.ts combine API, DOM, and WebSocket observation paths; src/game/observer.ts turns these into round-level signals. Browser session ownership, login, health, profile consistency, and anti-detection behavior sit behind src/browser/manager.ts, src/browser/session.ts, and src/browser/evasion/index.ts. This boundary depends on a Playwright/Chromium browser runtime, proxies, and protocol interception.
Decision, prediction, and risk gates
Observed rounds feed opportunity ranking, prediction, and policy evaluation before any execution. src/opportunity/ranker.ts, src/prediction/prediction-engine.ts, and src/prediction/acie/engine.ts provide signal and model paths. The decision boundary is src/decision/decision-engine.ts; financial/risk constraints are enforced by src/betting/risk-engine.ts, src/risk/velocity-controller.ts, and src/risk-engine/drawdown.ts. The system is designed to pause or observe when confidence, limits, or state integrity are insufficient.
Bet execution, settlement, and ledger integrity
Approved actions pass through src/betting/betting-coordinator.ts, src/betting/executor.ts, and src/betting/cashout.ts; idempotency and confirmation guard side effects. Post-round truth is resolved by src/settlement/authoritative-settlement-engine.ts, drift controls, and reconciliation. Financial records are maintained through src/ledger/balance-tracker.ts, src/ledger/daily-entries.ts, and src/ledger/reconciliation.ts, with database migrations including daily caps, audit logs, financial integrity, and double-entry settlement in migrations/011_terms_stake_daily.sql, migrations/013_financial_integrity.sql, and migrations/017_double_entry_settlement.sql.
Operator and tenant platform interfaces
Telegram is the primary operational interface: src/telegram/gateway.ts, src/telegram/router.ts, and src/telegram/commands/control.ts authenticate and route operator commands and notifications. A separate Next.js admin dashboard resides in admin-dashboard/app/page.tsx, using a proxy route at admin-dashboard/app/api/proxy/route.ts. Tenant provisioning/control, billing, subscriptions, and payments are centralized in src/platform/control-plane.ts, src/platform/tenant-manager.ts, and src/platform/billing/subscription-service.ts; external payment integrations include Stripe and Paystack.
Persistence, operations, and observability
PostgreSQL 15+ with TimescaleDB is the durable system of record; Redis is the cache/stream infrastructure. Access is encapsulated in src/persistence/client.ts, src/persistence/transaction.ts, and repositories. Docker Compose defines local, production, and tenant deployments in docker/docker-compose.yml, docker/docker-compose.prod.yml, and docker/docker-compose.tenant.yml. Metrics, logs, tracing, alerts, and health checks are implemented under src/observability/, with Prometheus and Grafana provisioning under docker/prometheus/prometheus.yml and docker/grafana/.
Main entry points: orchestrator.ts Lifecycle orchestrator · bus.ts Domain event bus · observer.ts Round observer · decision-engine.ts Decision engine
Components 22
Core Runtime
- Runtime entry
src/index.ts - Composition root · Includes upgrade-specific runtime wiring.
src/app/composition.ts - Validated configuration
src/config/loader.ts - Lifecycle orchestrator · Coordinates controlled round participation.
src/core/orchestrator.ts - Safety state machine · Guards permitted transitions and fail-safe states.
src/core/state-machine/machine.ts - Domain event bus · Decouples domain control flow and publishes durable events.
src/core/event-bus/bus.ts - Deferred jobs
src/core/job-queue/index.ts
Game Acquisition
- Round observer · Normalizes API, DOM, and WebSocket observations into rounds.
src/game/observer.ts - Game adapters
src/game/adapters/aggregator.ts - Browser session boundary · Owns login, browser health, profiles, and evasion.
src/browser/manager.ts
Decision & Execution
- Decision engine
src/decision/decision-engine.ts - Prediction engine
src/prediction/prediction-engine.ts - Risk gates · Enforces limits, velocity, and drawdown constraints.
src/betting/risk-engine.ts - Betting coordinator · Applies idempotent execution and cashout control.
src/betting/betting-coordinator.ts - Authoritative settlement
src/settlement/authoritative-settlement-engine.ts - Financial ledger · Tracks balances, daily entries, and reconciliation.
src/ledger/balance-tracker.ts
Operations & Platform
- Telegram operations · Authenticates commands and sends operational notifications.
src/telegram/gateway.ts - Tenant control plane · Centralizes tenant provisioning, billing, and subscriptions.
src/platform/control-plane.ts - Admin dashboard
admin-dashboard/app/page.tsx
Durability & Infrastructure
- PostgreSQL + TimescaleDB · Stores outbox, audit, settlement, and financial records.
src/persistence/client.ts - Redis streams · Provides stream transport and work dispatch.
src/core/event-bus/streams/redis-streams-bus.ts - Observability
Connections 23
- Runtime entry → Validated configuration: loads
- Runtime entry → Composition root: starts
- Composition root → Lifecycle orchestrator: wires
- Lifecycle orchestrator → Safety state machine: governed by
- Lifecycle orchestrator → Domain event bus: publishes and consumes
- Domain event bus → PostgreSQL + TimescaleDB: durable outbox/log
- Domain event bus → Redis streams: stream transport
- Redis streams → Deferred jobs: dispatches
- Lifecycle orchestrator → Round observer: controls observation
- Round observer → Game adapters: uses
- Game adapters → Browser session boundary: acquires via
- Round observer → Decision engine: round signals
- Prediction engine → Decision engine: confidence signals
- Decision engine → Risk gates: proposed action
- Risk gates → Betting coordinator: approved actions
- Betting coordinator → Authoritative settlement: execution outcome
- Authoritative settlement → Financial ledger: posts settled truth
- Financial ledger → PostgreSQL + TimescaleDB: persists
- Telegram operations → Lifecycle orchestrator: operator commands
- Lifecycle orchestrator → Telegram operations: notifications
- Admin dashboard → Tenant control plane: admin control
- Tenant control plane → PostgreSQL + TimescaleDB: tenant and billing data
- Lifecycle orchestrator → Observability: telemetry and health