Main backend API service for the CORE game website.
This NestJS service serves as the primary backend, handling:
- User authentication and management
- Team and event/tournament management
- Match results and statistics
- Database operations (PostgreSQL)
- RabbitMQ microservice communication
Use Node.js 26 or newer. TypeScript stays on the 6.0 release line because the Nest CLI, ts-jest, and typescript-eslint require its JavaScript compiler API.
Install pnpm:
corepack enable && corepack prepare pnpm@latest --activateor
brew install pnpm-
Install dependencies:
pnpm install
-
Set up environment variables:
cp .env.example .env
Edit
.env.localwith your configuration (see Environment Variables below). -
Run database migrations:
pnpm migration:run-local
-
Run development server:
pnpm start:dev
- Build:
pnpm build - Start:
pnpm start:prod
pnpm test runs the unit and HTTP tests. To also run the PostgreSQL session
race regression tests, provide SESSION_TEST_DATABASE_URL pointing at a test
PostgreSQL database. The suite creates and drops its own randomly named schema;
it needs permission to create schemas. CI runs these tests against PostgreSQL 17.
SESSION_TEST_DATABASE_URL=postgresql://postgres:session-tests@localhost:55439/postgres pnpm test --runInBandThe tests overlap rotation with logout, logout-all and reuse detection, and verify that concurrent refreshes share one successor and failed rotations roll back. They also overlap an old GitHub grant check with a new login to ensure the new session survives. They are skipped when the test database URL is absent.
DB_HOST- PostgreSQL hostDB_PORT- PostgreSQL portDB_USER- Database usernameDB_PASSWORD- Database passwordDB_NAME- Database nameDB_SCHEMA- Database schemaDB_URL- Alternative database connection URL overwrites the other database connection variablesDB_SSL_REQUIRED- Enable SSL connection (true/false)
RABBITMQ_URL- RabbitMQ connection URLAPI_SECRET_ENCRYPTION_KEY- Key for encrypting sensitive data
PORT- Server port (default: 4000)NODE_ENV- Environment (development/production)
- Generate:
pnpm migration:generate migration_nameCompares your current TypeScript entities with the database and automatically generates the necessary SQL (e.g., adding or removing columns). Use this for most schema changes. - Create:
pnpm migration:create migration_nameCreates an empty migration template. Use this only for manual SQL changes (e.g., seeding data, creating complex views, or custom indexes) that TypeORM cannot detect automatically. - Run:
pnpm migration:run-local(local) /pnpm migration:run(production) - Revert:
pnpm migration:revert-local(local) /pnpm migration:revert(production)
- Seed Users and Teams:
pnpm seed:users <eventId>Generates 90 users and 30 teams (3 members each) and assigns them to the specified event. This is useful for testing group phases and bracket logic. Each seeded team gets a simulated repository namedsim-<teamId>in READY state, so no repository is ever created for it. WhenNODE_ENVisdevelopment, github-service reports permission, lock, unlock and delete operations on these repositories as successful without calling GitHub, so closing submissions locks the seeded teams and the tournament can start.RANDOM_GAME_RESULTS=trueis required, because real matches cannot clonesim-*repositories. Tilt sets both.
-
Backfill campus names:
pnpm backfill:campus [--apply] [--all]Looks up every linked 42 account without a campus on the 42 intra API (/v2/users/:id) and stores its primary campus. Without--applyit only prints what would change;--allalso re-checks accounts that already have a campus. Set theDB_*variables of the target database and read the token without echoing it:read -rs FORTYTWO_ACCESS_TOKEN && export FORTYTWO_ACCESS_TOKEN pnpm backfill:campus # dry run pnpm backfill:campus --apply
An application token works:
curl -X POST https://api.intra.42.fr/oauth/token -d grant_type=client_credentials -d client_id=<uid> -d client_secret=<secret>. Requests are spaced to stay within the default limit of 2 per second, and the run stops at once if the token is rejected.
When running in development mode, Swagger documentation is available at:
http://localhost:4000/api
This service runs as both:
- REST API - HTTP endpoints for frontend communication
- Microservice - RabbitMQ message consumer for:
game_results- Match result processinggithub-service-results- GitHub operation results
- Go to GitHub → Settings → Developer settings → OAuth Apps
- Register a new OAuth app
- Set Authorization callback URL:
http://localhost:4000/auth/github/callback - Add Client ID and Secret to
.env.local
For testing account linking functionality:
- Go to 42 School → Settings → API → Applications
- Create a new application
- Set Redirect URI:
http://localhost:4000/auth/42/callback - Add Client ID and Client Secret to
.env.local