Sonar Code Editor is a desktop application built with web technologies. It is structured for high performance, secure offline capabilities, and seamless real-time collaboration — primarily targeting supervised exam and hackathon environments.
| Layer | Technology | Purpose |
|---|---|---|
| Desktop Runtime | Electron | OS-level APIs, window management, IPC |
| UI Framework | React 18 + Vite | Renderer process, component UI |
| Editor Engine | Monaco Editor | VS Code-compatible code editing |
| Collaboration | Yjs + y-websocket | CRDT-based real-time editing |
| Backend (BaaS) | Appwrite | Auth, database, cloud functions |
| File Tree | @knurdz/jack-file-tree | Custom workspace file explorer |
| Editor Tabs | @knurdz/jack-editor-tab | Multi-document tab management |
| Local Persistence | electron-store | Offline log storage |
| PDF Reporting | jsPDF + jsPDF-autotable | Activity report generation |
Sonar uses Electron's multi-process architecture:
Manages the app lifecycle, native OS interactions, and security:
main.ts— App lifecycle,BrowserWindowcreation, CSP headers, deep-link handling (sonar-editor://), macOS Automation permission enforcement.ipcHandlers.ts— Registered IPC handlers for filesystem operations (open/save/read/write files); enforcesenforceTrustedPathsandboxing.collaborationManager.ts— Self-hosted WebSocket server (wslibrary, port1234) implementing they-websocketprotocol. Manages multi-room awareness state and CRDT message broadcasting. Also handles Windows hosted network creation vianetsh.monitoring.ts—MonitoringServicethat tracks keyboard activity, window focus changes, and application events.offlineHeartbeat.ts— Periodic heartbeat signals sent to the renderer for offline-state tracking.securityLog.ts— Structured local security event logging (DevTools opened, app quit, etc.).buildAttestation.ts— Reads a compile-time signedbuild-attestation.jsontoken to identify official production builds vs. dev mode.integrityCheck.ts— Verifies asar archive integrity on startup to detect tampering.staticServer.ts— Local HTTP server for serving static assets inside the preview panel.
- Acts as a secure Context Bridge between Main and Renderer.
- Exposes only safe, explicit APIs via
window.electronAPI(filesystem ops, monitoring controls, security, collaboration, system info). - Prevents full Node.js access from the UI layer;
contextIsolation: true,nodeIntegration: false,sandbox: true.
The React SPA that drives the editor UI:
pages/IDE.tsx— Primary IDE shell: file tree panel, editor panel, preview panel, sidebar, collaboration and settings overlays.pages/Login.tsx— Hackathon/student login flow with Hackathon ID + Student ID + password authentication.components/Editor/— Monaco editor integration, auto-closing tags, LF enforcement, welcome screen.components/Collaboration/— Collaboration panel: host/join session, network interface selection, hosted-network creation.components/FileTree/— File tree wrapper around@knurdz/jack-file-tree.components/Preview/— Sandboxedwebviewtag withlocalhost-only navigation enforcement.components/Settings/— Settings modal with theme (System/Light/Dark) and environment controls.components/Search/— In-workspace file content search.context/AuthContext.tsx— React context for Appwrite authentication state.context/CollaborationContext.tsx— YjsDoc,WebsocketProvidermanagement, awareness, and cursor tracking.services/appwrite.ts— All Appwrite interactions: session management, team login, hackathon lookup, activity log sync, version gating.services/activityLogger.ts— Client-side activity event collection.services/reportGenerator.ts— PDF report creation via jsPDF.services/inviteLinks.ts— Deep-link invite URL generation and parsing.
Real-time collaboration follows the y-websocket protocol:
[Host Machine: Main Process]
└─ CollaborationManager (WebSocketServer on :1234)
└─ Room: "monaco-collab-{teamId}"
├─ Yjs CRDT sync (binary messages)
└─ Awareness state broadcasting
[Client Machine: Renderer Process]
└─ CollaborationContext
└─ WebsocketProvider → ws://{hostIp}:1234/{roomName}
└─ y-monaco binding → Monaco Editor
- Host starts the WS server via IPC (
COLLAB_START_HOST). - Clients connect via IPC (
COLLAB_JOIN_SESSION), which updates local status; the actual Yjs WS connection is made in the renderer'sCollaborationContext. - Awareness (cursor positions, selection) is replayed to late-joining clients using stored awareness states.
- Team isolation — rooms are namespaced by
teamId; connections from different teams are rejected.
The Sonar Web App (Sonar-Web-App/) is a SvelteKit application hosted at sonar.knurdz.org:
- Homepage — Marketing site with feature showcase, live GitHub release feed (fetched at page load via
+page.ts), and OS-aware download CTAs. - Admin Dashboard (
/admin/) — Cloud-based admin panel for managing hackathons, viewing activity logs, and managing sessions. Replaces the in-editor admin panel (removed in beta.6). - Download Page (
/download/) — Platform-specific download options (Homebrew, DMG, Microsoft Store, EXE). - Docs (
/docs/) — User and developer documentation. - Light/Dark theme — Full system-aware theme toggle using CSS
prefers-color-schemeand a manualThemeTogglecomponent.
To serve its primary use case in Supervised/Exam Environments:
- Preview Restriction: The preview panel is a sandboxed
webviewthat interceptswill-navigateandnew-windowevents, blocking any non-localhosttraffic. - Event Tracking: Keystrokes, window focus changes (blur/focus), and copy/paste actions are monitored via the
MonitoringServiceand stored locally viaelectron-store. - Activity Sync: Logs are synced to Appwrite's
Activity Logscollection via thesonar-activity-synccloud function when online. - Offline Resilience: An
offlineHeartbeatdetects connectivity loss; logs continue to accumulate locally and are exported viajsPDFon demand. - Build Attestation: Official production builds include a signed
build-attestation.jsontoken, verified by Appwrite cloud functions to prevent unauthorized client access. - ASAR Integrity Check: On startup,
integrityCheck.tsverifies the application's ASAR bundle hasn't been tampered with. - DevTools Lock: In production, if DevTools is somehow opened, it is immediately closed and a
DEVTOOLS_OPENEDsecurity event is logged. - macOS Automation Permission: On macOS, the app enforces that
System EventsAutomation permission is granted (required for app-switch detection) before the main window is created.