Chronos is the backend engine for a multiplayer online card game inspired by mythology and classic battle card mechanics (inspired by Dracomania). This service handles all game rules, player logic, turn rotation, card resolution, and battle flow.
- NestJS (TypeScript)
- REST API + Swagger
- PostgreSQL + Prisma ORM
- Docker-ready
- Create a
.envfile using the variables listed in the Docker section. - Install dependencies with your preferred package manager, for example
npm install. - Start the development server with
npm run start:devand access the API athttp://localhost:3053.
- Create and manage a match between 2 players
- Track game state, logs, turns, HP, and player hands
- Each player starts with 5 random cards in hand
- Only cards in hand can be played
- REST endpoints for game actions
- Swagger docs at
/api
CHRONOS_PORT=3053
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=chronos
DATABASE_URL=postgresql://postgres:postgres@db:5432/chronosdocker compose up -d db chronoshttp://localhost:3053
docker compose up -d db chronos
docker compose exec chronos sh -lc 'npx prisma migrate dev --name add-new-game-mode'In case of 'We found changes that cannot be executed':
docker compose exec chronos sh -lc 'npx prisma migrate dev --name add_auth_player_role --create-only'
docker compose exec chronos sh -lc 'npx prisma migrate reset --force --skip-seed'Then, generate files:
docker compose exec chronos sh -lc 'npx prisma generate'docker exec -it chronos-backend npx prisma studio --port 5555 --hostname 0.0.0.0 --browser nonessh -L 5555:127.0.0.1:5555 user@hostOpen: http://localhost:5555
Health
curl -k http://localhost:3053/healthStart a new game
curl -k -X POST http://localhost:3053/game/startPlay a card
curl -k -X POST http://localhost:3053/game/play-card \
-H "Content-Type: application/json" \
-d '{"gameId":"550e8400-e29b-41d4-a716-446655440000","player":"A","card":"fireball"}'http://localhost:3053/api
docker compose exec chronos sh -lc 'npx prisma migrate reset --force'
docker compose exec chronos sh -lc 'npx ts-node prisma/seed.ts'