DEV Community

Cover image for Developing a platform where programmers can practice solving problems
Zakaria Maaraki
Zakaria Maaraki

Posted on

Developing a platform where programmers can practice solving problems

Source Code : https://github.com/zakariamaaraki/Problem-Solving-Platform

The idea of the platform, is to let programmers to practice algorithms and data structures problems.
So the user can read the problem, think about the solution, and write the code, then submit it.
The platform needs to run the code on some test cases then return the verdict to the user (Accepted, Wrong answer, Runtime error, Compilation error, Time limit excceded, or Memory limit excceeded).

Architecture

Architecture

Remote Code Compiler

There are two main components (microservices), the first one is the remote code compiler https://github.com/zakariamaaraki/RemoteCodeCompiler, it's an online code compiler written using Java (Spring Boot) for Java, C, C++ and Python, for competitive programming and coding interviews.

Supports Rest Calls, Apache Kafka and Rabbit MQ Messages.

This service execute your code remotely using docker containers to separate the different environements of executions.

Architecture

Example of an input

{
    "input": "9",
    "expectedOutput": "0 1 2 3 4 5 6 7 8 9",
    "sourceCode": "public class Test1 {\npublic static void main(String[] args) {\nint i = 0;\nwhile (i < 10) {\nSystem.out.println(i++);\n}}}",
    "language": "JAVA",
    "timeLimit": 15,
    "memoryLimit": 500
}
Enter fullscreen mode Exit fullscreen mode

Example of an ouput

{
    "output": "0 1 2 3 4 5 6 7 8 9",
    "expectedOutput": "0 1 2 3 4 5 6 7 8 9",
    "status": "Accepted",
    "date": [2021,12,1,22,10,24,311828000]
}
Enter fullscreen mode Exit fullscreen mode

Examples of Executions

{
    "output": "0\n1\n2\n3\n",
    "expectedOutput": "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n",
    "status": "Wrong Answer",
    "date": [2021,12,2 ,22,10,24,311828000]
}
Enter fullscreen mode Exit fullscreen mode
{
    "output": "",
    "expectedOutput": "test compiler\n",
    "status": "Compilation Error",
    "date": [2021,12,1 ,22,10,24,311828000]
}
Enter fullscreen mode Exit fullscreen mode
{
    "output": "",
    "expectedOutput": "test\ntest\ntest\n",
    "status": "Time Limit Exceeded",
    "date": [2021,12,3 ,22,10,24,311828000]
}
Enter fullscreen mode Exit fullscreen mode
{
    "output": "abc\n",
    "expectedOutput": "abc\n",
    "status": "Accepted",
    "date": [2021,12,4 ,22,10,24,311828000]
}
Enter fullscreen mode Exit fullscreen mode

Problem Solving Platform

The second Microservice is written using C# (.Net core), and Razor as a template engine for the UI.
This component communicates with the Remote code compiler to run the user solution on test cases. It uses MongoDB as its document database.
I chose MongoDB as a database because of it's scalability and because it's a CP system (it provides Consistency and Partition Tolerence).

For dev env

The service provides a Swagger page : Architecture

How to run it

First you'll need to build the docker image of the project https://github.com/zakariamaaraki/RemoteCodeCompiler.

cd RemoteCodeCompiler
docker build . -t compiler
Enter fullscreen mode Exit fullscreen mode

Then clone the Platform source code https://github.com/zakariamaaraki/Problem-Solving-Platform/ and run the following command

docker-compose up --build
Enter fullscreen mode Exit fullscreen mode

Some screens

Problems

ProblemSolvingPlatformUI

Submissions verdict

ProblemSolvingPlatformUISubmissions

Discussion (0)