How zhuochun/simple-editor works
Project Type and Purpose
• This is a client‑side, single‑page web application (“Simple Editor”) for drafting and organizing complex documents in a non‑linear, hierarchical way.
• All data lives in the browser (localStorage or in‑memory) and can be exported/imported as plain text.
• It optionally integrates with external AI “completions” providers (OpenAI, OpenRouter) for automated content generation.
File‐Structure Analysis
• Root assets:
• index.html (entry point)
• style.css (presentation)
• script.js (main orchestrator)
• Feature modules (ES modules loaded by script.js):
• data.js (data model & persistence)
• dragDrop.js (drag‑and‑drop UI interactions)
• cardShortcuts.js (keyboard shortcuts, card manipulation)
• aiService.js (abstraction over external AI API calls)
• Supporting folders:
• docs/ (design specs, versioned API docs, data schema)
• examples/ (sample JSON exports for onboarding)
• No backend “src” or “api” directory: purely front‑end with external REST calls.
README Insights
• Confirms full client‑side execution, run via npx serve.
• AI keys supplied by user, configured in a sidebar.
• Uses any OpenAI‐style completions endpoint (REST).
a. Main Components
• Browser UI Layer
– index.html + CSS + DOM rendering (script.js drives UI)
• Model Layer
– data.js: holds document tree, CRUD, localStorage interface, import/export logic
• Interaction Layer
– dragDrop.js: node repositioning
– cardShortcuts.js: keyboard shortcuts, node operations
• Service Layer
– aiService.js: builds requests, handles API communication with OpenAI/OpenRouter
• External Systems
– OpenAI / OpenRouter REST API endpoints
• Hosting
– Static server (npx serve) delivering HTML/CSS/JS
b. Relationships & Data Flow
1. Browser loads index.html → script.js initializes modules.
2. User interacts via UI → interaction modules (dragDrop, shortcuts) invoke data.js.
3. data.js updates in‑memory model and persists to localStorage.
4. On “AI Draft” action → UI calls aiService → aiService sends HTTP request to external API → receives response → returns to data.js/UI for rendering.
5. Export/Import uses data.js to read/write JSON blobs.
c. Architectural Patterns & Principles
• SPA (single‑page application) with clear separation:
• Model (data.js)
• View (index.html, style.css, render logic in script.js)
• Controller/Services (script.js orchestration + aiService)
• Modular design: each concern in its own JS file
• Service abstraction: decouple AI API details from UI
d. Key Technologies & Frameworks
• Vanilla ES6 JavaScript modules
• HTML5/CSS3 for UI
• Browser localStorage (or IndexedDB) for persistence
• RESTful calls to OpenAI/OpenRouter endpoints
• Node.js npx serve for static hosting