Skip to content

Local development setup ​

This page explains how to run TodoAI locally for development.

Prerequisites ​

  • Node.js 20+ in PATH
  • npm 10+ or bun
  • MongoDB — local install, Docker, or Atlas
  • An EVM-compatible wallet (MetaMask, Coinbase Wallet, etc.)

1. Clone and install ​

bash
git clone https://github.com/totodo/quantokx.git
cd quantokx
npm install
npm run postinstall  # runs npx prisma generate automatically

2. Configure environment ​

bash
cp .env.example .env.local

Key fields in .env.local:

env
# MongoDB
DATABASE_URL="mongodb://127.0.0.1:27017/quantokx_dev"

# AI reasoning / DSL generation
API_URL=https://api.siliconflow.cn/v1/chat/completions
API_KEY=sk-xxx
AI_MODEL_NAME=Pro/deepseek-ai/DeepSeek-V3

# Admin wallet (for subscription features)
ADMIN_WALLET_ADDRESS=0x...

# OKX defaults (optional — real trades use per-user keys)
OKX_API_KEY=...
OKX_SECRET=...
OKX_PASSWORD=...
NEXT_PUBLIC_TRADING_MODE=demo

Required in production: ENCRYPTION_KEY and JWT_SECRET must be generated with openssl rand -hex 32 and must be different from each other. See Encryption key rotation.

3. Start MongoDB ​

Pick one:

bash
# Docker
docker run -d --name quantokx-mongo -p 27017:27017 mongo:7

# Local install
brew install mongodb-community && brew services start mongodb-community

On the first dev server boot, Prisma will auto-create the collections (no manual prisma db push needed).

4. Start the dev server ​

bash
npm run dev
# → http://localhost:3000

Once up:

  • Home http://localhost:3000/ — Dashboard
  • /strategy, /backtest, /trade

5. Start the engine scheduler (optional, for production) ​

The engine does not run automatically in local dev. To make it tick every 30s like production:

bash
DRY_RUN=1 npx tsx scripts/cron-tick.ts

DRY_RUN=1 makes it only log, not place orders. Remove it once the wiring checks out.

Common commands ​

bash
npm run dev          # Dev server (port 3000)
npm run build        # Production build
npm run start        # Production runtime (port 3001)
npm run lint         # ESLint
npm run test         # Vitest watch
npm run test:run     # Vitest single run
npx tsc --noEmit     # Type check
npx prisma generate  # Regenerate Prisma client

Encryption key rotation ​

ENCRYPTION_KEY encrypts users' exchange API keys at rest. Do not change it without first running the migration script — already-stored ciphertext will become undecryptable.

Correct rotation flow:

bash
# 1. Update ENCRYPTION_KEY in .env.production to the new value
# 2. Run migration (safe to run while live, no downtime):
npx tsx scripts/migrate-encryption.ts --old-key="<previous key>"
# 3. After "DONE succeeded=N failed=0" appears, restart the service

The migration script is idempotent and batched — safe to re-run, only re-encrypts records not yet at the current version.

Production deployment (VPS) ​

Full systemd deployment is documented in INSTALLATION.md — reverse proxy, SSL, scheduler, backup strategy.

TodoAI · Turn trading ideas into automated strategies