This document provides a exhaustive, step-by-step roadmap for rebuilding the ArenaX backend in the /server directory. It deconstructs the system into 40+ atomic GitHub issues to ensure maximum clarity and parallel development.
- Work Directory:
/server - Description: Implement a robust logging system using
winstonorpino. - Tasks:
- Setup Winston logger with different levels (info, warn, error).
- Implement a request-id middleware to trace logs across a single request.
- Configure stream rotation for log files.
- Work Directory:
/server - Description: Standardize API error responses.
- Tasks:
- Create a
BaseErrorclass and specialized subclasses (e.g.,NotFoundError,ValidationError). - Implement a global error handler middleware that masks internal details in production.
- Add Sentry or OpenTelemetry hooks for error monitoring.
- Create a
- Work Directory:
/server - Description: Basic security layers for the public API.
- Tasks:
- Configure
helmet.jswith strict CSP and HSTS. - Implement
express-rate-limiton sensitive routes (Login, Register). - Configure CORS for specific ArenaX domains.
- Configure
- Work Directory:
/server - Description: Base configuration for authentication strategies.
- Tasks:
- Setup Passport.js (or custom logic) with JWT strategy.
- Implementation of Secret/Public key management for token signing.
- Work Directory:
/server - Description: Create the registration endpoint with strict data normalization.
- Tasks:
- lowerCase email normalization during storage.
- Password hashing with
bcrypt(12 rounds). - Auto-generation of a unique
usernameif not provided.
- Work Directory:
/server - Description: Implement secure login with short-lived access tokens and long-lived refresh tokens.
- Tasks:
- Creation of
accessToken(15m) andrefreshToken(7d). - Implement
refreshTokenrotation (detect reuse and invalidate family). -
POST /auth/loginandPOST /auth/logouthandlers.
- Creation of
- Work Directory:
/server - Description: Role-based access control for ArenaX features.
- Tasks:
- Create
restrictTo(roles: string[])middleware. - Protect
/adminand/governanceroutes.
- Create
- Work Directory:
/server - Description: Manage user-level metadata.
- Tasks:
- Implementation of
GET /profiles/:username. -
PATCH /profiles/mewith Zod validation for social links and bio.
- Implementation of
- Work Directory:
/server - Description: Configure the DB for high-precision financial data.
- Tasks:
- Configure Prisma with
Decimalfor XLM, USDC, and NGN balances. - Define
WalletTransactionhistory model withstatus(PENDING, SUCCESS, FAILED).
- Configure Prisma with
- Work Directory:
/server - Description: Basic ledger movements within the platform.
- Tasks:
- Implement
addBalanceanddeductBalancemethods with ACID transactions. - Create a
getOrCreateWallet(userId)factory.
- Implement
- Work Directory:
/server - Description: Lock funds for matches and tournaments.
- Tasks:
- Implement
lockFundsToEscrow(userId, amount, matchId)logic. - Implement
releaseEscrow(matchId)andslashEscrow(matchId)methods.
- Implement
- Work Directory:
/server - Description: Connect Nigerian Naira (NGN) rails.
- Tasks:
- Implementation of
PaystackService.verifyTransaction(ref). - Secure Webhook handler for
charge.success.
- Implementation of
- Work Directory:
/server - Description: Push balance updates to the frontend instantly.
- Tasks:
- Setup Redis Pub/Sub for
wallet:{userId}:update. - Implement balance change observer in the
WalletService.
- Setup Redis Pub/Sub for
- Work Directory:
/server - Description: Programmable account creation on Stellar.
- Tasks:
- Implement utility for
Keypair.random(). - Create
StellarService.registerUserWallet(userId).
- Implement utility for
- Work Directory:
/server - Description: Secure storage of Stellar secret keys.
- Tasks:
- Implement
EncryptionServiceusingcrypto. -
encryptSecret(plain)anddecryptSecret(cipher).
- Implement
- Work Directory:
/server - Description: Base layer for sending Stellar transactions.
- Tasks:
- Build a generic
submitTransaction(tx)wrapper. - Log every
tx_hashto theBlockchainTransactiontable immediately.
- Build a generic
- Work Directory:
/server - Description: Interactive layer with the Soroban network.
- Tasks:
- Setup
SorobanRpc.Serverwith failover endpoints. - Implement a health check utility to verify RPC connectivity.
- Setup
- Work Directory:
/server - Description: Utility for building Soroban contract calls.
- Tasks:
- Implement
buildInvokeXDR(contractId, function, args). - Data-type mapping for
SCVal(Address, Symbol, Vec).
- Implement
- Work Directory:
/server - Description: Predict resource consumption before submission.
- Tasks:
- Implementation of
simulateTransaction(tx). - Logic for increasing
resourceFeesbased on simulation results.
- Implementation of
- Work Directory:
/server - Description: Reliable monitoring for transaction finality.
- Tasks:
- Implement a monitoring worker that polls
getTransaction. - Use exponential backoff (1s, 2s, 4s...) logic.
- Implement a monitoring worker that polls
- Work Directory:
/server - Description: Implement Sponsored Transactions for gasless UX.
- Tasks:
- Logic for backend signature as Source/FeePayer.
- Dual signature reassembly for Soroban transactions.
- Work Directory:
/server - Description: High-performance matchmaking storage.
- Tasks:
- Design Redis Sets structure for
queue:elo:{group}. - Implement logic to add/remove players from the queue.
- Design Redis Sets structure for
- Work Directory:
/server - Description: The core logic that matches two players.
- Tasks:
- Create a background worker that scans Redis sets for pairs.
- Handle "Stale Player" cleanup from the queue.
- Work Directory:
/server - Description: Dynamic matchmaking that expands search as wait time grows.
- Tasks:
- Implement
wait_timebased elo delta adjustment. - Log matchmaking metrics for performance tuning.
- Implement
- Work Directory:
/server - Description: Core rating logic.
- Tasks:
- Implement
calculateRating(ratingA, ratingB, outcome). - Create
EloHistoryrecords for auditability.
- Implement
- Work Directory:
/server - Description: Lifecycle of a single game match.
- Tasks:
- Enforce state transitions:
PENDING->ACTIVE->SETTLED. - Prevent actions in invalid states (e.g., reporting a finished match).
- Enforce state transitions:
- Work Directory:
/server - Description: Multi-player result verification.
- Tasks:
- Implement
POST /matches/:id/report. - Logic to detect when Player A and Player B results conflict.
- Implement
- Work Directory:
/server - Description: Handle inactive players in active matches.
- Tasks:
- Create a "Reaper" service that marks matches as
FORFEITafter 24h of no reports.
- Create a "Reaper" service that marks matches as
- Work Directory:
/server - Description: Setup brackets for new tournaments.
- Tasks:
- Implement
seedTournament(participants)logic. - Create initial
Matchrecords for Round 1.
- Implement
- Work Directory:
/server - Description: Move winners forward in the bracket.
- Tasks:
- Implement checking logic: "Have all matches in Round X finished?".
- Generate Round X+1 matches dynamically.
- Work Directory:
/server - Description: Ensure rewards are only paid once.
- Tasks:
- Use
match_idas an idempotency key in thePayoutstable. - Implement "Check-Before-Pay" logic.
- Use
- Work Directory:
/server - Description: Split the prize pool among top N players.
- Tasks:
- Implement ratio-based distribution (e.g., 50% to 1st, 30% to 2nd).
- Handle fractional remainders with a platform fee "dust" collector.
- Work Directory:
/server - Description: Enable real-time duplex communication.
- Tasks:
- Setup Socket.io with JWT authentication midddleware.
- Handle connection/disconnection heartbeats.
- Work Directory:
/server - Description: Broadcast backend events to users.
- Tasks:
- Subscribe to Redis balance/match events.
- Dispatch
emitevents to specific User-Id rooms.
- Work Directory:
/server - Description: Background syncing from the chain.
- Tasks:
- Implement
fetchEvents(pagingToken)loop. - Persistent storage of the
lastPagingTokenin the database.
- Implement
- Work Directory:
/server - Description: Turn SCVal events into human-readable data.
- Tasks:
- Implement parser for
TournamentStarted,MatchSettled, etc. - Map decoded data to Prisma model updates.
- Implement parser for
- Work Directory:
/server - Description: Manage multisig governance flow.
- Tasks:
- Define proposal statuses:
DRAFT,VOTING,APPROVED,EXECUTED. - Secure
approveendpoint restricted to Governance roles.
- Define proposal statuses:
- Work Directory:
/server - Description: Track user conduct.
- Tasks:
- Implement increment/decrement triggers for good/bad behavior.
- Logic for reputation-based cooldowns on matchmaking.
- Work Directory:
/server - Description: Admin tools for fixing match conflicts.
- Tasks:
- Implement
AdminOverrideMatch(matchId, winnerId)with full audit trail.
- Implement