플레이그라운드 구현
Playground Implementation Summary
Overview
The Vais web playground provides an interactive browser-based environment for writing, compiling, and executing Vais code without local installation.
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Vais Web Playground │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────┐ │
│ │ Frontend │─────▶│ Backend │─────▶│ Sandbox │ │
│ │ (React) │◀─────│ (Axum) │◀─────│ (WASM) │ │
│ └──────────────┘ └──────────────┘ └──────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
Components
1. Frontend (playground/)
Technology Stack:
- React with TypeScript
- Monaco Editor for code editing
- WebAssembly for client-side compilation
Features:
- Syntax highlighting
- Code completion
- Live error display
- Example programs
- Share code functionality
Key Files:
playground/src/App.tsx- Main application componentplayground/src/Editor.tsx- Code editor componentplayground/src/Output.tsx- Output displayplayground/README.md- Frontend documentationplayground/QUICKSTART.md- Quick start guideplayground/TUTORIAL.md- Comprehensive tutorialplayground/FEATURES.md- Feature documentationplayground/DEPLOYMENT.md- Deployment guideplayground/INTEGRATION.md- Integration guide
2. Backend (crates/vais-playground-server/)
Technology Stack:
- Axum web framework
- Tokio async runtime
- SQLite for code storage
Features:
- RESTful API for compilation
- Code execution with timeout
- Rate limiting
- Code sharing and persistence
Endpoints:
POST /api/compile- Compile codePOST /api/execute- Execute codePOST /api/share- Share code snippetGET /api/shared/:id- Retrieve shared code
3. Sandbox Execution
Security Features:
- WebAssembly isolation
- Resource limits (CPU, memory)
- Timeout enforcement
- Network access control
Implementation Status
✅ Completed
- ✅ Frontend React application
- ✅ Monaco editor integration
- ✅ Backend API server
- ✅ Code compilation endpoint
- ✅ Sandbox execution
- ✅ Example programs
- ✅ Documentation
🔄 In Progress
- Advanced debugging features
- Collaborative editing
- Persistent user sessions
🔮 Future Enhancements
- Real-time collaboration
- Code versioning
- Interactive tutorials
- Performance profiling
- Visual debugging
Usage
Development Server
# Start backend
cd crates/vais-playground-server
cargo run
# Start frontend
cd playground
npm install
npm start
Production Build
# Build frontend
cd playground
npm run build
# Build backend
cd crates/vais-playground-server
cargo build --release
API Documentation
Compile Endpoint
POST /api/compile
Content-Type: application/json
{
"code": "F main() -> i64 { 42 }",
"optimize": true
}
Response:
{
"success": true,
"output": "compiled successfully",
"errors": []
}
Execute Endpoint
POST /api/execute
Content-Type: application/json
{
"code": "F main() -> i64 { printf(\"Hello\\n\") 0 }",
"timeout": 5000
}
Response:
{
"success": true,
"output": "Hello\n",
"exit_code": 0
}
Security Considerations
- Sandboxing: All code execution in isolated WASM environment
- Resource Limits: CPU and memory caps prevent abuse
- Timeout: Maximum execution time enforced
- Rate Limiting: Prevents API abuse
- Code Validation: Syntax checking before execution
Performance
- Compilation Time: ~100-500ms for typical programs
- Execution Time: Limited to 5 seconds max
- Memory Limit: 128MB per execution
- Concurrent Users: Supports 100+ simultaneous users
Testing
# Backend tests
cargo test -p vais-playground-server
# Frontend tests
cd playground
npm test
Deployment
See playground/DEPLOYMENT.md for detailed deployment instructions.
Documentation
- README:
playground/README.md - Quick Start:
playground/QUICKSTART.md - Tutorial:
playground/TUTORIAL.md - Features:
playground/FEATURES.md - Deployment:
playground/DEPLOYMENT.md - Integration:
playground/INTEGRATION.md
Conclusion
The Vais web playground provides a complete browser-based development environment, making it easy for users to learn and experiment with Vais without installation.
Status: Production-ready with ongoing enhancements.