How dnisdv/ascii-editor works
Project type and purpose
• This is a browser-based, single-page ASCII art editor built with SvelteKit.
• It uses CanvasKit (Skia + WebAssembly) for canvas rendering, Redux Toolkit for state management, and localStorage for persistence.
File structure
• Top-level “src/routes” directory: SvelteKit routing (layout, pages).
• “src/components”, “src/views”: UI components and view assemblies.
• “src/store”: Redux Toolkit slices (document, layers, tools) and hooks.
• “src/bus”: an event-bus layer to decouple UI events and core logic.
• “src/editor”: core domain logic (canvas, camera, tools, history, serialization).
• “src/api/documents”: persistence API using localStorage.
• Config/bundler files: Vite, Tailwind, Docker, GitHub Actions.
Extract architectural insights from the README
• Single-page app with multi-layer ASCII canvas.
• Undo/Redo via history manager.
• Light/Dark theme support.
• Persistence in browser localStorage.
Main components & their interactions
a. Presentation Layer (Browser)
• SvelteKit routes → Layouts (+layout.svelte), Pages (Editor.svelte, Canvas.svelte)
• Views & re-usable UI components (buttons, menus, dialogs)
b. State Management
• Redux Toolkit store with three slices: document, layers, tools
• Hooks (useSelector, useDispatch) connect UI to store
c. Event Bus
• EditorBusProvider and individual buses (layers, notifications, tools)
• Decouples UI events from core logic
d. Editor Core
• Canvas manager using CanvasKit WASM → renders grid, ASCII characters
• History manager for undo/redo
• Camera & cursor modules
• Spatial indexing (spatial-hashmap) for performance
e. Persistence/API
• Document API abstracts localStorage reads/writes
• Serializer transforms in-memory models to JSON and back
f. External Dependencies
• CanvasKit WASM (Skia)
• SvelteKit, Vite, Tailwind CSS
• Docker for containerization, GitHub Actions for CI/CD
Architectural patterns & design principles
• Layered architecture: Presentation → State → Domain → Persistence
• Event-driven communication via an in-process event bus
• Unidirectional data flow (Redux Toolkit)
• Separation of concerns: UI components vs. editor core logic vs. persistence