Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions API_DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# CodeExecutor-API Documentation

Dynamic code execution API supporting multiple languages and database-backed problem management.

## Base URL
`http://localhost:3000`

## Interactive Documentation
Interactive docs are available at: [http://localhost:3000/docs](http://localhost:3000/docs)

---

## Endpoints

### 1. List Problems
Retrieve a summary of all problems in the database.
- **URL**: `/problems`
- **Method**: `GET`
- **Response**: `200 OK`
```json
{
"status": "success",
"data": [
{ "id": "uuid", "title": "Two Sum", "difficulty": "easy" }
]
}
```

### 2. Get Problem Details
Retrieve specific problem metadata, configuration, and public test cases.
- **URL**: `/problem/<problem_id>`
- **Method**: `GET`
- **Response**: `200 OK`

### 3. Execute Code (Problem-based)
Run code against test cases associated with a specific problem.
- **URL**: `/code/<problem_id>`
- **Method**: `POST`
- **Body**:
```json
{
"language": "python",
"code": "print('hello')"
}
```

### 4. Custom Execution
Run arbitrary code without a pre-defined problem.
- **URL**: `/run?lang=python`
- **Method**: `POST`
- **Body**:
```json
{
"code": "print('hello world')"
}
```

---

## Supported Languages
- **Python**: `python`
- **JavaScript**: `javascript`
- **Java**: `java`
- **C**: `c`
- **C++**: `cpp`
15 changes: 15 additions & 0 deletions bruno/docs.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
meta {
name: docs
type: http
seq: 3
}

get {
url: http://localhost:3000/docs
body: none
auth: inherit
}

settings {
encodeUrl: true
}
28 changes: 27 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
from flask import Flask, request, jsonify
from flask import Flask, request, jsonify, send_from_directory
from executor import execute_code, execute_custom_code
from db import init_db

app = Flask(__name__, static_folder='html')

@app.route('/openapi.yaml')
def serve_openapi():
"""Serve the OpenAPI specification."""
return send_from_directory(app.root_path, 'openapi.yaml')

@app.route('/docs')
def scalar_docs():
"""Serve interactive Scalar documentation."""
return f"""
<!doctype html>
<html>
<head>
<title>CodeExecutor-API Documentation</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body {{ margin: 0; }}
</style>
</head>
<body>
<script id="api-reference" data-url="/openapi.yaml"></script>
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
</body>
</html>
""", 200

init_db()

@app.post('/run')
Expand Down
229 changes: 120 additions & 109 deletions src/html/index.html
Original file line number Diff line number Diff line change
@@ -1,116 +1,127 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>DevScape API</title>
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap"
rel="stylesheet"
/>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: "Inter", sans-serif;
background: radial-gradient(circle at top, #0d1117, #000);
color: #e6edf3;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
overflow: hidden;
}
.container {
background: rgba(22, 27, 34, 0.85);
padding: 50px 80px;
border-radius: 20px;
box-shadow: 0 0 40px rgba(88, 166, 255, 0.3);
text-align: center;
backdrop-filter: blur(10px);
animation: fadeIn 1.5s ease-in-out;
}
h1 {
font-size: 3em;
color: #58a6ff;
margin-bottom: 20px;
letter-spacing: 1px;
}
p {
font-size: 1.2em;
color: #c9d1d9;
margin-bottom: 10px;
line-height: 1.6;
}
code {
background: rgba(88, 166, 255, 0.1);
color: #79c0ff;
padding: 4px 8px;
border-radius: 6px;
font-size: 1em;
}
.glow {
position: absolute;
top: -150px;
width: 600px;
height: 600px;
background: radial-gradient(
circle,

<head>
<meta charset="UTF-8" />
<title>DevScape API</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet" />
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}

body {
font-family: "Inter", sans-serif;
background: radial-gradient(circle at top, #0d1117, #000);
color: #e6edf3;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
overflow: hidden;
}

.container {
background: rgba(22, 27, 34, 0.85);
padding: 50px 80px;
border-radius: 20px;
box-shadow: 0 0 40px rgba(88, 166, 255, 0.3);
text-align: center;
backdrop-filter: blur(10px);
animation: fadeIn 1.5s ease-in-out;
}

h1 {
font-size: 3em;
color: #58a6ff;
margin-bottom: 20px;
letter-spacing: 1px;
}

p {
font-size: 1.2em;
color: #c9d1d9;
margin-bottom: 10px;
line-height: 1.6;
}

code {
background: rgba(88, 166, 255, 0.1);
color: #79c0ff;
padding: 4px 8px;
border-radius: 6px;
font-size: 1em;
}

.glow {
position: absolute;
top: -150px;
width: 600px;
height: 600px;
background: radial-gradient(circle,
rgba(88, 166, 255, 0.2),
transparent 70%
);
animation: pulse 6s infinite alternate;
z-index: -1;
}
footer {
margin-top: 20px;
font-size: 0.9em;
color: #8b949e;
}
footer a {
color: #58a6ff;
text-decoration: none;
transition: 0.2s;
transparent 70%);
animation: pulse 6s infinite alternate;
z-index: -1;
}

footer {
margin-top: 20px;
font-size: 0.9em;
color: #8b949e;
}

footer a {
color: #58a6ff;
text-decoration: none;
transition: 0.2s;
}

footer a:hover {
color: #79c0ff;
text-decoration: underline;
}

@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(30px);
}
footer a:hover {
color: #79c0ff;
text-decoration: underline;

to {
opacity: 1;
transform: translateY(0);
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}

@keyframes pulse {
from {
transform: scale(1);
opacity: 0.4;
}
@keyframes pulse {
from {
transform: scale(1);
opacity: 0.4;
}
to {
transform: scale(1.3);
opacity: 0.8;
}

to {
transform: scale(1.3);
opacity: 0.8;
}
</style>
</head>
<body>
<div class="glow"></div>
<div class="container">
<h1>Code Executor API</h1>
<p>
Welcome to the backend gateway of the
<strong>Code Executor API</strong>.
</p>
<footer>
<p>Made for developers, by developers. <a href="#">View Docs</a></p>
</footer>
</div>
</body>
</html>
}
</style>
</head>

<body>
<div class="glow"></div>
<div class="container">
<h1>Code Executor API</h1>
<p>
Welcome to the backend gateway of the
<strong>Code Executor API</strong>.
</p>
<footer>
<p>Made for developers, by developers. <a href="/docs">View Docs</a></p>
</footer>
</div>
</body>

</html>
Loading