# mdx-editor/editor architecture

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

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

## Overview

##### Main Components Identification

The system should be represented with these key components:

a) Core Editor Layer
- MDXEditor Component (entry point)
- Realm with Plugins System
- Lexical Editor Core (underlying framework)

b) Plugin System Architecture
- Core Plugins (text, paragraphs, formatting)
- Extension Plugins (tables, images, code blocks, etc.)
- Toolbar Plugins
- Custom Directive Editors

c) Data Flow Components
- Markdown Import Pipeline
- Markdown Export Pipeline
- MDX/JSX Processing System

- MDXEditor (Central component)
- RealmWithPlugins (Plugin management)
- Lexical Core (Foundation layer)

**Group plugins into categories:**
- Content Plugins (code, images, tables)
- Formatting Plugins (headings, lists, quotes)
- Special Plugins (frontmatter, directives)
- UI Plugins (toolbar, dialogs)

- Markdown Input → Import Pipeline → Internal State
- Internal State → Export Pipeline → Markdown Output
- User Interactions → Plugin System → State Updates

##### Key Relationships to Highlight

- Bidirectional communication between the core editor and plugins
- Visitor pattern implementation for markdown parsing/serialization
- Demonstrate the relationship between toolbar actions and content modifications
- Internationalization (i18n) integration points

##### Technical Details

- Blue: Core editor components
- Green: Plugin system
- Orange: Data transformation layers
- Purple: UI components

Specific technology labels:
- React
- Lexical
- MDX
- CodeMirror (for code editing)

##### Implementation Details

- The plugin-based architecture (src/plugins/* structure)
- The separation between core editing and extension features
- The transformation pipeline between markdown and internal state
- The customization points for directive editors and JSX components

##### Architectural Patterns to Highlight

- Plugin System Architecture
- Visitor Pattern (for markdown processing)
- Component Composition
- Event-driven Updates

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core
        MDX[MDXEditor]
        RP[RealmWithPlugins]
        LC[Lexical Core]
        
        MDX --> RP
        RP --> LC
    end
    
    subgraph "Plugin System"
        CP[Core Plugins]
        EP[Extension Plugins]
        TP[Toolbar Plugins]
        CDE[Custom Directive Editors]
        
        RP --> CP
        RP --> EP
        RP --> TP
        RP --> CDE
    end
    
    subgraph "Content Plugins"
        Code[Code Blocks]
        Img[Images]
        Tbl[Tables]
        
        EP --> Code
        EP --> Img
        EP --> Tbl
    end
    
    subgraph "Formatting Plugins"
        Head[Headings]
        List[Lists]
        Quote[Quotes]
        
        CP --> Head
        CP --> List
        CP --> Quote
    end
    
    subgraph "Special Plugins"
        FM[Frontmatter]
        Dir[Directives]
        
        EP --> FM
        EP --> Dir
    end
    
    subgraph "Data Flow"
        MI[Markdown Import]
        ME[Markdown Export]
        JSX[MDX/JSX Processing]
        
        MI --> MDX
        MDX --> ME
        JSX --> MDX
    end
    
    subgraph "Support Systems"
        I18N[Internationalization]
        Theme[Theme System]
        UI[UI Components]
        
        MDX --> I18N
        MDX --> Theme
        TP --> UI
    end

    classDef core fill:#2374ab
    classDef plugin fill:#2a9d8f
    classDef content fill:#e9c46a
    classDef format fill:#f4a261
    classDef special fill:#e76f51
    classDef data fill:#264653
    classDef support fill:#8338ec

    class MDX,RP,LC core
    class CP,EP,TP,CDE plugin
    class Code,Img,Tbl content
    class Head,List,Quote format
    class FM,Dir special
    class MI,ME,JSX data
    class I18N,Theme,UI support

    click MDX "https://github.com/mdx-editor/editor/blob/main/src/MDXEditor.tsx"
    click RP "https://github.com/mdx-editor/editor/blob/main/src/RealmWithPlugins.tsx"
    click CP "https://github.com/mdx-editor/editor/tree/main/src/plugins/core/"
    click MI "https://github.com/mdx-editor/editor/blob/main/src/importMarkdownToLexical.ts"
    click ME "https://github.com/mdx-editor/editor/blob/main/src/exportMarkdownFromLexical.ts"
    click JSX "https://github.com/mdx-editor/editor/tree/main/src/plugins/jsx/"
    click TP "https://github.com/mdx-editor/editor/tree/main/src/plugins/toolbar/"
    click CDE "https://github.com/mdx-editor/editor/tree/main/src/directive-editors/"
    click I18N "https://github.com/mdx-editor/editor/tree/main/locales/"
    click Theme "https://github.com/mdx-editor/editor/tree/main/src/styles/"
    click Code "https://github.com/mdx-editor/editor/tree/main/src/plugins/codeblock/"
    click Img "https://github.com/mdx-editor/editor/tree/main/src/plugins/image/"
    click Tbl "https://github.com/mdx-editor/editor/tree/main/src/plugins/table/"
    click Head "https://github.com/mdx-editor/editor/tree/main/src/plugins/headings/"
    click List "https://github.com/mdx-editor/editor/tree/main/src/plugins/lists/"
    click Quote "https://github.com/mdx-editor/editor/tree/main/src/plugins/quote/"
    click FM "https://github.com/mdx-editor/editor/tree/main/src/plugins/frontmatter/"
    click Dir "https://github.com/mdx-editor/editor/tree/main/src/plugins/directives/"
    click UI "https://github.com/mdx-editor/editor/tree/main/src/plugins/toolbar/components/"
```
