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
git clone https://github.com/totodo/quantokx.git
cd quantokx
npm install
npm run postinstall # runs npx prisma generate automatically2. Configure environment
cp .env.example .env.localKey fields in .env.local:
# 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=demoRequired in production:
ENCRYPTION_KEYandJWT_SECRETmust be generated withopenssl rand -hex 32and must be different from each other. See Encryption key rotation.
3. Start MongoDB
Pick one:
# Docker
docker run -d --name quantokx-mongo -p 27017:27017 mongo:7
# Local install
brew install mongodb-community && brew services start mongodb-communityOn the first dev server boot, Prisma will auto-create the collections (no manual prisma db push needed).
4. Start the dev server
npm run dev
# → http://localhost:3000Once 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:
DRY_RUN=1 npx tsx scripts/cron-tick.tsDRY_RUN=1 makes it only log, not place orders. Remove it once the wiring checks out.
Common commands
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 clientEncryption 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:
# 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 serviceThe 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.