How swiftfiddle/swiftfiddle-runner works
Project Type and Purpose
• This is a backend microservice (“swiftfiddle-runner”) that provides an online sandboxed Swift code execution environment for the SwiftFiddle frontend (swiftfiddle.com).
• It’s implemented in Deno (main.ts, deps.ts), containerized via Docker, and orchestrated locally via docker-compose. CI/CD and deployment are handled through GitHub Actions.
File-Structure Analysis
• Top level:
• main.ts, deps.ts, versions.json → Deno entry point + vendored deps
• Dockerfile, docker-compose.yml → container build & local infra
• _Packages/ → vendored TypeScript modules for offline Deno import
• .github/workflows → CI/CD workflows (test, deploy, UDD)
• No DB or persistent store—execution is ephemeral.
• CI: renovate (dependency updates), test.yml (unit/integration), deploy.yml (build & push container).
README Insights
• Core function: receive Swift source via HTTP, spin up an isolated Docker sandbox, compile/execute, stream results back.
• No additional architecture notes in README.
a. Main Components
• SwiftFiddle Frontend (Browser UI)
• Runner API Service (Deno server)
• Docker Engine (host’s daemon or remote)
• Swift Sandbox Containers (ephemeral Docker containers with Swift toolchain)
• CI/CD Pipeline (GitHub Actions)
b. Relationships & Data Flow
1. Frontend issues HTTP POST → Runner API
2. Runner calls Docker Engine API → create new Swift sandbox container
3. Docker spins up container (mounts user code, runs swift run or swiftc)
4. Container streams stdout/stderr → Runner collects and forwards to frontend
5. Container stops and is destroyed
6. CI/CD: on push → GitHub Actions builds Docker image → pushes to registry → deploys new version of Runner service
c. Architectural Patterns & Principles
• Microservice for isolation of code-execution
• Container-based sandboxing for security and reproducibility
• Ephemeral job processing: no long-lived state, each code run is a self-contained task
d. Key Technologies & Frameworks
• Deno (TypeScript runtime)
• Docker & Docker Engine API
• docker-compose (local dev)
• GitHub Actions (CI/CD)
• Vendored modules in _Packages for deterministic builds