Skip to content

A Service of Algocode - A leetcode like project to handle all the code submission and consume result from Remote Code Execution Engine Service

License

Notifications You must be signed in to change notification settings

Mahboob-A/code-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


Logo

Algocode - The Leetcode for Hackers

Algocode is a DSA practice platform just like Leetcode!

Read the blog Β»

Algocode Auth Service . Code Manager Service . RCE Engine Service

General Information

Algocode is an online data structure and algorithm practice backend built in microservices architecture.

Algocode currently has three services: Algocode Auth Service . Code Manager Service . and RCE Engine Service

Code Manager Service is responsible to interact with client side to handle code submission requests and manage code execution in the RCE Engine Service.

To learn more about Algocode and the architecture, please READ-THE-BLOG-URL or visit Algocode here.

NOTE

A. Rate Limit Alert

The API endpoint to submit solution to the Algocode platfrom (Implemented using Token Bucket Algorithm Rate Limit Middleware ) is rate limited to 1 request per 20 seconds.

    POST https://codemanager.algocode.site/api/v1/code/submit/

B. Documentation

Please visit the documentation page for the detailed guide on Algocode Code Manager Service.

However, all the APIs are referenced in the API Reference section below.

C. Deployment

The service is deployed in AWS EC2 Ubuntu 22.04 server.

D. About Algocode

This is Code Manager Service specific guideline.

Please visit Algocode to learn the mircroservices architecture of Algocode and more in-depth guideline how to submit a solution to Algocode platform.



Production

Production Stage Code Manager

The Algocode Code Manager Services uses the following services to serve the request during Production Stage.

a. Nginx as webserver.
b. Nginx Proxy Manager to manage Nginx.
c. Portainer to manage and monitor docker container in Code Manager Service. 
d. Gunicorn as application server.
e. RabbitMQ for asynchronous message processig.
f. Django as backend. 
g. Django Rest Framework for API. 
h. PostgreSQL for Algocode questions/problems database.
i. Redis for cache. 
j. MongoDB to store code execution result.
k. Docker to containerize the service. 

Deployment

The Code Manager Service is deployed in AWS EC2 Ubuntu 22.04 Server.



Workflow - Code Manager

Overview

Code Manager Service acts as middleman between the clients and the RCE Engine Service to handle code submission and code execution.

The client can not directly interact with the RCE Engine Service as it is a secure and isolated environment to actually execute the user submitted code in the Algocode platform. Code Manager acts as the connecting dots between the client and the RCE Engine service from solution submission to result persistence process.

Workflow

The user submits the solution of the problem they want to submit through the code submission API. The API processes the data and publishes the data in aRabbitMQ instance. The RCE Engine Service consumes the message and executes the user submitted code and generates a result comparing the testcases and the output of the user submitted code.

Once a result is generated, the RCE Engine publishes the code execution result to a unified result queue, Code Manager Services listens to the unified result queue.

Code Manger processes the message from the unified result queue, caches it in Redis and stores the result in MongoDB database for persistence.



Watch In Action

A. Long Video (Describes all the features and architecture)

  • Watch from 16:30 for code execution begin and 18:30 for code submission result.
Watch the video

B. Short Video (Only core features)

  • Watch from 09:30 for code execution begin and 11:30 for code submission result.
Watch the video

API Reference - Code Submission and Submission Result

Problem Lists

To learn about the Problems in Algocode without calling API, Please visit Algocode Problem Lists to get all the available problems.

I have used notion page to host the available problems in Algocode as I am focusing on advanced backend engineering, and as there is no client app for Algocode at the time I am writing this Readme.

If you want to contribute to build a client app for the Algocode, pelase do not hesitate to email here: Email Me

To learn more on Algocode and the microservices architecture of Algocode; and more detailed guide on how to submit a solution, please visit algocode here.


Code Submission API
    POST https://codemanager.algocode.site/api/v1/code/submit/
Parameter Type Value/Description
problem_id string Required. The problem_id of the problem you are submitting the solution.
lang string Required. cpp. Currently cpp is supported. java RCE Engine is under development.
code string Required. Your solution for the problem in JSON format.

The queue is based on the programming language of the solution.


Example Payload

Here's an example payload for one of a problem in Algocode Sqrt(X). The problem is same as this Leetcode Problem.


Example Payload

{
    "problem_id": "f17f511a-8c53-41d3-b750-7673d25835af", 
    "lang": "cpp", 
    "code": "#include <iostream>\n\nint mySqrt(int x) {\n    if (x == 0) return 0;\n    int left = 1, right = x, result = 0;\n    while (left <= right) {\n        
     int mid = left + (right - left) / 2;\n        if (mid <= x / mid) {\n            result = mid;\n            left = mid + 1;\n        } else {\n            right = mid - 1;\n        }\n    
    }\n    return result;\n}\n\nint main() {\n    int t;\n    std::cin >> t;\n    while (t--) {\n        int x;\n        std::cin >> x;\n        std::cout << mySqrt(x) << 
    std::endl;\n    }\n    return 0;\n}\n"
}

Code Submission Result API

The second API of the Code Manager service is to check the result of an code submission to the Algocode platform.

The API is a Short Polling API. It checks the data in cache, then in MongoDB Database and if the data could not be found, it waits for 5 seconds for the availability of the data.

    GET  https://codemanager.algocode.site/api/v1/result/check/<submission_id>/
Parameter Type Description
submission_id string Required. The submission_id of your solution as per the API Guideline - Code Submission in Algocode section.


API Reference - Problem List APIs

All Problems in Algocode

The API response is paginated with 10 results.

    POST https://codemanager.algocode.site/api/v1/problem/all/

Specific Problem in Algocode

Any specific problem using problem id.

    POST https://codemanager.algocode.site/api/v1/problem/<uudi:id>/
Parameter Type Description
id string Required. The id of the problem/question.

Healthcheck

     GET  https://codemanager.algocode.site/api/v1/common/healthcheck/

Please visit the documentation page for more details.



Run Locally and Contribution

Run Locally

Please fork and clone this development branch of Algocode Code Manager Service, and follow along with the envs-examples.

cd to src and create a virtual environment. Activate the virtual environment.

Run make docker-up and the development setup will start running. Please install make in your host machine.

If you use Windows Operating System, please run the respective docker commands from the dev.yml docker compose file.

Contribution

You are always welcome to contribute to the project. Please open an issue or raise a PR on the project.



Code Submission Result Examples


Some Code Submission Result Snapshots


A. AC Solution

dd8dbfe4-621b-49f1-b3a6-7ab2a892db87

B. WA Solution

bedb4255-86c9-4417-b920-5976e6129cbb

C. Compilation Error

1c5edd39-8ccd-4e23-a61d-66ae9564ca85

D. Segmentation Fault

WhatsApp Image 2024-06-05 at 11 42 42 PM (1)

E. Memory Limit Exceed

WhatsApp Image 2024-06-05 at 11 42 03 PM (1)

F. Time Limit Exceed

WhatsApp Image 2024-06-05 at 11 42 03 PM (1)



Linux Postman C++ Java Python Django AWS Docker Bash Azure CircleCI Node.js Kafka RabbitMQ Nginx

πŸ”— Links

Email Me Twitter LinkedIn Hashnode Medium Devto LeetCode

About

A Service of Algocode - A leetcode like project to handle all the code submission and consume result from Remote Code Execution Engine Service

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published