This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
SkyCode is a multi-tenant browser-based code editor built with Skykit. It provides a VS Code-like experience with Monaco Editor for code editing and xterm.js for an integrated PTY terminal with real-time command execution via WebSocket.
# Run locally
go run .
# Build
go build -o skycode .
# Run with Docker
docker build -t skycode .
docker run -p 5000:5000 skycode
skycode/
├── main.go # Application entry point, public file serving
├── controllers/
│ ├── code.go # File CRUD, git operations, editor UI
│ ├── terminal.go # SSE command execution (legacy)
│ ├── ws.go # WebSocket PTY terminal (primary)
│ └── admin.go # Admin user management
├── models/
│ ├── database.go # Database connection
│ ├── file.go # File model and operations
│ ├── project.go # Project model (cloned repos, workspaces)
│ └── session.go # Workspace session management
└── views/
├── home.html # Landing page (Vercel-inspired design)
├── editor.html # Monaco + xterm.js editor (loads external scripts)
├── admin.html # Admin dashboard
└── public/
├── scripts/ # Frontend JavaScript modules
│ ├── main.js # Global state, settings, Monaco init
│ ├── terminal.js # PTY terminal multiplexing, resize
│ ├── files.js # File operations, tabs, file tree
│ ├── git.js # Git operations, project management
│ └── search.js # Code search functionality
└── styles/ # CSS stylesheets
└── home.css # Homepage styles (grid bg, animations)
| Concept | Location | Purpose |
|---|---|---|
| File | Database | Source of truth for all user files |
| Project | Database | Tracks cloned repos with RemoteURL for restoration |
| Session | In-memory | Ephemeral workspace, 30-min timeout |
| Workspace | Filesystem | /tmp/skycode/{sessionID}/workspace/ |
| Tool Directory | Filesystem | /tmp/skycode/users/{userID}/ (persists tool installs) |
Editor & Files:
| Route | Method | Handler | Purpose |
|---|---|---|---|
/ |
GET | home.html | Landing page |
/editor |
GET | editor.html | Code editor (requires auth) |
/api/files |
GET | listFiles | List user's files |
/api/files/open |
GET | openFile | Get file content |
/api/files/save |
POST | saveFile | Save file content |
/api/files/rename |
POST | renameFile | Rename a file |
/api/files |
DELETE | deleteFile | Delete a file |
/api/projects |
GET | listProjects | List user's projects |
Git Operations:
| Route | Method | Handler | Purpose |
|---|---|---|---|
/api/workspace/clone |
POST | cloneRepo | Clone a git repository |
/api/git/status |
GET | gitStatus | Get git status for project |
/api/git/stage |
POST | gitStage | Stage files |
/api/git/commit |
POST | gitCommit | Create commit |
/api/git/push |
POST | gitPush | Push to remote |
/api/git/pull |
POST | gitPull | Pull from remote |
/api/git/checkout |
POST | gitCheckout | Checkout branch |
/clone |
GET | handleClone | Public clone endpoint (OAuth flow) |
Terminal:
| Route | Method | Handler | Purpose |
|---|---|---|---|
/api/terminal |
WebSocket | handleTerminalWS | PTY terminal (primary) |
/api/terminals |
GET | listTerminals | List active terminals |
/api/terminals |
POST | createTerminal | Create new terminal |
/api/terminals/{id} |
DELETE | deleteTerminal | Close terminal |
/api/exec |
POST | execCommand | SSE command execution (legacy) |
File - User's code files stored in database:
type File struct {
skykit.Model
OwnerID string // User ID
Path string // e.g., "project/main.go" or "src/utils.go"
Content string
Language string // Detected from extension
}
Project - Tracks cloned repositories and workspaces:
type Project struct {
skykit.Model
OwnerID string // User ID
Name string // Display name
Path string // Directory name in workspace
RemoteURL string // Git remote URL (for re-cloning on restore)
IsDefault bool // If true, this is the default project
}
Session - Ephemeral workspace for terminal execution:
type Session struct {
ID string
UserID string
WorkDir string // /tmp/skycode/{sessionID}/workspace
CreatedAt time.Time
LastUsed time.Time
initialized int32 // atomic flag
}
Data Flow:
Database (source of truth)
↓ MaterializeFiles()
Workspace (ephemeral filesystem)
↓ Terminal/Git operations
Workspace modifications
↓ SyncWorkspaceToDB()
Database (updated)
Session Lifecycle:
MaterializeFiles() called:
RemoteURL are re-cloned (restores .git directory)Why Re-clone?
The .git directory is not stored in the database (too large, binary data). When a session expires and restores, we re-clone repos with RemoteURL to restore full git functionality, then overlay any local file modifications from the database.
PTY Terminal (Primary) - controllers/ws.go:
/ws/terminalgithub.com/creack/ptySSE Terminal (Legacy) - controllers/terminal.go:
/api/execBoth terminals configure identical environments:
cmd.Env = append(os.Environ(),
"HOME="+workDir, // Workspace is home (~ works correctly)
"PATH="+userPath, // Includes user tool directories
"NPM_CONFIG_PREFIX="+..., // npm global installs persist
"GOPATH="+..., // Go installs persist
"CARGO_HOME="+..., // Rust installs persist
)
Directory Structure:
/tmp/skycode/
├── {sessionID}/
│ └── workspace/ # User's workspace (HOME)
│ ├── project1/ # Cloned repo
│ └── project2/ # Another project
├── users/
│ └── {userID}/ # Tool directory (persists across sessions)
│ ├── .local/bin/
│ ├── .npm-global/
│ ├── go/
│ └── .cargo/
└── cache/ # Shared cache
├── npm/
└── go/mod/
Scripts are served from /public/scripts/ (embedded in binary):
| File | Purpose |
|---|---|
main.js |
Global state, user settings, Monaco editor initialization |
terminal.js |
Terminal multiplexing, resize handling, show/hide toggle |
files.js |
File tree, tabs, open/save/rename/delete operations |
git.js |
Git status, staging, commit, push, pull, clone modal |
search.js |
Code search with regex support, result navigation |
Styles are served from /public/styles/ (embedded in binary):
| File | Purpose |
|---|---|
home.css |
Homepage styles: grid background pattern, gradient borders, terminal mockup, feature card hover effects, animations (pulse, blink cursor) |
monaco-editor@0.52.0 (CDN)xterm@5.3.0 (CDN)| Variable | Required | Description |
|---|---|---|
PORT |
No | Server port (default: 5000) |
DB_NAME |
For replica | Database name |
DB_URL |
For replica | LibSQL primary URL |
DB_TOKEN |
For replica | Database JWT token |
OwnerID filter on all queries)safePath() validationisValidGitURL() checks protocol and shell safetyisValidGitRef() prevents command injectionRemoteURLgit clone --depth 1 --branch main --single-branch (shallow clone)
main doesn't existRemoteURL--branch main --single-branch to restore .gitThe Dockerfile includes development tools:
.git in database