Skip to content

Andrew1326/code-runner

Repository files navigation

Code Playground

A full-stack code execution platform that allows users to write and execute code in multiple programming languages.

Architecture

The project consists of three main components:

  1. Code Runner (Go) - Executes code in isolated environments
  2. Playground Server (Go) - API server with authentication and MongoDB integration
  3. Playground Client (Next.js) - Frontend web application

Features

  • User authentication (register, login, logout)
  • Code execution in multiple languages (JavaScript, Python, Go, Java, C++, C, Rust)
  • Execution history tracking
  • Real-time code editing with Monaco Editor
  • Secure code execution via isolated code runner

Getting Started

Prerequisites

  • Docker and Docker Compose
  • Go 1.21+ (for local development)
  • Node.js 18+ (for local development)

Quick Start with Docker

  1. Start the code runner:
cd code-runner
docker-compose up -d
  1. Start the playground server:
cd playground-server
docker-compose up -d
  1. Start the playground client:
cd playground-client
npm install
npm run dev

The application will be available at:

Local Development

Code Runner

Already set up. See code-runner/README.md for details.

Playground Server

cd playground-server
go mod download
go run main.go

Make sure MongoDB is running (via Docker or locally).

Playground Client

cd playground-client
npm install
npm run dev

Environment Variables

Playground Server

  • MONGODB_URI - MongoDB connection string (default: mongodb://localhost:27017)
  • DATABASE_NAME - Database name (default: playground)
  • JWT_SECRET - Secret key for JWT tokens
  • PORT - Server port (default: 8080)
  • CODE_RUNNER_URL - Code runner URL (default: http://localhost:8000)

Playground Client

API Endpoints

Authentication

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - Login user
  • GET /api/auth/me - Get current user (protected)

Code Execution

  • POST /api/execute - Execute code (protected)
  • GET /api/executions - Get execution history (protected)

Technology Stack

Backend

  • Go
  • Gin (HTTP framework)
  • MongoDB
  • JWT authentication
  • Docker

Frontend

  • Next.js 14
  • TypeScript
  • Tailwind CSS
  • Monaco Editor
  • Axios
  • React Hot Toast

Security

  • Passwords are hashed using bcrypt
  • JWT tokens for authentication
  • CORS enabled
  • Code execution in isolated Docker containers

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published