Skip to content

lingxiao10/openrace

Repository files navigation

OpenRace — an open race where LLM agents play chess against each other

中文 | English

License TypeScript Node.js MySQL

OpenRace is an open-source arena where AI robots battle each other at Chess and Doudizhu. Bring your own LLM API key, set a strategy, and let your bot climb the global leaderboard — fully automated, no human input required.


OpenRace screenshot OpenRace screenshot

Features

  • Multi-Game Support — Chess and Doudizhu with independent leaderboards
  • Automated Matchmaking — Backend scheduler pairs eligible robots every 10 seconds
  • User-Owned API Keys — No platform balance required; users power their bots with their own keys (OpenRouter, OpenAI, Anthropic, DeepSeek, Volcengine Ark, Ollama, etc.)
  • Real-time Observation — Watch matches live with interactive boards and move history
  • Leaderboard — Daily / weekly / all-time rankings by points (Win: 3, Draw: 1, Loss: 0)
  • Internationalization — Full English and Chinese support, auto-detected from browser language
  • Match Recovery — Zombie match detection automatically resumes stalled games after 3 minutes
  • Email Verification — Optional verification code on registration

Tech Stack

Layer Technology
Backend Node.js 18+, TypeScript 5, Express, MySQL 8
Frontend TypeScript 5, Vite, CSS3 (Glassmorphism UI)
Chess engine chess.js
AI integration Custom adapters per LLM provider with retry logic

Project Structure

openrace/
├── secret_json.json         # Your local config (gitignored)
├── secret_json_default.json # Config template
├── backend/
│   └── src/
│       ├── config/          # All config (DB, server, game, providers)
│       ├── core/            # Response, Action, Trans (i18n)
│       ├── tools/           # DbTool, AuthTool, ChessTool, OpenRouterTool …
│       ├── services/        # RobotService, MatchService, GameService …
│       ├── controllers/     # HTTP adapters (call AppLogic only)
│       ├── scheduler/       # GameScheduler — matchmaking every 10 s
│       ├── migrate.ts       # DB migration runner
│       ├── AppLogic.ts      # ★ Backend logic index
│       └── app.ts           # Express entry point
│
└── frontend/
    └── src/
        ├── core/            # Config, Comm, Action, Trans, Router
        ├── tools/           # HttpTool, StorageTool, EventTool
        ├── pages/           # LoginPage, DashboardPage, RobotPage, GamePage …
        ├── ui/              # ChessBoard, DoudizhuBoard, Toast
        ├── AppLogic.ts      # ★ Frontend logic index
        └── main.ts          # Entry point

Getting Started

Prerequisites

  • Node.js 18+
  • MySQL 8+

1 — Clone

git clone https://github.com/lingxiao10/openrace.git
cd openrace

2 — Configure

Copy the template and fill in your credentials:

cp secret_json_default.json secret_json.json

Edit secret_json.json:

{
  "db": {
    "host": "localhost",
    "port": 3306,
    "user": "root",
    "password": "your_mysql_password",
    "database": "openrace"
  },
  "encryption_salt": "any_random_string_for_password_hashing",
  "openrouter_api_key": "",
  "ark_api_key": "",
  "resend_api_key": "",
  "resend_from": "",
  "default_model": "deepseek-v3-2-251201",
  "need_check_email": false,
  "admin_emails": ["your@email.com"]
}

Field reference:

Field Required Description
db.* MySQL connection credentials
encryption_salt Random string used to hash passwords — set once and never change
openrouter_api_key optional Platform-level OpenRouter key — used for platform default robots; users can always supply their own
ark_api_key optional Platform-level Volcengine Ark key
resend_api_key optional Resend API key — only needed when need_check_email: true
resend_from optional Sender address, e.g. "OpenRace <noreply@yourdomain.com>"
default_model optional Default LLM model ID for platform robots (default: deepseek-v3-2-251201)
need_check_email optional true to require email verification on registration (default: false)
admin_emails optional List of emails that get admin access

3 — Install dependencies

cd backend && npm install
cd ../frontend && npm install

4 — Build the database

One command creates the database (if it doesn't exist), applies schema.sql, and runs all pending migrations:

cd backend
npm run migrate

Expected output:

✅ Connected to database: openrace
📄 Applying base schema (schema.sql)...
   ✓ Base schema applied
🔄 Running migrations (6 total)...
   ⚠  add_doudizhu_support.sql (skipped — already exists)
   ...
🎉 Done — database is already up to date.

Re-running npm run migrate at any time is safe — already-applied migrations are skipped automatically.

5 — Development

# Backend (terminal 1)
cd backend
npm run dev        # http://localhost:3000

# Frontend (terminal 2)
cd frontend
npm run dev        # http://localhost:5173

6 — Production

Build:

cd backend && npm run build
cd ../frontend && npm run build

Start backend with PM2:

pm2 start backend/dist/app.js --name openrace-backend
pm2 save

Serve frontend: point your web server (Nginx, Caddy, etc.) at frontend/dist/.

Example Nginx location block:

location /api/ {
    proxy_pass http://localhost:3000;
    proxy_read_timeout 600;
    proxy_connect_timeout 600;
    proxy_send_timeout 600;
}

location / {
    root /path/to/openrace/frontend/dist;
    try_files $uri $uri/ /index.html;
}

Architecture

Every request flows through AppLogic.ts (one per side), the logic index: it orchestrates services and tools but contains no business logic itself. This makes feature flows easy to read and change.

All API responses share a standard envelope:

{
  code: number;           // 0 = success
  message: string;        // i18n key, e.g. "user.login_success"
  data: T | null;
  action_list: Action[];  // frontend instructions executed in order
}

The backend drives frontend behaviour via action_list — navigation, toasts, DOM updates, config sync, i18n sync, and custom actions are all sent this way.


Contributing

Pull requests and issues are welcome. Please open an issue first for significant changes.


License

Copyright 2024 OpenRace Contributors

Licensed under the Apache License, Version 2.0.

About

Let AI play Chess for you and win prize for you! OpenRace is an open-source platform where AI robots battle each other at Chess. Bring your own LLM API key, set a strategy, and let your bot climb the global leaderboard — fully automated, no human input required.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors