/CodeBox

Primary LanguageJavaScript

CodeBox 1.0

GitHub go.mod Go version Next JS Postgres RabbitMQ

About

CodeBox is an online code executor and judging platform designed to provide a user-friendly environment for developers and programmers as practice platform for data structures and algorithms (DSA). It is similar to Leetcode , compile and execute code online.

SC1

Features

  • Based on Docker; One-click deployment.
  • Separated backend and frontend; Modular programming; Micro service.
  • Multi-language support: C++, Java, Python3
  • Sandbox for running quick snipts.
  • Provides insights of result.
  • Maintains history of code problems tried.

Working

Blank diagram - Page 1(1)

  • When user hit Run on the screen, client makes a packs the code written and problem id this payload is called Task, this is sent to te api server which stores it in DB. Api server creates a Task-id and returns it marking it a successful submission.
  • Api server after successfully stroing it in DB adds it to the RMQ which delivers the task aka message to availble CodeRunner.
  • CodeRunner is a Sandbox env, It accepts the task mark it Running in DB. CR compiles the code and runs it with standard inputs. If code is DSA type it matches the code output with expected output and produces the result. Now if there is malicious code it would just crash the docker container, for that enable restart on crash in docker. There is additional measure which timeouts the code execution if it exceeds X amount of seconds/minutes and results TLE.
  • Meanwhile on user side, client is continuously long polling for the result with a Task-id, and shows it to user when result is available.

Installation

  1. Install the necessary dependencies

    Fedora

    sudo dnf groupinstall c-development
    sudo dnf install python3
    pip3 install --upgrade pip
    sudo dnf install java-1.8.0-openjdk.x86_64

    Ubuntu

    sudo apt-get update
    sudo apt install build-essential
    sudo apt-get install -y vim python3-pip curl git
    pip3 install --upgrade pip
    sudo apt install default-jdk
  2. Install docker and docker compose from Here

  3. Create a postgres database server using docker. Set a user and password for the db which we will use.

    docker run --name postgres-db -e POSTGRES_USER=vishvajeet -e POSTGRES_PASSWORD=xyzPassword -p 5432:5432 -d postgres
  4. Now we need to start a rabbit mq instance which will be the message queue for our application.

    docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.11-management
  5. cd into the root of the project and create a .env file to store our db and queue credentials.

    PORT=8080
    
    RM_QUEUE=codeBox
    RMQ_URL=amqps://xxxuserxxx:xxxpassxxx@xxxhostxxx/xxxportxxx
    RMQ_EXCHANGE_NAME=CodeBoxExchange
    RMQ_QUEUE_NAME=CodeBoxQueue
    
    DB_URL=postgresql://<user>:<Db Pass>@<host add>:<port>/<db>
    
  6. From the root of the project, start the service

    cd CodeBox
    docker compose up

Screenshots

Home:

SC1

When solution is accepted:

SS2

If solution is rejected due to wrong answer or TLE:

SS3

Sandbox to run small snippets:

SS4

History tab:

ss5

Thanks

  • Project is yet in developement, it is right now in the bare minimum working codition. I would try imporve uppon the code quality if time permits.
  • Special thanks to Charan Vasu and Gaurav, for resolving minor challenges that arose during the project