# lbiddiscombe/wysiwyg-markdown-editor architecture

> Architecture diagram of the GitHub repository lbiddiscombe/wysiwyg-markdown-editor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lbiddiscombe/wysiwyg-markdown-editor
- Repository: https://github.com/lbiddiscombe/wysiwyg-markdown-editor

## Overview

##### Main Components
- Frontend UI – Represent the main Svelte application components:
- The Layout and Page Components in src/routes (e.g., +layout.svelte, +page.svelte)
- The Editor component (src/routes/Editor/Editor.svelte)
- Plugin/Extension System:
- Together as “Markdown Editing Extensions” where each plugin (codePlugin, completions, keyMap, etc.) contributes to the editing experience.
- Reusable Components and Utilities:
- The src/lib folder, which contains UI components (e.g., ExamplePicker.svelte, ThemeToggle.svelte), state management (appState.svelte.ts), examples, and utility functions.
- Testing & Configuration:
- Integration tests and E2E tests (files in e2e, src/demo.spec.ts, page.svelte.test.ts) can be depicted as side modules ensuring quality.
- Third-party Dependencies:
- CodeMirror as the core library for text editing with rich capabilities.

##### Relationships and Interactions
- Data Flow:
- How UI components in the routes layer interact with the underlying plugin system to manage markdown rendering and editing commands.
- Component Dependencies:
- Dependency between the main Editor component and the plugins/extensions which modify the behavior of markdown (e.g., handling slash commands, formatting shortcuts, and widget integrations).
- That the utility modules in src/lib support multiple parts of the application with shared functions and application state.

##### Architectural Patterns and Design Principles
- Modular Architecture:
- That the project is structured to allow extensions and plugin support. This modularity is evident in the clear separation between Editor components and extension modules.
- Separation of Concerns:
- Clearly differentiate between the core layout, state management, UI components, and the specialized markdown processing logic.
- Component Reusability:
- The segregation in src/lib (with UI components and utilities) supports reusability and testability.

##### Relevant Technologies and Frameworks
- Svelte Framework:
- Use of Svelte for UI rendering and component management.
- CodeMirror:
- CodeMirror’s integration, showing how it acts as the engine for text editing.
- Testing Frameworks:
- Mention of testing configurations as evidenced by the presence of Playwright (playwright.config.ts and e2e tests) and Vitest setup (vitest-setup-client.ts).
- Configuration and Build Tools:
- Presence of configuration files (vite.config.ts, svelte.config.js, tsconfig.json) which support the build and development workflow.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main UI
    subgraph "Main UI (Svelte Components)"
        UI1["+layout.svelte"]:::svelte
        UI2["+page.svelte"]:::svelte
    end
    click UI1 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/+layout.svelte"
    click UI2 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/+page.svelte"

    %% Editor Component
    subgraph "Editor"
        ED["Editor.svelte"]:::svelte
    end
    click ED "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/Editor.svelte"

    %% Markdown Extension Plugins
    subgraph "Markdown Extension Plugins"
        EXT_DIR["Extensions Folder"]:::extension
    end
    click EXT_DIR "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/tree/main/src/routes/Editor/extensions"

    subgraph "Plugin Modules"
        PL1["WysiwygPlugin.ts"]:::extension
        PL2["codePlugin.ts"]:::extension
        PL3["completions.ts"]:::extension
        PL4["keyMap.ts"]:::extension
        PL5["lezerExtensions.ts"]:::extension
        PL6["renderBlocks.ts"]:::extension
        PL7["theme.ts"]:::extension
    end
    click PL1 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/WysiwygPlugin.ts"
    click PL2 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/codePlugin.ts"
    click PL3 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/completions.ts"
    click PL4 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/keyMap.ts"
    click PL5 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/lezerExtensions.ts"
    click PL6 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/renderBlocks.ts"
    click PL7 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/theme.ts"

    subgraph "Extension Widgets"
        WID_DIR["Widgets Folder"]:::extension
        W1["BlockWidget.ts"]:::extension
        W2["CopyCodeWidget.ts"]:::extension
        W3["LinkWidget.ts"]:::extension
        W4["MermaidWidget.ts"]:::extension
        W5["SubSupWidget.ts"]:::extension
        W6["TaskMarkerWidget.ts"]:::extension
        W7["mermaidHelper.ts"]:::extension
        W8["index.ts"]:::extension
    end
    click WID_DIR "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/tree/main/src/routes/Editor/extensions/wysiwygMarkdown/widgets"
    click W1 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/widgets/BlockWidget.ts"
    click W2 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/widgets/CopyCodeWidget.ts"
    click W3 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/widgets/LinkWidget.ts"
    click W4 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/widgets/MermaidWidget.ts"
    click W5 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/widgets/SubSupWidget.ts"
    click W6 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/widgets/TaskMarkerWidget.ts"
    click W7 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/widgets/mermaidHelper.ts"
    click W8 "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/Editor/extensions/wysiwygMarkdown/widgets/index.ts"

    %% Reusable Components & Utilities
    subgraph "Reusable Components & Utilities"
        UTIL_DIR["UI Components & State"]:::util
        EXAMPLE_PICK["ExamplePicker.svelte"]:::util
        THEME_TOGGLE["ThemeToggle.svelte"]:::util
        APP_STATE["appState.svelte.ts"]:::util
        UTILS["utils.ts"]:::util
        EXAMPLES_DIR["Markdown Examples"]:::util
    end
    click UTIL_DIR "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/tree/main/src/lib"
    click EXAMPLE_PICK "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/lib/ExamplePicker.svelte"
    click THEME_TOGGLE "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/lib/ThemeToggle.svelte"
    click APP_STATE "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/lib/appState.svelte.ts"
    click UTILS "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/lib/utils.ts"
    click EXAMPLES_DIR "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/tree/main/src/lib/examples"

    %% Testing & Configuration
    subgraph "Testing & Configuration"
        TEST_DIR["Integration & E2E Tests"]:::util
        DEMO_SPEC["src/demo.spec.ts"]:::util
        PAGE_TEST["page.svelte.test.ts"]:::util
        CONFIG_FILES["Configuration Files"]:::util
        VITE["vite.config.ts"]:::util
        SVELTE["svelte.config.js"]:::util
        TSCONF["tsconfig.json"]:::util
        PLAYWRIGHT["playwright.config.ts"]:::util
        VITEST["vitest-setup-client.ts"]:::util
    end
    click TEST_DIR "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/tree/main/e2e"
    click DEMO_SPEC "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/demo.spec.ts"
    click PAGE_TEST "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/src/routes/page.svelte.test.ts"
    click VITE "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/vite.config.ts"
    click SVELTE "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/svelte.config.js"
    click TSCONF "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/tsconfig.json"
    click PLAYWRIGHT "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/playwright.config.ts"
    click VITEST "https://github.com/lbiddiscombe/wysiwyg-markdown-editor/blob/main/vitest-setup-client.ts"

    %% Third-party Dependencies
    subgraph "Third-party Libraries"
        CM["CodeMirror"]:::thirdparty
        MERMAID["Mermaid"]:::thirdparty
    end

    %% Relationships
    UI2 -->|"renders"| ED
    ED -->|"invokes"| EXT_DIR
    ED -->|"uses"| CM
    UTIL_DIR -->|"supports"| UI2
    UTIL_DIR -->|"supports"| ED
    EXT_DIR -->|"communicates"| ED
    TEST_DIR -->|"validates"| ED
    CONFIG_FILES -->|"configures"| ED

%% Styles
classDef svelte fill:#add8e6,stroke:#00008b,stroke-width:2px,rx:5,ry:5;
classDef extension fill:#90ee90,stroke:#006400,stroke-width:2px,rx:5,ry:5;
classDef util fill:#d3d3d3,stroke:#808080,stroke-width:2px,rx:5,ry:5;
classDef thirdparty fill:#dda0dd,stroke:#800080,stroke-width:2px,rx:5,ry:5;
```
