Skip to content

Bobagi/chronos

Repository files navigation

Chronos – Mythological Card Game Engine (Backend)

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.

🛠 Tech Stack

  • NestJS (TypeScript)
  • REST API + Swagger
  • PostgreSQL + Prisma ORM
  • Docker-ready

▶️ Run Locally (without Docker)

  1. Create a .env file using the variables listed in the Docker section.
  2. Install dependencies with your preferred package manager, for example npm install.
  3. Start the development server with npm run start:dev and access the API at http://localhost:3053.

📦 Features

  • 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

🚀 Run with Docker

1) .env (root)

CHRONOS_PORT=3053
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=chronos
DATABASE_URL=postgresql://postgres:postgres@db:5432/chronos

2) Start services

docker compose up -d db chronos

3) API base URL

http://localhost:3053

📜 Create Migration (exact commands)

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'

🗄 Prisma Studio (DB UI)

docker exec -it chronos-backend npx prisma studio --port 5555 --hostname 0.0.0.0 --browser none
ssh -L 5555:127.0.0.1:5555 user@host

Open: http://localhost:5555


🧪 Quick API Checks

Health

curl -k http://localhost:3053/health

Start a new game

curl -k -X POST http://localhost:3053/game/start

Play 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"}'

📘 Swagger

http://localhost:3053/api

🔄 Reset DB and Seed (optional)

docker compose exec chronos sh -lc 'npx prisma migrate reset --force'
docker compose exec chronos sh -lc 'npx ts-node prisma/seed.ts'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages