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.
- 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. 📚
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.
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:
- Clone the repository
git clone https://github.com/Mohab96/online-chess-game.git
- Change directory to the project directory
cd online-chess-game
- Copy the
.env.example
file to.env
cp .env.example .env
- Start filling the environment variables in the
.env
file, you can go with the default values for testing purposes except forNODEMAILER_EMAIL
andNODEMAILER_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
- 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.
- 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:
-
http://localhost:3000/api/health
to check the health of the server -
http://localhost:3000/api-docs
to access the Swagger documentation -
To stop the server, you can run the following command:
docker-compose down
If you are interested in contributing to this project, you can follow along with these steps:
Requirements:
- Node.js
- npm
- PostgreSQL
- Redis
-
Fork the repository
-
Clone the repository
git clone https://github.com/<your-github-username>/online-chess-game.git
- Change directory to the project directory
cd online-chess-game
- Install the dependencies
npm install
- Copy the
.env.example
file to.env
cp .env.example .env
- Start filling the environment variables in the
.env
file, you can go with the default values for testing purposes except forNODEMAILER_EMAIL
andNODEMAILER_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
- Start the PostgreSQL database and Redis server
- Run the following command to start the express server
npm start
- After the server is up and running, you can access the API at
http://localhost:3000
.
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.