A professional, layered-architecture API for dynamic code execution. This project allows you to run code in multiple languages against database-backed problems and test cases. 🚀🧪
Before embarking on this journey, ensure your machine is equipped with:
- 🐳 Docker: Install Docker
- 🐳 Docker Compose: Install Docker Compose
Follow these steps to get your own instance of CodeExecutor-API up and running in minutes!
Open your terminal and clone this project:
git clone https://github.com/Saannddy/CodeExecutor-API
cd CodeExecutor-APIThe project uses a .env file for configuration. Copy the example to get started:
cp .env.example .env(You can tweak the DATABASE_URL or ports inside .env if needed, but defaults work perfectly!)
Run the entire stack (API + PostgreSQL DB) using Docker Compose:
## FOR LOCAL DB
docker compose --profile local up -d --build
## FOR PRODUCTION
docker compose --profile remote up -d --build-d: Runs containers in the background (detached mode).--build: Ensures all recent code changes are freshly compiled.
On the very first run, the system will automatically:
- Create all database tables (using UUIDs for safety).
- Seed 7+ coding problems (Two Sum, Palindrome, etc.).
- Link problems with their respective categories and tags.
While the system handles initialization automatically, you may need these manual commands for development:
If you modify the models in src/models/, use these commands to sync the database:
- Check Status:
docker compose --profile local exec code-api alembic current - Apply Migrations:
docker compose --profile local exec code-api alembic upgrade head - Generate New Migration:
docker compose --profile local exec code-api alembic revision --autogenerate -m "description_of_change"
If you need to re-seed or reset the initial data:
- Run Seeder:
docker compose --profile local exec code-api python3 -m scripts.seed(The seeder is idempotent and will skip problems that already exist!)
For the most professional development experience, we recommend the following tools:
- ⚡ OrbStack: A fast, light, and easy way to run Docker containers on macOS.
- 🐝 Beekeeper Studio: A smooth and easy-to-use SQL editor and database manager for PostgreSQL.
- 🐶 Bruno: A fast and git-friendly API client for testing the CodeExecutor endpoints.
Since you're up and running, you'll want to know how to talk to the API!
- Detailed Endpoints: See API_DOCUMENTATION.md for full request/response examples.
- Interactive Swagger/Scalar Docs: Visit http://localhost:3000/docs while the app is running.
- OpenAPI Spec: Available at
http://localhost:3000/openapi.yaml.
For the best developer experience, we've included a Bruno Collection:
- Open Bruno.
- Import the folder located at
./bruno. - Start firing requests!
- 🐍 Python (
python) - 🟨 JavaScript (
javascript) - ☕ Java (
java) - 🟦 C (
c) - 🟥 C++ (
cpp)
- 💡 4 Spaces: Always use spaces instead of tabs in your JSON
codestrings. - ⏱️ Timeouts: Most problems are capped at 5 seconds for safety.
- 🔒 Sandboxing: Code runs in a dedicated non-root container environment.
Build with focus on Modular, Scalable, and Professional architecture. ✨