How mokeyish/obsidian-code-emitter works
Project type and purpose
• This is an Obsidian plugin (“Obsidian Code Emitter”) that lets users execute code blocks interactively in their notes.
• It combines a UI layer (SolidJS-based front end), a plugin runtime layer (Obsidian API), local sandboxing (JavaScript/WebAssembly for JS/TS/Python), and network‐based language execution providers (e.g., Sololearn, play.rust-lang.org).
File structure
• Top‐level config:
• vite.config.ts, tsconfig.json, eslint.config.mjs → build/dev tooling
• manifest.json → Obsidian plugin metadata
• .github/workflows → CI pipelines
• src/
• main.tsx, hmr.ts, setting.ts, solidify.ts → plugin startup, HMR, settings registration
• backend/index.ts → orchestrator: routes code requests to either sandbox or external provider
• backend/languages/*.ts → per‐language configuration (endpoints, transpiling rules)
• backend/providers/*.ts → provider wrappers (Sololearn)
• lib/sandbox/*.ts → JS sandbox implementation (qiankun proxy), Pyodide integration, utility functions
• components/*.tsx/.scss/.css → UI controls: CodeBlock, Play button, Terminal output, Settings tab
• typings/ → ambient type definitions for Obsidian, Electron, etc.
README for additional insights
• Describes supported platforms, languages, execution modes (local sandbox vs. remote request), and security note.
Main components of the system (to show
A. Obsidian Host (plugin loader, UI container)
B. Frontend UI
• CodeBlock component (renders editable code, run button)
• Terminal component (displays output)
• SettingsTab (configures plugin options)
C. Plugin Core (backend/index.ts + store.ts)
• Orchestrator: receives run requests, reads language config, dispatches to sandbox or provider
D. Local Sandbox
• JS Sandbox (qiankun proxy) for JS/TS
• Pyodide for Python
E. Remote Providers
• Sololearn wrapper for C, C++, C#, Go, Java, R, Rust, Swift, etc.
• Direct REST calls (play.haskell.org, play.kotlinlang.org, play.rust-lang.org, vosca.dev, etc.)
F. Network Layer (fetch calls, HTTP)
G. Obsidian Data Store (optional: plugin settings persisted by Obsidian)
Relationships and interactions
1. User clicks “Run” on a CodeBlock → Frontend UI emits an event
2. Event goes to Plugin Core (store/orchestrator)
3. Orchestrator reads language metadata from backend/languages/index.ts
– If language ∈ {js, ts, python} → Local Sandbox path
– Else → Remote Provider path
4. Local Sandbox path
a. JS/TS sandbox: qiankun proxySandbox executes code in an isolated iframe/worker
b. Python sandbox: Pyodide WebAssembly runtime loads via lib/sandbox/common.ts
5. Remote Provider path
a. Build a POST request according to provider config (Sololearn or other endpoint)
b. Send code over HTTP, await compile/execute response
6. Plugin Core receives execution result (stdout, stderr, errors)
7. Sends result back to Frontend → Terminal component renders output
Architectural patterns and design principles
• Clear separation of concerns:
• UI (components) vs. orchestrator (backend/index.ts) vs. execution engines (sandbox/providers)
• Strategy pattern for language execution: each language module declares its “execute” strategy
• Adapter pattern for wrapping third‐party REST endpoints
• Modular: each language & provider in its own file for easy extension
• Secure isolation: local sandboxing via qiankun proxy to prevent host contamination
• [ ] All six main components (Obsidian Host, UI, Core, Sandbox, Providers, Network)
• [ ] Labels for critical paths (strategy selection, fetch calls, sandbox eval)
• [ ] Notation for TypeScript modules, WebAssembly runtime, and HTTP endpoints