KnightArena is a modern chess platform built with Next.js, Prisma, NextAuth, and Socket.IO. It supports AI play, online real-time multiplayer, friend challenges, and PGN/FEN analysis.
- Play vs AI with
easy,medium, andharddifficulty modes - Online quick matchmaking with live board sync
- Private invites and friend challenges
- User accounts (sign up / sign in)
- Analysis board with:
- FEN import
- PGN import (paste or
.pgnfile) - PGN export
- Move navigation (first/prev/next/last)
- Time controls and game clocks
- Multiple board themes
- Next.js App Router
- React + TypeScript
- Tailwind CSS
- Prisma ORM + SQLite
- NextAuth (credentials auth)
- Socket.IO (real-time gameplay)
- chess.js (chess rules and move generation)
app/— pages, components, API routesapp/lib/— game logic, AI, socket client, auth, prisma clientapp/components/— board/UI componentsapp/online/— online multiplayer pagesapp/analysis/— analysis board pageprisma/schema.prisma— database schemaserver.ts— custom Next + Socket.IO server
- Node.js 20+
- npm 10+
Create a .env file in the project root:
DATABASE_URL="file:./prisma/dev.db"
NEXTAUTH_SECRET="your-secret-key"
NEXTAUTH_URL="http://localhost:3000"npm installnpx prisma generate
npx prisma migrate dev --name initFor online multiplayer, use the custom server:
npm run dev:serverIf you run only npm run dev, Socket.IO multiplayer will not behave correctly.
Open: http://localhost:3000
This app uses a custom persistent Socket.IO server (server.ts).
For production, deploy as two services:
- Vercel: Next.js frontend/API/auth
- Railway/Render/Fly: realtime Socket.IO server
Use the full checklist in DEPLOYMENT.md.
npm run dev— Next.js dev server onlynpm run dev:server— custom server (server.ts) with Socket.IO + Nextnpm run build— production buildnpm run start— start production buildnpm run start:server— production custom server with tsx loadernpm run lint— lint projectnpm run db:push— Prisma schema pushnpm run db:studio— open Prisma Studio
- Two players must be signed in with different accounts.
- Quick match pairs by:
- same time control
- rating window that expands over wait time
- Friend challenge works through
/friends.
- Export PGN from a finished/ongoing game
- Open
/analysis - Import PGN via paste or
.pgnupload - Review moves and positions
- Export updated PGN if needed
- Ensure both users selected the same time control
- Ensure two different accounts are used
- Ensure app is running with
npm run dev:server
Set NEXTAUTH_URL in .env to your active host (usually http://localhost:3000).
Run:
npx prisma generateThen restart TypeScript server/IDE if needed.
- Persistent active-game state using Redis
- Distributed socket scaling
- Game history page (
My Games) - Engine analysis lines (depth/eval)
Built as a full-featured chess demo with production-style architecture.