Skip to main content

No project description provided

Project description

repo_logo

Judge Microservice

A modern, configuration-driven online judge microservice system for automated code evaluation. Built with Docker and designed for high-performance competitive programming assessment and educational purposes.

โœจ Features

  • ๐Ÿš€ Zero Code Modification: The evaluation harness never requires changes
  • ๐ŸŽฏ Pure Function Interface: User functions operate on parameters without global state
  • ๐Ÿ“ Configuration-Driven: Define test cases through JSON configuration files
  • ๐Ÿณ Docker Native: Full containerization with local and remote Docker support
  • ๐Ÿ”ง Microservice Architecture: Stateless, containerized evaluation engines
  • ๐Ÿ›ก๏ธ Resource Isolation: Secure sandboxed execution environment with resource limits
  • โšก High Performance: Efficient container lifecycle management
  • ๐Ÿš€ Optimized Batch Execution: Test same code with multiple configurations without recompilation
  • ๐Ÿ Python Support: Full Python language support with multiple versions (3.9-3.13)
  • ๐Ÿ”Œ Python SDK: Easy-to-use Python API for seamless integration
  • ๐ŸŒ Remote Support: Execute on remote Docker hosts via SSH
  • ๐Ÿ“Š Detailed Reporting: Comprehensive performance metrics and error analysis
  • ๐Ÿ’ป Multi-Language Support: C, C++, and Python with modern standards
  • ๐Ÿ› ๏ธ RESTful API: Complete HTTP API with OpenAPI documentation

๐Ÿ—๏ธ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        Judge Micro System                            โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚  Client Code    โ”‚    โ”‚  API / SDK      โ”‚    โ”‚  Docker Manager   โ”‚ โ”‚
โ”‚  โ”‚  - Submit Code  โ”‚โ”€โ”€โ”€โ–ถโ”‚  - JudgeMicro   โ”‚โ”€โ”€โ”€โ–ถโ”‚  - Local/Remote   โ”‚ โ”‚
โ”‚  โ”‚  - Get Results  โ”‚    โ”‚  - Validation   โ”‚    โ”‚  - SSH Support    โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                   โ”‚                       โ”‚          โ”‚
โ”‚                                   โ–ผ                       โ–ผ          โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚                    Execution Containers                         โ”‚ โ”‚
โ”‚  โ”‚                                                                 โ”‚ โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚
โ”‚  โ”‚  โ”‚  C Container  โ”‚  โ”‚ C++ Container โ”‚  โ”‚  Python Container   โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ - GCC Compilerโ”‚  โ”‚- G++ Compiler โ”‚  โ”‚ - Python 3.9-3.13  โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚- cJSON Libraryโ”‚  โ”‚- JSON Library โ”‚  โ”‚ - JSON Library      โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚- Test Harness โ”‚  โ”‚- Test Harness โ”‚  โ”‚ - Test Harness      โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚
โ”‚  โ”‚        โ”‚                    โ”‚                    โ”‚             โ”‚ โ”‚
โ”‚  โ”‚        โ–ผ                    โ–ผ                    โ–ผ             โ”‚ โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ Config.json   โ”‚  โ”‚ Config.json   โ”‚  โ”‚    Config.json      โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ User Code     โ”‚  โ”‚ User Code     โ”‚  โ”‚    User Code        โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ Test Cases    โ”‚  โ”‚ Test Cases    โ”‚  โ”‚    Test Cases       โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚
โ”‚  โ”‚        โ”‚                    โ”‚                    โ”‚             โ”‚ โ”‚
โ”‚  โ”‚        โ–ผ                    โ–ผ                    โ–ผ             โ”‚ โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ Result.json   โ”‚  โ”‚ Result.json   โ”‚  โ”‚    Result.json      โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ - Status      โ”‚  โ”‚ - Status      โ”‚  โ”‚    - Status         โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ - Performance โ”‚  โ”‚ - Performance โ”‚  โ”‚    - Performance    โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ - Errors      โ”‚  โ”‚ - Errors      โ”‚  โ”‚    - Errors         โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐ŸŽฏ Core Design Principles

1. Configuration-Driven Evaluation ๐Ÿ“

  • Zero Code Modification: The evaluation harness never needs changes
  • Pure Function Interface: User functions operate on parameters without global state
  • JSON Configuration: Test cases defined through structured configuration files
  • Flexible Parameters: Support for arbitrary function signatures and types

2. Microservice Architecture ๐Ÿ”ง

  • Stateless Execution: Each evaluation runs in isolation
  • Container Lifecycle: Create โ†’ Execute โ†’ Destroy pattern
  • Resource Management: CPU, memory, and time limits enforced
  • Scalable Design: Horizontal scaling through container orchestration

3. Multi-Language Support ๐Ÿ’ป

  • C Language: GCC with cJSON library support (C99, C11, C23)
  • C++ Language: G++ with modern standards (C++11, C++17, C++20, C++23)
  • Python Language: Multiple Python versions (3.9, 3.10, 3.11, 3.12, 3.13)
  • Template Support: Generic functions and type deduction
  • No Compilation for Python: Direct execution for interpreted languages
  • Extensible Framework: Easy addition of new language containers

4. Comprehensive Error Detection ๐Ÿ›ก๏ธ

  • Compilation Errors: Automatic detection of syntax and type errors
  • Runtime Errors: Segmentation faults, exceptions, and crashes
  • Logic Errors: Output validation against expected results
  • Resource Monitoring: CPU time, memory usage, and execution metrics

๐Ÿ› ๏ธ System Requirements

  • Operating System: Linux (Ubuntu/Debian recommended)
  • Container Runtime: Docker Engine 20.10+
  • Python: 3.8+ for SDK usage
  • Network: Internet access for Docker image pulls

๐Ÿš€ Quick Start

Method 1: Docker Compose (Recommended)

git clone https://github.com/TsukiSama9292/judge_micro.git
cd judge_micro
docker compose up -d

Method 2: Python SDK Installation

# Install from PyPI
pip install judge_micro

# Or install from source
git clone https://github.com/TsukiSama9292/judge_micro.git
cd judge_micro
pip install -e .

Method 3: API Service

# Start the REST API server
uvicorn judge_micro.api.main:get_app --host 0.0.0.0 --port 8000 --factory --reload

# Access API documentation
# - Swagger UI: http://localhost:8000/docs
# - ReDoc: http://localhost:8000/redoc

๐Ÿ’ก Usage Examples

Python SDK - Basic Example

from judge_micro.services.efficient import JudgeMicroservice

# Initialize the service
judge = JudgeMicroservice()

# C/C++ example
user_code = '''
int solve(int a, int b) {
    return a + b;
}
'''

config = {
    "solve_params": [
        {"name": "a", "type": "int", "input_value": 5},
        {"name": "b", "type": "int", "input_value": 3}
    ],
    "expected": {"result": 8},
    "function_type": "int"
}

result = judge.run_microservice('c', user_code, config)

if result['status'] == 'SUCCESS':
    print(f"โœ… Test passed! Result: {result['actual']}")
    print(f"โฑ๏ธ Execution time: {result['metrics']['test_execution_time']:.3f}s")

Python SDK - Python Language Example

# Python code example
python_code = '''
def solve(numbers: list, multiplier: int) -> list:
    return [x * multiplier for x in numbers]
'''

python_config = {
    "solve_params": [
        {"name": "numbers", "type": "list", "input_value": [1, 2, 3, 4]},
        {"name": "multiplier", "type": "int", "input_value": 2}
    ],
    "expected": {"result": [2, 4, 6, 8]},
    "function_type": "list"
}

# Test with Python 3.12 (default)
result = judge.run_microservice('python', python_code, python_config)

# Test with specific Python version
result = judge.run_microservice('python-3.11', python_code, python_config)

Python SDK - Optimized Batch Testing

# Test same code with multiple configurations efficiently
user_code = '''
int factorial(int n) {
    if (n <= 1) return 1;
    return n * factorial(n - 1);
}
'''

# Multiple test configurations
configs = [
    {
        "solve_params": [{"name": "n", "type": "int", "input_value": 5}],
        "expected": {"result": 120},
        "function_type": "int"
    },
    {
        "solve_params": [{"name": "n", "type": "int", "input_value": 0}],
        "expected": {"result": 1},
        "function_type": "int"
    },
    {
        "solve_params": [{"name": "n", "type": "int", "input_value": 7}],
        "expected": {"result": 5040},
        "function_type": "int"
    }
]

# Single compilation, multiple tests
results = judge.optimized_batch_test('c', user_code, configs)
print(f"Executed {len(results)} tests with single compilation")

REST API - Basic Usage

# C/C++ submission
curl -X POST "http://localhost:8000/judge/submit" \
-H "Content-Type: application/json" \
-d '{
  "language": "c",
  "user_code": "int solve(int a, int b) { return a + b; }",
  "solve_params": [
    {"name": "a", "type": "int", "input_value": 5},
    {"name": "b", "type": "int", "input_value": 3}
  ],
  "expected": {"result": 8},
  "function_type": "int"
}'

REST API - Python Submission

# Python submission with specific version
curl -X POST "http://localhost:8000/judge/submit" \
-H "Content-Type: application/json" \
-d '{
  "language": "python-3.12",
  "user_code": "def solve(numbers: list, target: int) -> bool:\n    return target in numbers",
  "solve_params": [
    {"name": "numbers", "type": "list", "input_value": [1, 2, 3, 4, 5]},
    {"name": "target", "type": "int", "input_value": 3}
  ],
  "expected": {"result": true},
  "function_type": "bool"
}'

REST API - Optimized Batch Processing

# Submit multiple test configurations for batch processing
curl -X POST "http://localhost:8000/judge/batch/optimized" \
-H "Content-Type: application/json" \
-d '{
  "language": "c",
  "user_code": "int solve(int x) { return x * x; }",
  "test_configs": [
    {
      "solve_params": [{"name": "x", "type": "int", "input_value": 2}],
      "expected": {"result": 4},
      "function_type": "int"
    },
    {
      "solve_params": [{"name": "x", "type": "int", "input_value": 5}],
      "expected": {"result": 25},
      "function_type": "int"
    }
  ]
}'

๐ŸŒ Use Cases

  • Online Judge Platforms: Competitive programming websites like Codeforces, AtCoder
  • Educational Systems: Automated assignment grading and student assessment
  • Coding Interviews: Technical assessment platforms for recruitment
  • Code Quality Tools: Automated testing and validation systems
  • Research Projects: Algorithm performance evaluation and benchmarking
  • Multi-Language Learning: Support for learning C, C++, and Python programming

๐Ÿš€ Supported Languages

Language Versions Container Image Features
C C99, C11, C23 tsukisama9292/judge_micro:c GCC compiler, cJSON library
C++ C++11, C++17, C++20, C++23 tsukisama9292/judge_micro:c_plus_plus G++ compiler, STL, templates
Python 3.9, 3.10, 3.11, 3.12, 3.13 tsukisama9292/judge_micro:python-X.Y No compilation, direct execution

Python Language Support

  • Default Version: Python 3.12 (python language code)
  • Specific Versions: Use python-3.9 through python-3.13
  • Built-in Types: Support for int, float, str, bool, list, dict
  • No Compilation: Direct execution for faster testing
  • Version-Specific Testing: Test code compatibility across Python versions

๐Ÿ“š Documentation

๐Ÿ”ง Advanced Configuration

Remote Docker Support

# Configure remote Docker host via SSH
import os
os.environ['DOCKER_SSH_REMOTE'] = 'true'
os.environ['DOCKER_SSH_HOST'] = '192.168.1.100'
os.environ['DOCKER_SSH_USER'] = 'docker'
os.environ['DOCKER_SSH_KEY_PATH'] = '/path/to/ssh/key'

Resource Limits

# Set container resource limits
os.environ['CONTAINER_CPU'] = '1.0'      # CPU limit (cores)
os.environ['CONTAINER_MEM'] = '512m'     # Memory limit
os.environ['CONTAINER_TIMEOUT'] = '30'   # Execution timeout (seconds)
os.environ['COMPILE_TIMEOUT'] = '20'     # Compilation timeout (seconds)

Language-Specific Configuration

# C++ with specific standard
config = {
    "compiler_settings": {
        "standard": "cpp20",
        "flags": "-Wall -Wextra",
        "optimization_level": "-O2"
    }
}

# C with specific standard
config = {
    "compiler_settings": {
        "standard": "c11",
        "flags": "-Wall -Wextra -pedantic"
    }
}

# Python with specific version
result = judge.run_microservice('python-3.11', user_code, config)

Batch Processing Configuration

# Optimize batch execution for multiple test cases
from judge_micro.services.efficient import JudgeMicroservice

judge = JudgeMicroservice()

# Single code, multiple test configurations
results = judge.optimized_batch_test(
    language='python',
    user_code=user_code,
    test_configs=multiple_configs
)

# Performance benefits:
# - Single compilation/initialization
# - Reused container
# - Parallel test execution

๐Ÿงช Testing

# Run all tests
pytest tests/ -v

# Run language-specific tests
pytest tests/test_c.py -v        # C language tests
pytest tests/test_cpp.py -v      # C++ language tests  
pytest tests/test_python.py -v   # Python language tests

# Run API tests
python scripts/test_api.py

# Run optimized batch tests
pytest test_optimized_batch.py -v

# Run Python API tests
pytest test_python_api.py -v

๐Ÿ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

judge_micro-0.0.3.tar.gz (3.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

judge_micro-0.0.3-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file judge_micro-0.0.3.tar.gz.

File metadata

  • Download URL: judge_micro-0.0.3.tar.gz
  • Upload date:
  • Size: 3.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.3

File hashes

Hashes for judge_micro-0.0.3.tar.gz
Algorithm Hash digest
SHA256 21a6e6a5a0c030515ac2939155c9dcb4c421245b9e646399061e1cb9f6f4e583
MD5 b7ca0632f1543bfa8409b8dea33355ad
BLAKE2b-256 1925961f63438b263b2ed0d881ba53183dc8f0b74534fbdca8c9d428f31042c1

See more details on using hashes here.

File details

Details for the file judge_micro-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for judge_micro-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 eb225436ba63e364f061663d441c11e00b08e87cd78207a962a035ecdcfde3b5
MD5 cc78c3a804543d587130c740f55de3e0
BLAKE2b-256 9551749d193849a19ad88700a27dc92b4f4c07149d1b35b4f9b15c3efa5694c7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page