NestJS backend for the Makayla Jam game.
- Clone the repository
- Install dependencies:
npm install - Copy
.env.exampleto.envand configure variables - Start MongoDB:
docker-compose up -d - Run the application:
npm run start:dev
NODE_ENV- Environment (development/production)PORT- Server port (default: 3000)MONGODB_URI- MongoDB connection stringJWT_SECRET- Secret for device JWT tokensJWT_EXPIRES_IN- JWT expiration timeADMIN_JWT_SECRET- Secret for admin JWT tokensADMIN_JWT_EXPIRES_IN- Admin JWT expiration timeTHROTTLE_LIMIT- Rate limit requests per TTLTHROTTLE_TTL- Rate limit time window in seconds
npm run start- Start production servernpm run start:dev- Start development server with watch modenpm run test- Run unit testsnpm run test:e2e- Run end-to-end testsnpm run lint- Lint codenpm run format- Format codenpm run seed- Seed database with sample datanpm run backup- Backup database
After starting the server, visit http://localhost:3000/api for Swagger documentation.
The application uses MongoDB with the following collections:
users- Player data and game statetransactions- Coin transaction historyitems- Shop itemsmissions- Mission definitions
- Authentication for device users and admins, with separate JWTs and refresh handling.
- Player progression covering coins, energy, multitap upgrades, and mission/social task flows.
- Economy with idempotent coin mutations logged to a ledger and consumable shop items.
- Redeem codes that can be created by admins, optionally pre-assigned to a user with gift metadata, and require admin confirmation before rewards are applied.
- Gifting between users via admin-managed gift records.
- Tournaments that cap entries at 10 players, track coins generated during the event, and compute winners from the leaderboard.
- Notifications for registering device tokens and dispatching messages from admin tools.
- Admin console endpoints for bans, analytics snapshots, and game-configuration storage.
The backend follows a modular structure with separate modules for authentication, users, shop, missions, leaderboard, gifting, redeem codes, tournaments, and notifications. All state-changing operations are idempotent using opId to prevent duplicate processing.
- Create – An admin creates a code with rewards, optional expiry/max uses, and optional assignment to a specific user plus gift context.
- Confirm – A user provides the code to an admin, who confirms it via the admin redeem endpoint; only after confirmation are rewards applied and the use recorded.
- Audit – Codes track confirmation status, assignment, and usage history to prevent unauthorized redemption.
- Enrollment – Up to 10 players can join an active tournament; additional join attempts are rejected once the cap is reached.
- Scoring – Clients submit coins-generated totals; higher coin totals overwrite a player’s previous best.
- Results – Leaderboards sort by coins generated to surface current placement and winners at event end.