# smartxworks/sunmao-ui architecture

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

- Interactive diagram: https://gitdiagram.com/smartxworks/sunmao-ui
- Repository: https://github.com/smartxworks/sunmao-ui

## Overview

##### Core Architecture Components

a. Core Layer (packages/core)
- Application Manager
- Component Registry
- Trait System
- Scope Management
- Module System

b. Runtime Layer (packages/runtime)
- Component Renderer
- State Management
- Event Handling
- Service Layer
- Trait Implementation

c. Editor Layer (packages/editor)
- Visual Editor Interface
- Component Form Management
- Operations Manager
- Validation System
- Structure Tree

d. Component Libraries
- Arco Components (packages/arco-lib)
- Chakra UI Components (packages/chakra-ui-lib)

##### Key Relationships and Data Flow

**┌─────────────────────────────────────────────────────────┐**
- Editor Layer                        │
- ┤
- ┌─────────────┐  ┌──────────────┐  ┌────────────────┐  │
- Component    │  │Operation      │  │Validation      │  │
- Editor UI    │◄─►│Manager       │◄─►│System         │  │
- ┘  └──────────────┘  └────────────────┘  │
- ▲                ▲                  ▲           │
- ┼────────────────┼──────────────────┼───────────┘

**┌─────────┼────────────────┼──────────────────┼───────────┐**
- ▼                ▼                  ▼           │
- ┌─────────────┐  ┌──────────────┐  ┌────────────────┐  │
- Component    │  │State         │  │Event           │  │
- Runtime      │◄─►│Manager       │◄─►│Handler        │  │
- ┘  └──────────────┘  └────────────────┘  │
- Runtime Layer                          │
- ┘
- ▲                 ▲                  ▲

**┌─────────┼─────────────────┼──────────────────┼──────────┐**
- ▼                 ▼                  ▼          │
- ┌─────────────┐  ┌──────────────┐  ┌────────────────┐  │
- Component    │  │Trait         │  │Module          │  │
- Registry     │◄─►│System        │◄─►│System         │  │
- ┘  └──────────────┘  └────────────────┘  │
- Core Layer                            │
- ┘
- ▲                 ▲

**┌─────────┼─────────────────┼────────────┐**
- ▼                 ▼            │
- ┌─────────────┐  ┌──────────────┐     │
- Arco UI      │  │Chakra UI     │     │
- Components   │  │Components    │     │
- ┘  └──────────────┘     │
- Component Libraries            │
- ┘

##### Important Elements

- Blue: Core system components
- Green: Runtime components
- Orange: Editor components
- Purple: Component libraries

- Connection types:
- Double lines: Data flow

- Labels:
- Clear component names
- Interface points
- Data flow direction
- Key operations

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#e6f3ff,stroke:#2196f3
    classDef runtime fill:#e8f5e9,stroke:#4caf50
    classDef editor fill:#fff3e0,stroke:#ff9800
    classDef library fill:#f3e5f5,stroke:#9c27b0

    %% Editor Layer
    subgraph EditorLayer["Editor Layer"]
        EditorUI["Visual Editor Interface"]
        CompForm["Component Form Management"]
        OpManager["Operations Manager"]
        Validator["Validation System"]
        StructTree["Structure Tree"]
        
        EditorUI <--> CompForm
        CompForm <--> OpManager
        OpManager <--> Validator
        EditorUI <--> StructTree
    end

    %% Runtime Layer
    subgraph RuntimeLayer["Runtime Layer"]
        CompRenderer["Component Renderer"]
        StateManager["State Management"]
        EventHandler["Event Handling"]
        ServiceLayer["Service Layer"]
        TraitImpl["Trait Implementation"]
        
        CompRenderer <--> StateManager
        StateManager <--> EventHandler
        EventHandler <--> ServiceLayer
        ServiceLayer <--> TraitImpl
    end

    %% Core Layer
    subgraph CoreLayer["Core Layer"]
        AppManager["Application Manager"]
        CompRegistry["Component Registry"]
        TraitSystem["Trait System"]
        ModuleSystem["Module System"]
        ScopeManager["Scope Management"]
        
        AppManager <--> CompRegistry
        CompRegistry <--> TraitSystem
        TraitSystem <--> ModuleSystem
        ModuleSystem <--> ScopeManager
    end

    %% Component Libraries
    subgraph CompLibs["Component Libraries"]
        ArcoLib["Arco UI Components"]
        ChakraLib["Chakra UI Components"]
    end

    %% Inter-layer connections
    EditorLayer <--> RuntimeLayer
    RuntimeLayer <--> CoreLayer
    CoreLayer <--> CompLibs

    %% Click events
    click AppManager "https://github.com/smartxworks/sunmao-ui/blob/develop/packages/core/src/application.ts"
    click CompRegistry "https://github.com/smartxworks/sunmao-ui/blob/develop/packages/core/src/component.ts"
    click TraitSystem "https://github.com/smartxworks/sunmao-ui/blob/develop/packages/core/src/trait.ts"
    click ModuleSystem "https://github.com/smartxworks/sunmao-ui/blob/develop/packages/core/src/module.ts"
    click ScopeManager "https://github.com/smartxworks/sunmao-ui/blob/develop/packages/core/src/scope.ts"
    click CompRenderer "https://github.com/smartxworks/sunmao-ui/blob/develop/packages/runtime/src/components/_internal/ImplWrapper/ImplWrapper.tsx"
    click StateManager "https://github.com/smartxworks/sunmao-ui/blob/develop/packages/runtime/src/services/StateManager.ts"
    click EventHandler "https://github.com/smartxworks/sunmao-ui/blob/develop/packages/runtime/src/utils/runEventHandler.ts"
    click ServiceLayer "https://github.com/smartxworks/sunmao-ui/tree/develop/packages/runtime/src/services"
    click TraitImpl "https://github.com/smartxworks/sunmao-ui/tree/develop/packages/runtime/src/traits/core"
    click EditorUI "https://github.com/smartxworks/sunmao-ui/blob/develop/packages/editor/src/components/Editor.tsx"
    click CompForm "https://github.com/smartxworks/sunmao-ui/tree/develop/packages/editor/src/components/ComponentForm"
    click OpManager "https://github.com/smartxworks/sunmao-ui/tree/develop/packages/editor/src/operations"
    click Validator "https://github.com/smartxworks/sunmao-ui/tree/develop/packages/editor/src/validator"
    click StructTree "https://github.com/smartxworks/sunmao-ui/tree/develop/packages/editor/src/components/StructureTree"
    click ArcoLib "https://github.com/smartxworks/sunmao-ui/tree/develop/packages/arco-lib/src/components"
    click ChakraLib "https://github.com/smartxworks/sunmao-ui/tree/develop/packages/chakra-ui-lib/src/components"

    %% Legend
    subgraph Legend
        CoreComp["Core Component"]:::core
        RuntimeComp["Runtime Component"]:::runtime
        EditorComp["Editor Component"]:::editor
        LibraryComp["Library Component"]:::library
    end
```
