# RunBin [δΈ­ζ–‡](README.md) | English RunBin is an online code execution and sharing platform that supports running, compiling, and displaying results for multiple programming languages. ## ✨ Features - πŸš€ Online Code Execution - Run code in multiple programming languages - πŸ“ Code Sharing - Share code snippets via unique IDs - 🐳 Docker Isolation - Secure code execution using Docker containers - πŸ’Ύ Flexible Storage - Supports both in-memory and database storage - πŸ”„ Async Processing - Worker processes handle code execution tasks asynchronously - πŸ“Š Performance Stats - Track execution time and memory usage - 🌐 Web Interface - Modern frontend with code editor support ## πŸ—οΈ Architecture The project uses a frontend-backend separation architecture: ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ Web Client │─────▢│ API Server │─────▢│ PostgreSQL β”‚ β”‚ (Vue 3) β”‚ β”‚ (Gin) β”‚ β”‚ Database β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”‚ β”‚ Worker │─────▢│ Docker β”‚ β”‚ Service β”‚ β”‚ Environment β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Components - **Web Client**: Modern frontend application built with Vue 3 + Vite - **API Server**: RESTful API service built with Gin framework - **Worker Service**: Background task processing service for executing user-submitted code - **PostgreSQL**: Persistent storage for code and execution results - **Docker**: Provides secure code execution environment ## πŸ“‹ Prerequisites - Go 1.24.2 or higher - Docker and Docker daemon - PostgreSQL database (optional, for production) - Node.js and npm (for frontend development) ## πŸš€ Quick Start ### 1. Clone the Repository ```bash git clone https://github.com/dreamstarsky/runbin.git cd runbin ``` ### 2. Install Dependencies ```bash # Install Go dependencies go mod download # Install frontend dependencies cd web npm install cd .. ``` ### 3. Setup Database (Optional) If using database storage, create the database and run migrations: ```bash # Create database createdb runbin # Run migrations psql -d runbin -f migrations/0001_init_pastes.sql psql -d runbin -f migrations/0002_create_queue_table.sql psql -d runbin -f migrations/0003_add_compilelog_column.sql ``` ### 4. Configure Services Edit the configuration files: #### API Service Configuration (`config/api.yaml`) ```yaml app: env: "release" # release or debug port: 8080 storage: type: "database" # memory or database database: dsn: "host=localhost port=5432 user=postgres password=password dbname=runbin sslmode=disable" ``` #### Worker Service Configuration (`config/worker.yaml`) ```yaml storage: type: "database" database: dsn: "host=localhost port=5432 user=postgres password=password dbname=runbin sslmode=disable" limit: time: 10.0 # Max execution time (seconds) cpu: 1.0 # CPU limit memory: 512 # Memory limit (MB) size: 1024000 # Output size limit (bytes) process: 1 # Number of worker processes name: "default name" compilerimage: "cpp_gcc-latest:latest" # Compiler image ``` ### 5. Start Services #### Start API Server ```bash go run cmd/api/main.go ``` The API server will run at `http://localhost:8080`. #### Start Worker Service ```bash go run cmd/worker/main.go ``` #### Start Frontend Development Server ```bash cd web npm run dev ``` The frontend will run at `http://localhost:5173`. ## 🐳 Docker Deployment ### Frontend Web Deployment The frontend supports Docker deployment: ```bash cd web docker build -t runbin-web . docker run -d -p 80:80 -e BACKEND_URL=http://your-api-url:8080 runbin-web ``` For detailed frontend deployment instructions, see [web/README.md](web/README.md). > **Note**: API and Worker services do not currently support Docker deployment. Please run them directly with Go. ## πŸ“‘ API Documentation ### Submit Code ```http POST /api/pastes Content-Type: application/json { "code": "your code here", "language": "c++20", "stdin": "input data", "run": true } ``` Response: ```json { "message": "Created", "paste_id": "uuid-string", "url": "/api/pastes/uuid-string" } ``` ### Get Code Result ```http GET /api/pastes/:id ``` Response: ```json { "ID": "uuid-string", "code": "your code here", "language": "c++20", "stdin": "input data", "stdout": "program output", "stderr": "error output", "status": "completed", "compile_log": "compilation output", "execution_time_ms": 100, "memory_usage_kb": 1024, "created_at": "2024-01-01T00:00:00Z", "updated_at": "2024-01-01T00:00:01Z", "backend": "worker-name" } ``` ### Get Supported Languages ```http GET /api/languages ``` Response: ```json { "languages": ["c++20"] } ``` ## πŸ—‚οΈ Project Structure ``` . β”œβ”€β”€ cmd/ β”‚ β”œβ”€β”€ api/ # API service entry point β”‚ └── worker/ # Worker service entry point β”œβ”€β”€ config/ # Configuration files β”‚ β”œβ”€β”€ api.yaml β”‚ └── worker.yaml β”œβ”€β”€ internal/ β”‚ β”œβ”€β”€ config/ # Configuration loading β”‚ β”œβ”€β”€ controller/ # Controller layer β”‚ β”œβ”€β”€ model/ # Data models β”‚ β”œβ”€β”€ repository/ # Data access layer β”‚ β”œβ”€β”€ router/ # Route configuration β”‚ └── worker/ # Worker task processing β”œβ”€β”€ migrations/ # Database migration files β”œβ”€β”€ web/ # Frontend application β”‚ β”œβ”€β”€ src/ # Source code β”‚ β”œβ”€β”€ public/ # Static assets β”‚ └── dist/ # Build output β”œβ”€β”€ workerEnv/ # Worker environment configuration β”œβ”€β”€ go.mod # Go module definition └── LICENSE # Apache 2.0 License ``` ## πŸ”§ Development Guide ### Adding New Language Support 1. Add a new task processor in Worker (refer to `internal/worker/RunCppTask.go`) 2. Prepare the corresponding Docker image 3. Configure the compiler image in `worker.yaml` 4. Update the supported language list in the controller ### Local Development ```bash # Start API in development mode go run cmd/api/main.go # Start Worker in development mode go run cmd/worker/main.go # Start frontend with hot reload cd web && npm run dev ``` ### Build for Production ```bash # Build API go build -o bin/api cmd/api/main.go # Build Worker go build -o bin/worker cmd/worker/main.go # Build frontend cd web && npm run build ``` ## πŸ”’ Security - All code executes in Docker containers, isolated from the host - Configured resource limits (CPU, memory, execution time) - Output size limits to prevent malicious code - CORS configuration to protect API access ## 🀝 Contributing Contributions are welcome! Please follow these steps: 1. Fork the repository 2. Create a feature branch (`git checkout -b feature/AmazingFeature`) 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`) 4. Push to the branch (`git push origin feature/AmazingFeature`) 5. Open a Pull Request ## πŸ“„ License This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for details. ## πŸ“ž Contact For questions or suggestions, please contact us via GitHub Issues. --- Made with ❀️ by dreamstarsky