Skip to content

Online Chess Game API imitates major features in famous chess platforms.

Notifications You must be signed in to change notification settings

Mohab96/online-chess-game

Repository files navigation

Online Chess Game API

Introduction

The Online Chess Game API allows players to join chess games, make moves, invite other players to join games, and manage their ongoing matches. The API supports real-time interactions through WebSockets for instant game updates and HTTP endpoints for managing game states. Players can authenticate, manage their profiles, and track their game progress through this API.

Table of Contents

Features

  • Real-Time Gameplay: Experience instant game updates via WebSockets. ⚡️
  • Player Management: Authenticate, manage profiles, and track progress. 👤
  • Comprehensive Game Controls: Join games, make moves, and invite others. ♟️
  • Friends System: send and accept friend requests and view friends list. 🤝
  • API Documentation: Easily integrate with detailed API and WebSocket event documentation. 📚

Data Models

Data Models

Documentation

For a detailed API documentation for all API endpoints, please refer to this postman collection. Swagger API documentation is also available at http://localhost:3000/api-docs when you run the server correctly. You can also find documentation for all websocket events here the server emits and listens to.

Usage

If you want to run the server locally and just use it for testing purposes or for building a client, you can follow these steps:

First of all, you need to have docker installed on your machine. You can download it from here. You can check if docker is installed by running the following command:

docker -v

unless you prefer not to use docker, you can follow the steps in the Contributing section.

After you have docker installed, you can go on with these steps:

  1. Clone the repository
git clone https://github.com/Mohab96/online-chess-game.git
  1. Change directory to the project directory
cd online-chess-game
  1. Copy the .env.example file to .env
cp .env.example .env
  1. Start filling the environment variables in the .env file, you can go with the default values for testing purposes except for NODEMAILER_EMAIL and NODEMAILER_PASSWORD which you need to fill with your email and password to be able to send emails.
POSTGRES_USER=postgres # name of the postgres user
POSTGRES_PASSWORD=551258 # password for the postgres user
POSTGRES_DB=chess # name of the database
JWT_SECRET=secret # secret token used in validating JWTs
NODEMAILER_EMAIL=email used by nodemailer
NODEMAILER_PASSWORD=password used by nodemailer
  1. Run the following command to start the express server, PostgreSQL database, Prisma client, and the Redis server

If it is the fisrt time, you need to run the container with the --build flag to build the image first.

Make sure that ports 5432, 6379, and 3000 are not used by other services.

docker-compose up --build

If you have already built the image, you can run the container without the --build flag.

docker-compose up

You can check whether the image is built or not by running the following command:

docker images

You should see mohabyaser/online_chess_game_api in the list of images.

  1. After the server is up and running, you can access the API at http://localhost:3000.

You can try these endpoints to check if the server is running correctly:

  1. http://localhost:3000/api/health to check the health of the server

  2. http://localhost:3000/api-docs to access the Swagger documentation

  3. To stop the server, you can run the following command:

docker-compose down

Contributing

If you are interested in contributing to this project, you can follow along with these steps:

Requirements:

  • Node.js
  • npm
  • PostgreSQL
  • Redis
  1. Fork the repository

  2. Clone the repository

git clone https://github.com/<your-github-username>/online-chess-game.git
  1. Change directory to the project directory
cd online-chess-game
  1. Install the dependencies
npm install
  1. Copy the .env.example file to .env
cp .env.example .env
  1. Start filling the environment variables in the .env file, you can go with the default values for testing purposes except for NODEMAILER_EMAIL and NODEMAILER_PASSWORD which you need to fill with your email and password to be able to send emails.
POSTGRES_USER=postgres # name of the postgres user
POSTGRES_PASSWORD=551258 # password for the postgres user
POSTGRES_DB=chess # name of the database
JWT_SECRET=secret # secret token used in validating JWTs
NODEMAILER_EMAIL=email used by nodemailer
NODEMAILER_PASSWORD=password used by nodemailer
  1. Start the PostgreSQL database and Redis server
  2. Run the following command to start the express server
npm start
  1. After the server is up and running, you can access the API at http://localhost:3000.

Note

This is the dependency graph, a visual representation of the project's file dependencies. It shows how the files in the project depend on each other, rather than the dependencies in the node modules. This can be helpful for understanding the structure and relationships within the project.

Dependency Graph

About

Online Chess Game API imitates major features in famous chess platforms.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages