# matry/editor architecture

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

- Interactive diagram: https://gitdiagram.com/matry/editor
- Repository: https://github.com/matry/editor

## Overview

##### Main System Components

A. Core Editor Layer
- Main editor components from /editor directory:
- State Management (state.js)
- DOM Manipulation (dom.js)
- CSS Object Model (cssom.js)
- Event Handlers (handlers.js)
- Effects System (effects.js)

B. Mode System Layer
- This as a wrapper around the core editor
- Different modes from /editor/modes:
- Normal Mode
- Interactive Mode
- Append Mode
- Project Mode

C. Component Layer
- This above the core editor
- React components from /editor/components:
- Workspace View
- Project View
- Canvas Node
- Style Editor
- File View

D. Extension System
- This on the side
- Extension architecture from /extensions
- Currently highlight the image search extension as an example

E. Overlay System
- This as a top layer
- Components from /overlay:
- Overlay

F. Utility Services
- As a supporting layer
- Utilities from /utils:
- Storage
- Broadcast Channel
- URL Handling

##### Specific Architectural Patterns to Highlight

- Command Pattern: Show how keyboard commands flow through the system
- Observer Pattern: Illustrate the state management and updates
- Component Hierarchy: Demonstrate the React component structure
- Extension System: Show how plugins can integrate

##### Technical Stack Indicators

Technology badges or labels for:
- React (Frontend Framework)
- TypeScript (for type-safe components)
- Tailwind CSS (Styling)
- Vite (Build Tool)

##### Important Relationships

- Command Flow: Keyboard Input → Mode System → Core Editor → State Updates → UI Updates
- Extension Integration: Extension System → Core Editor → Overlay System
- State Management: Core Editor → Component Updates
- File System Interaction: Project View → Storage System

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#a7d8e8,stroke:#333
    classDef mode fill:#b8e6d1,stroke:#333
    classDef component fill:#ffd7b5,stroke:#333
    classDef extension fill:#e6ccff,stroke:#333
    classDef overlay fill:#ffb3b3,stroke:#333
    classDef utility fill:#f2f2f2,stroke:#333

    %% Core Editor Layer
    subgraph CoreEditor["Core Editor Layer"]
        State["State Management"]
        DOM["DOM Manipulation"]
        CSSOM["CSS Object Model"]
        Handlers["Event Handlers"]
        Effects["Effects System"]
    end

    %% Mode System Layer
    subgraph ModeSystem["Mode System Layer"]
        Normal["Normal Mode"]
        Interactive["Interactive Mode"]
        Append["Append Mode"]
        Project["Project Mode"]
    end

    %% Component Layer
    subgraph Components["Component Layer"]
        Workspace["Workspace View"]
        ProjectView["Project View"]
        Canvas["Canvas Node"]
        StyleEditor["Style Editor"]
        FileView["File View"]
    end

    %% Extension System
    subgraph Extensions["Extension System"]
        ImageSearch["Image Search Extension"]
        ExtensionComponent["Extension Component"]
    end

    %% Overlay System
    subgraph Overlays["Overlay System"]
        BoxModel["Box Model Overlay"]
        Outline["Outline Overlay"]
        MainOverlay["Main Overlay"]
        OverlayEvents["Overlay Events"]
    end

    %% Utility Services
    subgraph Utils["Utility Services"]
        Storage["Storage"]
        Broadcast["Broadcast Channel"]
        Color["Color Management"]
        URL["URL Handling"]
    end

    %% Relationships
    ModeSystem --> CoreEditor
    CoreEditor --> Components
    Extensions --> CoreEditor
    CoreEditor --> Overlays
    Utils --> CoreEditor

    %% Click Events
    click State "https://github.com/matry/editor/blob/main/editor/state.js"
    click DOM "https://github.com/matry/editor/blob/main/editor/dom.js"
    click CSSOM "https://github.com/matry/editor/blob/main/editor/cssom.js"
    click Handlers "https://github.com/matry/editor/blob/main/editor/handlers.js"
    click Effects "https://github.com/matry/editor/blob/main/editor/effects.js"
    
    click Normal "https://github.com/matry/editor/blob/main/editor/modes/normal.js"
    click Interactive "https://github.com/matry/editor/blob/main/editor/modes/interactive.js"
    click Append "https://github.com/matry/editor/blob/main/editor/modes/append.js"
    click Project "https://github.com/matry/editor/blob/main/editor/modes/project.js"
    
    click Workspace "https://github.com/matry/editor/blob/main/editor/components/WorkspaceView.jsx"
    click ProjectView "https://github.com/matry/editor/blob/main/editor/components/ProjectView.jsx"
    click Canvas "https://github.com/matry/editor/blob/main/editor/components/CanvasNode.jsx"
    click StyleEditor "https://github.com/matry/editor/blob/main/editor/components/StyleEditor.jsx"
    click FileView "https://github.com/matry/editor/blob/main/editor/components/FileView.jsx"
    
    click ImageSearch "https://github.com/matry/editor/blob/main/extensions/image/ImageSearch.jsx"
    click ExtensionComponent "https://github.com/matry/editor/blob/main/editor/components/Extension.jsx"
    
    click BoxModel "https://github.com/matry/editor/blob/main/overlay/BoxModelOverlay.jsx"
    click Outline "https://github.com/matry/editor/blob/main/overlay/OutlineOverlay.jsx"
    click MainOverlay "https://github.com/matry/editor/blob/main/overlay/Overlay.jsx"
    click OverlayEvents "https://github.com/matry/editor/blob/main/overlay/events.js"
    
    click Storage "https://github.com/matry/editor/blob/main/utils/storage.js"
    click Broadcast "https://github.com/matry/editor/blob/main/utils/broadcast-channel.js"
    click Color "https://github.com/matry/editor/blob/main/utils/colors.js"
    click URL "https://github.com/matry/editor/blob/main/utils/url.js"

    %% Style Applications
    class State,DOM,CSSOM,Handlers,Effects core
    class Normal,Interactive,Append,Project mode
    class Workspace,ProjectView,Canvas,StyleEditor,FileView component
    class ImageSearch,ExtensionComponent extension
    class BoxModel,Outline,MainOverlay,OverlayEvents overlay
    class Storage,Broadcast,Color,URL utility
```
