# tencent/tmagic-editor architecture

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

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

## Overview

This project is a monorepo for a visual page builder known as “TMagic”. Its primary purpose is to allow developers to quickly set up a visual (low-code) editor for building mobile H5 pages. The core functionality is encapsulated in the editor packages (especially packages/editor) with additional support provided by runtime projects (offering Vue2, Vue3, and React renderers), UI components, forms, and other helper libraries. In essence, TMagic is a visual construction platform that uses a DSL to describe pages and offers both an editor and runtime renderers.

##### Main Components Identification
a. Editor Module:
- Located under packages/editor.
- Provides the core visual editor (with components, services, hooks, layouts, and utility code).
- Interacts with other packages (e.g., core, design, data-source, stage, table) to facilitate editing, undo/redo, event handling, and UI updates.
b. UI and Design System:
- Found in packages/ui, packages/design and the vue/react-components subdirectories.
c. Form and Data Management:
- packages/form supplies form rendering and configuration.
- packages/data-source handles data integration and observed data patterns.
d. Runtime/Rendering Environment:
- The runtime directory contains the actual page rendering projects (Vue2, Vue3, React variations) that use the DSL produced by the editor to display pages.
- playground demonstrates an integrated example, showing how the editor outputs DSL and how the runtime consumes it to render pages.
e. Supporting Libraries:
- Additional packages like packages/core, packages/schema, packages/dep, packages/stage, and packages/table provide low-level support for event management, dependency resolution, node operations, stage layout, drag-resize behaviors, and table components.
f. CLI and Build Tools:
- packages/cli supplies developer tools to bootstrap or manage the project.
- Scripts, configuration files (pnpm-workspace.yaml, tsconfig, eslint configurations) and GitHub workflows help maintain code quality and continuous integration.

##### Architectural Relationships and Interactions
- The Editor (packages/editor) is the hub and produces a DSL (domain-specific language) representing the page configuration.
- UI component libraries (from packages/ui/design and the framework-specific component folders for Vue and React) are referenced by both the Editor and the Runtime projects.
- DataSource and Form packages integrate into the Editor to enable dynamic configuration of components and forms.
- The Runtime projects in the runtime directory load the DSL generated by the Editor to render the final pages. They might, for example, load runtime configurations for Vue (Vue2/Vue3) or React.
- The CLI is used for bootstrapping, building, and possibly releasing individual packages.
- Testing and documentation (present in docs and tests folders) support the overall health and knowledge sharing.

##### Architectural Patterns and Design Principles
- Modular Monorepo: The project is divided into many npm packages, each handling separate responsibilities (editor, UI, form, runtime).
- Component-based Architecture: Both the editor and the UI are built using Vue components (and their React counterparts), emphasizing reusability and isolation.
- DSL-driven Workflow: The editor generates a DSL which is then consumed by runtime renderers to produce the final UI.
- Separation of Concerns: There’s a clear split between the authoring tools (Editor/CLI) and the presentation layer (Runtime).
- Ecosystem Integration: With support for Vue 3 Composition API and TypeScript across packages, the project uses modern JavaScript/TypeScript patterns.

##### Relevant Technologies and Frameworks
- Vue 3.0 (via Composition API) is a key technology for the editor.
- TypeScript is used across packages for strong typing.
- Supporting frameworks include elements from Element-UI (notably in the form packages), along with adapters for Element Plus and TDesign in Vue and React.
- Build and tooling setups with pnpm, Vite, Rollup, ESLint, and Husky for commits and pre-push hook configurations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Editor & Core"
        Editor["Editor (packages/editor)"]:::core
        DSL["DSL (Generated)"]:::core
        FormData["Form & Data (packages/form & packages/data-source)"]:::core
        Editor -->|"generates"| DSL
        FormData -->|"integrates"| Editor

        subgraph "Supporting Libraries"
            Core["Core (packages/core)"]:::core
            Schema["Schema (packages/schema)"]:::core
            Dep["Dep (packages/dep)"]:::core
            Stage["Stage (packages/stage)"]:::core
            Table["Table (packages/table)"]:::core
        end

        Core --> Editor
        Schema --> Editor
        Dep --> Editor
        Stage --> Editor
        Table --> Editor
    end

    subgraph "UI & Design"
        UIC["UI Components (packages/ui)"]:::ui
        DS["Design System (packages/design)"]:::ui
    end

    UIC --> Editor
    DS --> Editor

    subgraph "Runtime Environment"
        RuntimeVue2["Vue2 Renderer (runtime/vue2)"]:::runtime
        RuntimeVue3["Vue3 Renderer (runtime/vue3)"]:::runtime
        RuntimeReact["React Renderer (runtime/react)"]:::runtime
        Playground["Playground (playground)"]:::runtime

        DSL -->|"renders DSL"| RuntimeVue2
        DSL -->|"renders DSL"| RuntimeVue3
        DSL -->|"renders DSL"| RuntimeReact
        DSL -->|"renders DSL"| Playground

        UIC -->|"used_in"| RuntimeVue2
        UIC -->|"used_in"| RuntimeVue3
        UIC -->|"used_in"| RuntimeReact
        UIC -->|"used_in"| Playground
        DS -->|"used_in"| RuntimeVue2
        DS -->|"used_in"| RuntimeVue3
        DS -->|"used_in"| RuntimeReact
        DS -->|"used_in"| Playground
    end

    subgraph "Dev Tools"
        CLI["CLI & Build Tools (packages/cli)"]:::dev
        Docs["Docs & Testing (docs & tests)"]:::dev
    end

    CLI -->|"builds"| Editor
    CLI -->|"builds"| UIC
    CLI -->|"builds"| DS
    Docs -->|"supports"| Editor
    Docs -->|"supports"| UIC
    Docs -->|"supports"| DS
    Docs -->|"supports"| DSL

classDef core fill:#f9f,stroke:#333,stroke-width:2px;
classDef ui fill:#bbf,stroke:#333,stroke-width:2px;
classDef runtime fill:#bfb,stroke:#333,stroke-width:2px;
classDef dev fill:#ffb,stroke:#333,stroke-width:2px;

click Editor "https://github.com/tencent/tmagic-editor/tree/master/packages/editor"
click UIC "https://github.com/tencent/tmagic-editor/tree/master/packages/ui"
click DS "https://github.com/tencent/tmagic-editor/tree/master/packages/design"
click FormData "https://github.com/tencent/tmagic-editor/tree/master/packages/form"
click Core "https://github.com/tencent/tmagic-editor/tree/master/packages/core"
click Schema "https://github.com/tencent/tmagic-editor/tree/master/packages/schema"
click Dep "https://github.com/tencent/tmagic-editor/tree/master/packages/dep"
click Stage "https://github.com/tencent/tmagic-editor/tree/master/packages/stage"
click Table "https://github.com/tencent/tmagic-editor/tree/master/packages/table"
click RuntimeVue2 "https://github.com/tencent/tmagic-editor/tree/master/runtime/vue2"
click RuntimeVue3 "https://github.com/tencent/tmagic-editor/tree/master/runtime/vue3"
click RuntimeReact "https://github.com/tencent/tmagic-editor/tree/master/runtime/react"
click Playground "https://github.com/tencent/tmagic-editor/tree/master/playground"
click CLI "https://github.com/tencent/tmagic-editor/tree/master/packages/cli"
click Docs "https://github.com/tencent/tmagic-editor/tree/master/docs"
```
