Velox is a high-performance, containerized code execution engine (Online Judge) built with Go and Docker. It allows you to submit code in various languages, execute it against multiple test cases, and receive detailed resource usage (time and memory) along with execution status.
https://drive.google.com/file/d/1W_tCFVxVPxistrRpI8Y9a9LbJ5uf3Lv5/view?usp=sharing
The project is split into two main services: an API Server and a Worker.
Core Go application logic.
- cmd/
- api/: Entry point for the HTTP server. Handles
/submitand/statusendpoints, protected by API Key authentication. - worker/: Entry point for the background worker. Continuously polls Redis for new submissions to process.
- api/: Entry point for the HTTP server. Handles
- auth/: Authentication module handling API Keys, Users, and background API usage metrics.
- judge/: Defines the data models (
judge.go) for requests and responses used across the system. - processSubmission/: The language orchestrator utilizing the Strategy Pattern. Handles compilation and script preparation for all supported languages.
- runBatch/: The execution engine. Runs binaries/scripts in a controlled environment, pipes input, and captures results, Time (ms), and Memory (KB).
- shared/redis/: Basic Redis wrapper for pushing/popping submissions and results.
- docs/: Automatically generated Swagger (OpenAPI 3.0) documentation.
The project uses Swagger (OpenAPI 3.0) for API documentation.
When the server is running in development mode (GO_ENV=development), you can access the interactive Swagger UI at:
If you add new endpoints or update annotations, regenerate the documentation using:
cd backend
go run github.com/swaggo/swag/cmd/swag init -g cmd/api/main.goContains infrastructure configuration.
- Dockerfile.api: Minimal Go runtime for the API service.
- Dockerfile.worker: Full-featured image containing compilers (gcc, g++, javac) and runtimes (python, node, openjdk) required for judging.
Orchestrates the api, worker, postgres, and redis services into a single local environment.
- Language: Go (Golang)
- Database: PostgreSQL
- Queue/Store: Redis
- Containerization: Docker & Docker Compose
- Supported Languages:
- C (GCC 12+)
- C++ (G++ 12+)
- Java (OpenJDK 17)
- C#
- Python (3.x)
- Node.js
- TypeScript
Ensure you have Docker and Docker Compose installed.
-
Clone the repository:
git clone https://github.com/RISHIK92/velox.git cd velox -
Spin up the stack:
docker compose up --build
-
Test a submission:
curl -X POST http://localhost:8080/submit \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <YOUR_API_KEY>" \ -d '{ "language": "cpp", "source_code": "#include <iostream>\nusing namespace std;\nint main() { int a, b; while (cin >> a >> b) cout << a + b << endl; return 0; }", "test_cases": [{"test_case_id": 1, "input": "5 10", "expected_output": "15"}] }'
-
Check status:
curl -X GET "http://localhost:8080/status?submission_id=<ID_FROM_PREVIOUS_STEP>" \ -H "Authorization: Bearer <YOUR_API_KEY>"
We welcome contributions! To help you get started:
- Create Strategy: Under
backend/processSubmission/, create a new file (e.g.,ruby_strategy.go) implementing theLanguageStrategyinterface. - Register Strategy: Update
NewDefaultRegistry()in theprocessSubmissionmodule to register your new strategy with its corresponding language key. - Update Dockerfile: Update
build/Dockerfile.workerto ensure the necessary compiler or runtime is installed in the worker image. - Add Tests: Add unit tests for your strategy execution path.
- Code Style: We follow standard Go formatting (
go fmt). - Testing: Use the provided
curlsamples and test scripts to verify your changes. - Watch Mode: You can use
docker compose watch(if supported by your version) to automatically rebuild services when files inbackend/change.
- Fork the repo.
- Create your feature branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.