Golf it! is a game designed to let you show off your code-fu by solving problems
in the least number of characters ✨
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
One of our teammates loves to solve codegolf questions. We thought it would be a good idea to implement this as a one on one competition, where two players can compete live to write the shortest snippet of code to solve a question.
Code Golf refers to attempting to solve a problem using the least amount of characters possible i.e. to have the smallest source code. The term is derived from the sport golf where the player’s goal is to hit their ball in the hole using the least number of shots possible. In Code Golf the developer that solves the problem (usually writing a function) using the fewest number characters possible wins.
The backend was built using NodeJS
and Typescript
. We used expressJS
to implement all the routes required for submitting code. The backend uses an npm library called code-executor
which was built in the past by one of our teammates, to execute code against test cases in isolated Docker
containers. To implement real-time communication when a head-to-head game started, we used socket.io
to connect both the players in the same room. We used firestore as a database.
The frontend was built using React and Bootstrap. We used socket.io-client
to interact with the socket server, and axios to interact with the express backend. To display the code editor on the website with multiple themes and syntax support for languages, we used a library called react-ace
.
We have many features planned for golf-it in the future:
- Global leaderboards across the website, for players who regularly win more and more head-to-head games to showcase their skills.
- User accounts (registering and logging in)
- The ability for users to submit their own questions, and people to vote for questions they found interesting.
- Picking avatars for your own profile
- Having live competitions with even more people, instead of just head-to-head ones.
Backend | Frontend |
---|---|
Typescript | Javascript |
express | axios |
firebase | React |
code-executor | react-redux |
socket.io | socket.io-client |
joi | react-router-dom |
redis | react-ace |
To get a local copy up and running follow these simple steps.
This is an example of how to list things you need to use the software and how to install them.
- yarn
npm install -g yarn
- Clone the repo
git clone https://github.com/ashikka/golf-it.git
- Install yarn packages
yarn
- Add necessary environment variables to the project using:
{
echo 'API_KEY='
echo 'AUTH_DOMAIN='
echo 'PROJECT_ID='
echo 'STORAGE_BUCKET='
echo 'MESSAGING_SENDER_ID='
echo 'APP_ID='
} >> .env
Start the project locally by following these steps.
- Run a Redis broker on your system
docker run -p6379:6379 redis
- Start the worker which is going to interact with the library
code-executor
.
cd backend
ts-node worker.ts
- Start the backend using:
yarn run dev
- Start the frontend using:
cd frontend
yarn start
The backend of the project supports the following routes:
POST /code/submission/:questionName
Parameter | Type | Description |
---|---|---|
params |
string |
questionName |
body |
string |
language |
body |
string |
code |
body |
Date |
submitTime |
POST /room/create
Parameter | Type | Description |
---|---|---|
body |
string |
clientId |
body |
number |
payload |
GET /room/:roomId
Parameter | Type | Description |
---|---|---|
params |
string |
roomId |
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'feat: Add some AmazingFeature'
) - Push to the Branch (
git push -u origin feature/AmazingFeature
) - Open a Pull Request
You are requested to follow the contribution guidelines specified in CONTRIBUTING.md while contributing to the project 😄.
Distributed under the MIT License. See LICENSE
for more information.