# tencent/cherry-markdown architecture

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

- Interactive diagram: https://gitdiagram.com/tencent/cherry-markdown
- Repository: https://github.com/tencent/cherry-markdown

## Overview

##### Main Components
- Core Engine (packages/cherry-markdown): This is the heart of the editor and contains the syntax parser, renderer (Engine.js, Previewer.js), configuration (Cherry.config.js), hooks (for transforming markdown syntax), and libraries for sanitization and logging.
- UI Editor Layer: This layer uses the core engine to render an interactive markdown editor. It involves components like the toolbar, bubble toolbar, and previewer. In addition, there is a “client” package (packages/client) that implements the UI using frameworks like Vue (as per its App.vue and main.ts) or uses a Tauri integration for desktop apps.
- VSCode Plugin (packages/vscodePlugin): Presented as an integration module that leverages the core functionality of Cherry Markdown to provide an editing experience in VS Code. It has a distinct file set (extension.ts, webview.ts, etc.) and uses similar underlying libraries.

##### Relationships and Interactions
- The Client layer (browser UI and Tauri desktop application) and the VSCode extension are “consumers” of the core engine.
- The configuration files and build scripts (e.g., in packages/cherry-markdown/build, gulpfile.js, rollup configs) are used to compile and bundle the different parts of the system, so include a “Build & Deployment” module node that interacts with each package.
- The examples and tests demonstrate integration points and validate the overall system functionality.

##### Architectural Patterns and Design Principles
- Modular design – Each main feature (core engine, plugin system, UI components) is separated into its own module or package.
- Plugin architecture – The engine is designed to use dynamic imports and allow plugin registration prior to instantiation.
- Separation of concerns – Notice the division between markdown processing (syntax, sanitization, parsing) and the UI/editor components (toolbars, preview panels).
- Support for multiple modes – The system supports both browser-based and server-based rendering (Node.js engine mode) along with integrations for desktop (Tauri) and IDE (VSCode).

##### Technologies and Frameworks
- JavaScript/TypeScript – The core code is written in JavaScript with some modules indicating TypeScript usage.
- CSS/SCSS – There are style sheets for the editor theme, syntax highlighting, and UI customization.
- Build Tools – Tools like Rollup, gulp, and webpack (especially for the VSCode plugin) are used to bundle the modules.
- Tauri – In the client package’s “src-tauri” directory, indicating desktop application support.

##### Detailing Essential Architectural Elements
- To show how configuration and build scripts connect to both core engine and client packages.
- Test and example layers to indicate quality checks (e.g., Jest tests, CommonMark specifications).
- That the extension points are designed for easy modification (custom syntax, toolbar adjustments, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Engine Subgraph
    subgraph "Core Engine (Cherry Markdown)"
        CE1["Engine"]:::core
        CE2["Previewer"]:::core
        CE3["Cherry.config"]:::core
    end

    %% Plugin System Subgraph
    subgraph "Plugin System (Addons)"
        PS1["Mermaid Plugin"]:::plugin
        PS2["PlantUML Plugin"]:::plugin
    end

    %% UI Editor Layer Subgraph
    subgraph "UI Editor Layer (Client)"
        UI1["App.vue"]:::client
        UI2["main.ts"]:::client
    end

    %% VSCode Extension Subgraph
    subgraph "VSCode Extension"
        VS1["extension.ts"]:::vscode
        VS2["webview.ts"]:::vscode
    end

    %% Examples & Test Suites Subgraph
    subgraph "Examples & Tests"
        ET1["Examples"]:::example
        ET2["Test Suites"]:::example
    end

    %% Build & Deployment Subgraph
    subgraph "Build & Deployment"
        BD1["Build Scripts"]:::build
        BD2["GitHub Workflows"]:::build
    end

    %% Relationships and Interactions
    %% UI Editor and VSCode consume Core Engine
    UI1 -->|"consumes"| CE1
    VS1 -->|"consumes"| CE1

    %% Core Engine registers Plugins (using both plugins)
    CE1 -->|"registers"| PS1
    CE1 -->|"registers"| PS2

    %% Build & Deployment builds Core Engine, UI Editor and VSCode Extension
    BD1 -->|"builds"| CE1
    BD1 -->|"builds"| UI1
    BD1 -->|"builds"| VS1
    BD2 -->|"deploys"| CE1
    BD2 -->|"deploys"| UI1
    BD2 -->|"deploys"| VS1

    %% Examples & Tests validate Core Engine
    ET1 -->|"validates"| CE1
    ET2 -->|"validates"| CE1

    %% Styles
    classDef core fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef plugin fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;
    classDef client fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef vscode fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef example fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef build fill:#D1F2EB,stroke:#16A085,stroke-width:2px;

    %% Click Events
    click CE1 "https://github.com/tencent/cherry-markdown/blob/dev/packages/cherry-markdown/src/Engine.js"
    click CE2 "https://github.com/tencent/cherry-markdown/blob/dev/packages/cherry-markdown/src/Previewer.js"
    click CE3 "https://github.com/tencent/cherry-markdown/blob/dev/packages/cherry-markdown/src/Cherry.config.js"
    click PS1 "https://github.com/tencent/cherry-markdown/blob/dev/packages/cherry-markdown/src/addons/cherry-code-block-mermaid-plugin.js"
    click PS2 "https://github.com/tencent/cherry-markdown/blob/dev/packages/cherry-markdown/src/addons/cherry-code-block-plantuml-plugin.js"
    click UI1 "https://github.com/tencent/cherry-markdown/blob/dev/packages/client/src/App.vue"
    click UI2 "https://github.com/tencent/cherry-markdown/blob/dev/packages/client/src/main.ts"
    click VS1 "https://github.com/tencent/cherry-markdown/blob/dev/packages/vscodePlugin/src/extension.ts"
    click VS2 "https://github.com/tencent/cherry-markdown/blob/dev/packages/vscodePlugin/src/webview.ts"
    click ET1 "https://github.com/tencent/cherry-markdown/tree/dev/examples"
    click ET2 "https://github.com/tencent/cherry-markdown/tree/dev/packages/cherry-markdown/test"
    click BD1 "https://github.com/tencent/cherry-markdown/tree/dev/packages/cherry-markdown/build"
    click BD2 "https://github.com/tencent/cherry-markdown/tree/dev/.github/_workflows"
```
