codetrail

Maintaining CodeTrail

A guide for maintainers: how the project fits together, how changes reach codearena.co, what to check before merging, and what to do when something breaks. Contributors should start with CONTRIBUTING.md.

The shape of it

Part Where Notes
Backend backend/ Node, Express, Socket.io, SQLite. server.js holds battles, matchmaking and sockets; routes/ the REST API; db.js schema, migrations and queries.
Code runner backend/arena/ Builds a program from a player’s code plus a small driver, runs it on Judge0, compares results. One driver per language in runner/harness.js.
Problems backend/arena/problems/ One JSON file per problem, with JavaScript, Python and Java reference solutions in arena/solutions/.
Frontend frontend/ Next.js, React, Tailwind, Monaco.
Shared shared/ Code both sides use, such as fair-use limits (codearenaProductMode.js).

How a change reaches codearena.co

  1. A pull request runs CI (.github/workflows/ci.yml):
    • the publish boundary check;
    • backend: problem validation, a boot and health probe, and every test;
    • frontend: lint, tests and a production build.
    • browser flows: practice, private and bot battles, matchmaking, and page rendering against an isolated local database without production credentials.
  2. Merging to main deploys automatically:
    • backend on Railway, using railway.toml at the repo root. Keep the service’s Root Directory empty: the build and start commands already point into backend/.
    • frontend on Vercel, with Root Directory frontend.
  3. Railway waits for GET /health to pass before switching traffic, so a build that crashes on boot never replaces the running version.

main is production. Merge only what you would deploy.

Before you merge a pull request

Costs and safety limits

Application quotas limit normal use. Configure provider spending limits separately; application quotas do not protect against a stolen provider key.

Service Used for Cap
Judge0 (RapidAPI) Running player code CODEARENA_GLOBAL_DAILY_CODE_EXECUTION_LIMIT runs per day, plus per-player daily limits
Anthropic Claude models in prompt battles and other AI features Workspace spend limit, plus CODEARENA_GLOBAL_DAILY_PROMPT_EVALUATION_LIMIT
OpenAI, Gemini, DeepSeek Extra prompt battle models Prepaid credit or free tier; each model hides itself when its key is unset
Resend Email Key restricted to the codearena.co domain

Pricier models count more against the daily prompt budget (Opus 5, Sonnet 3, the rest 1), in backend/services/promptBattleRunner.js.

Hosted deployment isolation

The local browser suite does not verify production email delivery, provider credentials or hosting access. Before announcing a release, separately verify a new account’s registration, email verification, login and code execution on the deployed site.

Provider maintenance

Deploy support for these controls before enabling them:

These switches stop normal application calls; they do not protect credentials still present in the process from a server compromise. Remove affected provider secrets from the deployment and restart it to remove runtime access. Revoke old keys at the provider after all legitimate consumers have migrated. Old deployments may retain configuration, so do not roll back to a deployment containing retired credentials.

To restore service, configure dedicated provider credentials, remove the maintenance switches, redeploy, and verify a code submission and an avatar change.

When something breaks

Moderation

Integrity implementation boundary

The public battle-integrity implementation is developed independently for this project’s players. Do not import private assessment detection engines, proctoring modules, edit-trace analysis, calibration fixtures, scoring thresholds or their tests from another product. The publish guard checks known private module names and identifiers, including copies under renamed paths. Human review is still required; this is not a general detector of copied code.

Generic UI state, account security and community moderation can remain public. New community-developed integrity techniques are welcome when contributors have the right to publish them. Validate detection and false-positive behavior before enabling them for players.

The project’s license governs community contributions. Do not assume maintaining the project grants additional rights to incorporate others’ contributions into proprietary software. Before any such reuse, record the source revision, authors and dependencies, and obtain a legal review of the applicable licenses and any separate permissions. No contributor has granted extra rights merely because this guide describes that review.

Act on reports promptly. Remove content that breaks the Terms.

Known quirks

Good next things

Running the checks locally

cd backend && npm test && npm run validate:problems
cd frontend && npm run lint && npm test
node scripts/check-boundary.js