How pascalx-git/sketchprompt works
Project type and purpose
• SketchPrompt is an OpenVSX-compatible editor extension (e.g., VS Code, Cursor IDE, Windsurf) that provides a rich sketching canvas inside the editor.
• It consists of two runtime components:
a. A TypeScript-based extension “host” that integrates with the editor’s Extension API (commands, custom editors, file watching).
b. A React-based Webview (built with Vite) hosting TLDraw for in-editor sketching.
• It ships also with a static documentation website and an experimental “canvas-experiments” demo app.
File structure
Top-level directories & files:
• src/ → VSCode/OpenVSX extension entry points (extension.ts, SketchPromptCustomEditor.ts)
• media/ → Webview assets & code (sketching-app.tsx, SketchExportService.ts)
• canvas-experiments/ → Standalone React/Vite demo sandbox
• website/ → Static docs site (HTML/CSS/JS, deploy.sh)
• config/build files: vite.config.ts, webpack.config.js, tsconfig.json
• root scripts & docs: package.json, README.md, HELP.md, SECURITY.md, etc.
README insights
• Architecture summary:
• Extension (TypeScript)
• Webview (React + TLDraw)
• Build: Vite for webview, TypeScript compiler/webpack for extension
• Core features: auto-save (debounced), file watching (self-trigger suppression), JSON file schema
Main components & interactions
1. Editor Host (OpenVSX runtime)
2. SketchPrompt Extension (Node/TypeScript)
3. Webview UI (React + TLDraw in an iframe-like panel)
4. File System (local .sketchprompt files)
5. Build Pipeline (Vite → Webview bundle; tsc/webpack → Extension)
6. Static Website (deploy via deploy.sh)
7. Experimental Demo App (canvas-experiments)
b. Relationships & data flows
• Editor Host loads the Extension
• Extension registers commands & custom editor provider
• On “New Sketch” or “Open .sketchprompt”, Extension spawns Webview
• Webview sends “load sketch” request → Extension reads JSON file → returns data
• User draws in Webview → TLDraw emits change events → Webview posts “save” message
• Extension receives save message → debounced write to FS → backup & recovery logic
• File Watcher in Extension monitors FS changes → self-trigger suppression → Webview reload
• Build Pipeline: npm scripts build Webview bundle (vite) and compile Extension (tsc/webpack)
• Static Website lives separately—deployed via deploy.sh
c. Architectural patterns & principles
• MV(VC) pattern: Extension = controller, Webview = view, FS JSON = model
• Message-passing API between Extension & Webview
• Debounce + deep equality for optimized auto-save
• File watcher with suppression to avoid infinite loops
• Local-first, privacy-by-design, no external cloud dependencies
d. Key technologies & frameworks
• OpenVSX/VSCode Extension API (Node + TypeScript)
• React & react-dom + TLDraw for Webview UI
• Vite for webview bundling
• TypeScript & webpack/tsc for extension build
• JSON schema validation, CSP, path traversal protection
Diagramming recommendations
• Use clear labels: “Editor Host”, “SketchPrompt Extension”, “Webview (React+TLDraw)”, “Local FS”
• Extension ↔ Editor API calls
• Extension ↔ Webview message passing (load/save events)
• Extension ↔ File System read/write and file watcher events
• npm scripts → build outputs
• Blue rectangles for runtime components