# aisuda/amis-editor-demo architecture

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

- Interactive diagram: https://gitdiagram.com/aisuda/amis-editor-demo
- Repository: https://github.com/aisuda/amis-editor-demo

## Overview

This project is a React-based single‐page demo for the AMIS visual editor. In essence, the system provides a rich, extensible interface where end users can visually edit AMIS JSON schemas and see a live preview of the resulting UI. In addition, the repository maintains multiple built demo versions (with versioned “demo-…” directories) so that historical or beta versions can be previewed online.

##### Overall Architecture and Main Components
- Frontend Application (SPA): At its core, the project runs as a React-based single-page application. The entry point is defined in the “src/index.tsx” along with “src/index.html” – these bootstraps the editor and routing system.
- Editor & Renderer Modules:
– The “src/editor” folder contains code for editor plugins (for example “DisabledEditorPlugin.tsx” and “MyRenderer.tsx”) that extend the AMIS editor.
– The “src/component” folder holds key UI components such as “AMISRenderer.tsx” (which likely renders the AMIS JSON configuration), and “AddPageModal.tsx” for managing the UI channels.
– The “src/renderer” directory shows additional custom renderers, which are integrated with the editor.
- Routing and Pages:
– The “src/route” folder defines different routes like “Editor.tsx”, “Preview.tsx”, and “NotFound.tsx”. This allows a clear separation between the editor view, preview mode, and error handling.
- Global State Management:
– The “src/store” folder houses state management files (e.g., “Page.ts”, “index.ts”). This part likely uses Redux or React’s Context to keep the AMIS JSON schema and editor state in sync.
- Styling and Assets:
– “src/scss” contains the main stylesheet.
- TypeScript Configuration:
– “tsconfig.json” and “package.json” denote a strongly typed codebase with defined dependencies.

##### Demos and Historical Versions
- A large set of “demo-…” directories (e.g. demo-6.11.0, demo-6.7.0, etc.) represent prebuilt artifacts of various released versions. Each demo directory is a self-contained, static version with its own index.html, JavaScript workers (e.g. for CSS, HTML, JSON, TypeScript), fonts, css, and images.
- These directories reflect how the project bundles and deploys different revisions – serving as both a historical record and as distinct deployment targets.

##### Architectural Patterns and Design Principles
- Modular and Extensible Plugin System: The editor is built to allow custom renderers and extension via plugins (as detailed in the readme under “扩充自定义编辑器”). The system design should highlight how plugins are registered (via registerEditorPlugin or by injecting them as properties) and how they hook into the editing lifecycle.
- Separation of Concerns: The application clearly separates presentation (components and renderers), routing (managed in the “route” directory), state management (in the “store”), and configuration (pages.json and scaffold definitions within plugins).
- Versioning and Build Artifacts: The use of multiple “demo-…” folders demonstrates a design choice where the build process generates fully self-contained outputs for each version. This should be depicted as a parallel “build” or “deployment” pipeline that archives historical builds.
- Client-Side Rendering and Worker Scripts: Many demo directories include worker scripts (like css.worker.js, html.worker.js, ts.worker.js), suggesting that the application offloads some code processing (e.g. syntax highlighting or language services) to web workers. It is important to capture the browsers’ multi-threading model in the design.

##### Interactions and Data Flow
- When a user interacts with the editor (for example, changing an AMIS JSON configuration), the change flows from the editor’s UI components in “src/editor” and “src/component” to the state management layer (“src/store”). The updated state is then re-rendered via the “AMISRenderer” component.
- The routing layer handles navigation between the editor, preview mode, and error pages.
- Plugin events (active, beforeInsert, afterInsert, beforeUpdate, etc.) are dispatched during component configuration; these events are integrated using the plugin system’s event listeners and affect the behavior of the editor.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Bootstrap/Entry Point
    subgraph "Frontend Application"
        FB1["src/index.tsx"]
        FB2["src/index.html"]
    end

    %% Routing and Pages
    subgraph "Routing and Pages"
        RP1["src/route/Editor.tsx"]
        RP2["src/route/Preview.tsx"]
        RP3["src/route/NotFound.tsx"]
        RPIndex["src/route/index.tsx"]
    end

    %% Editor Core: Editor Modules and UI Components/Renderers
    subgraph "Editor Core"
        subgraph "Editor Modules"
            EM1["src/editor/DisabledEditorPlugin.tsx"]
            EM2["src/editor/MyRenderer.tsx"]
        end
        subgraph "UI Components/Renderers"
            UIC1["src/component/AMISRenderer.tsx"]
            UIC2["src/component/AddPageModal.tsx"]
            UIC3["src/renderer/MyRenderer.tsx"]
        end
    end

    %% Global State Management
    subgraph "Global State Management"
        State1["src/store/Page.ts"]
        State2["src/store/index.ts"]
    end

    %% Styling and Assets
    subgraph "Styling and Assets"
        Style1["src/scss/style.scss"]
        Style2["src/icons/index.tsx"]
        Pages["src/pages.json"]
    end

    %% Project Configuration
    subgraph "Project Configuration"
        TSConfig["tsconfig.json"]
        Package["package.json"]
    end

    %% Build Output / Demo Versions
    subgraph "Build Output / Demo Versions"
        Demo["demo-* Directories"]
    end

    %% Worker Scripts within Demo Directories
    subgraph "Worker Scripts"
        Worker1["css.worker.js"]
        Worker2["editor.worker.js"]
        Worker3["html.worker.js"]
        Worker4["json.worker.js"]
        Worker5["ts.worker.js"]
    end

    %% Plugin Architecture
    subgraph "Plugin Architecture"
        Plugin["Custom Plugin System\n(registerEditorPlugin, lifecycle events)"]
    end

    %% Connections
    %% Frontend Bootstrap triggers routing and initializes the app.
    FB1 -->|"boots"| RPIndex
    FB2 --> RPIndex

    %% Routing directs to appropriate pages.
    RPIndex -->|"routes to"| RP1
    RPIndex -->|"routes to"| RP2
    RPIndex -->|"routes to"| RP3

    %% Editor Route loads the editor core.
    RP1 -->|"loads"| EM1
    RP1 --> EM2
    EM1 ---|"integrates with"| Plugin
    EM2 --- Plugin

    %% Editor Core UI Components interact with Global State.
    UIC1 -->|"updates"| State1
    UIC1 --> State2
    UIC2 --> State1
    UIC2 --> State2
    UIC3 --> State1
    UIC3 --> State2

    %% State updates trigger re-rendering via AMISRenderer.
    State1 -->|"triggers re-render"| UIC1
    State2 --> UIC1

    %% Styling and Assets support the visual aspects.
    Style1 --- UIC1
    Style2 --- UIC2
    Pages --- UIC1

    %% Project configuration supports the entire project.
    TSConfig --- FB1
    Package --- FB1

    %% Build outputs connect with Worker Scripts.
    Demo -->|"contains"| Worker1
    Demo --> Worker2
    Demo --> Worker3
    Demo --> Worker4
    Demo --> Worker5

    %% Click Events
    click FB1 "https://github.com/aisuda/amis-editor-demo/blob/master/src/index.tsx"
    click FB2 "https://github.com/aisuda/amis-editor-demo/blob/master/src/index.html"
    click EM1 "https://github.com/aisuda/amis-editor-demo/blob/master/src/editor/DisabledEditorPlugin.tsx"
    click EM2 "https://github.com/aisuda/amis-editor-demo/blob/master/src/editor/MyRenderer.tsx"
    click UIC1 "https://github.com/aisuda/amis-editor-demo/blob/master/src/component/AMISRenderer.tsx"
    click UIC2 "https://github.com/aisuda/amis-editor-demo/blob/master/src/component/AddPageModal.tsx"
    click UIC3 "https://github.com/aisuda/amis-editor-demo/blob/master/src/renderer/MyRenderer.tsx"
    click RP1 "https://github.com/aisuda/amis-editor-demo/blob/master/src/route/Editor.tsx"
    click RP2 "https://github.com/aisuda/amis-editor-demo/blob/master/src/route/Preview.tsx"
    click RP3 "https://github.com/aisuda/amis-editor-demo/blob/master/src/route/NotFound.tsx"
    click RPIndex "https://github.com/aisuda/amis-editor-demo/blob/master/src/route/index.tsx"
    click State1 "https://github.com/aisuda/amis-editor-demo/blob/master/src/store/Page.ts"
    click State2 "https://github.com/aisuda/amis-editor-demo/blob/master/src/store/index.ts"
    click Style1 "https://github.com/aisuda/amis-editor-demo/blob/master/src/scss/style.scss"
    click Style2 "https://github.com/aisuda/amis-editor-demo/blob/master/src/icons/index.tsx"
    click Pages "https://github.com/aisuda/amis-editor-demo/blob/master/src/pages.json"
    click TSConfig "https://github.com/aisuda/amis-editor-demo/blob/master/tsconfig.json"
    click Package "https://github.com/aisuda/amis-editor-demo/blob/master/package.json"
    click Demo "https://github.com/aisuda/amis-editor-demo/tree/master/demo-*"
    click Worker1 "https://github.com/aisuda/amis-editor-demo/blob/master/css.worker.js"
    click Worker2 "https://github.com/aisuda/amis-editor-demo/blob/master/editor.worker.js"
    click Worker3 "https://github.com/aisuda/amis-editor-demo/blob/master/html.worker.js"
    click Worker4 "https://github.com/aisuda/amis-editor-demo/blob/master/json.worker.js"
    click Worker5 "https://github.com/aisuda/amis-editor-demo/blob/master/ts.worker.js"

    %% Styles
    class FB1,FB2 bootstrap
    class RP1,RP2,RP3,RPIndex routing
    class EM1,EM2,UIC1,UIC2,UIC3 editorCore
    class State1,State2 state
    class Style1,Style2,Pages styling
    class TSConfig,Package config
    class Demo demo
    class Worker1,Worker2,Worker3,Worker4,Worker5 worker
    class Plugin plugin

    %% Class Definitions with colors
    classDef bootstrap fill:#cce5ff,stroke:#004085,stroke-width:2px,color:#000;
    classDef routing fill:#f8d7da,stroke:#721c24,stroke-width:2px,color:#000;
    classDef editorCore fill:#d4edda,stroke:#155724,stroke-width:2px,color:#000;
    classDef state fill:#fff3cd,stroke:#856404,stroke-width:2px,color:#000;
    classDef styling fill:#e2e3e5,stroke:#6c757d,stroke-width:2px,color:#000;
    classDef config fill:#f5c6cb,stroke:#721c24,stroke-width:2px,color:#000;
    classDef demo fill:#d1ecf1,stroke:#0c5460,stroke-width:2px,color:#000;
    classDef worker fill:#fff,stroke:#6f42c1,stroke-width:2px,color:#000,fill-opacity:0.8;
    classDef plugin fill:#fefbd8,stroke:#e0a800,stroke-width:2px,color:#000;
```
