# tencent/kbone architecture

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

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

## Overview

##### Main Components of the System

a) Core Components:
- miniprogram-render: Browser environment simulator
- miniprogram-element: Custom component system
- mp-webpack-plugin: Build system plugin
- kbone-ui: UI component library
- Vue/React adaptation layer

b) Development Tools:
- kbone-cli: Project scaffolding tool
- vue-cli-plugin-kbone: Vue CLI integration

##### System Architecture Layers

**┌─────────────────────────────────────────────┐**
- Application Layer             │
- (Web Applications / Mini Program Pages)    │
- ┤
- Framework Adaptation Layer       │
- (Vue/React/Preact Support)          │
- ┤
- Kbone Core Layer              │
- ┌─────────────┐  ┌────────────────────┐   │
- DOM/BOM     │  │  Custom Component  │   │
- Simulation  │  │     System         │   │
- ┘  └────────────────────┘   │
- ┤
- Build & Tools Layer             │
- (Webpack Plugin, CLI, Development Tools)   │
- ┤
- Platform Runtime Layer             │
- (Web Browser / Mini Program Runtime)    │
- ┘

##### Key Relationships to Highlight

- Blue: Data flow
- Green: Build process flow
- Orange: Runtime interactions

##### Component Details

For each major component, include:
**┌─────────────────────┐**
- Component Name      │
- ┤
- Key Features      │
- Dependencies      │
- Integration Points│
- ┘

##### Implementation Notes

- Browser environment simulation in Mini Program
- Framework adaptation mechanisms
- Build process transformation
- Component lifecycle management
- Cross-platform state management

##### Technical Details

**┌─────────────────────────────────────┐**
- Technical Implementation Details    │
- ┤
- DOM/BOM API Simulation           │
- Custom Component Registration    │
- Build Configuration             │
- Framework Integration           │
- Platform-specific Optimizations │
- ┘

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef platform fill:#e6f3ff,stroke:#666
    classDef core fill:#f9f9f9,stroke:#666
    classDef framework fill:#f0fff0,stroke:#666
    classDef tools fill:#fff0f0,stroke:#666
    classDef ui fill:#fff0e6,stroke:#666

    %% Platform Runtime Layer
    subgraph PlatformLayer["Platform Runtime Layer"]
        WebBrowser["Web Browser"]
        MiniProgram["WeChat Mini Program Runtime"]
    end

    %% Core Layer
    subgraph CoreLayer["Kbone Core Layer"]
        BrowserSim["Browser Environment Simulator"]:::core
        CustomComp["Custom Component System"]:::core
        
        subgraph BrowserSimDetails["Browser Simulation"]
            DOM["DOM Implementation"]:::core
            BOM["BOM Implementation"]:::core
            EventSystem["Event System"]:::core
        end
        
        subgraph CompSystem["Component System"]
            CompCore["Component Core"]:::core
            CompTemplates["Component Templates"]:::core
            CustomComponents["Custom Components"]:::core
        end
    end

    %% Framework Adaptation Layer
    subgraph FrameworkLayer["Framework Adaptation Layer"]
        VueAdapter["Vue Adapter"]:::framework
        ReactAdapter["React Adapter"]:::framework
        PreactAdapter["Preact Adapter"]:::framework
        VueLoader["Vue Improve Loader"]:::framework
        GlobalVarHandler["Global Variable Handler"]:::framework
    end

    %% Build & Tools Layer
    subgraph BuildLayer["Build & Tools Layer"]
        WebpackPlugin["MP Webpack Plugin"]:::tools
        KboneCLI["Kbone CLI"]:::tools
        VueCLIPlugin["Vue CLI Plugin"]:::tools
        BuildTools["Build Tools"]:::tools
    end

    %% UI Components Layer
    subgraph UILayer["UI Components Layer"]
        KboneUI["Kbone UI Library"]:::ui
        CoreComponents["Core Components"]:::ui
        WeUIComponents["WeUI Components"]:::ui
        Styles["UI Styles"]:::ui
    end

    %% Relationships
    BrowserSim --> DOM
    BrowserSim --> BOM
    BrowserSim --> EventSystem
    CustomComp --> CompCore
    CustomComp --> CompTemplates
    CustomComp --> CustomComponents
    
    KboneUI --> CoreComponents
    KboneUI --> WeUIComponents
    KboneUI --> Styles

    WebpackPlugin --> BuildTools
    KboneCLI --> BuildTools
    VueCLIPlugin --> BuildTools

    %% Platform Connections
    CoreLayer --> WebBrowser
    CoreLayer --> MiniProgram

    %% Click Events
    click BrowserSim "https://github.com/Tencent/kbone/tree/develop/packages/miniprogram-render/"
    click DOM "https://github.com/Tencent/kbone/tree/develop/packages/miniprogram-render/src/bom/"
    click EventSystem "https://github.com/Tencent/kbone/tree/develop/packages/miniprogram-render/src/event/"
    click CustomComp "https://github.com/Tencent/kbone/tree/develop/packages/miniprogram-element/"
    click CompCore "https://github.com/Tencent/kbone/tree/develop/packages/miniprogram-element/src/"
    click CompTemplates "https://github.com/Tencent/kbone/tree/develop/packages/miniprogram-element/src/template/"
    click CustomComponents "https://github.com/Tencent/kbone/tree/develop/packages/miniprogram-element/src/custom-component/"
    click WebpackPlugin "https://github.com/Tencent/kbone/blob/develop/packages/mp-webpack-plugin/src/index.js"
    click BuildTools "https://github.com/Tencent/kbone/tree/develop/packages/mp-webpack-plugin/src/tool/"
    click KboneUI "https://github.com/Tencent/kbone/tree/develop/packages/kbone-ui/"
    click CoreComponents "https://github.com/Tencent/kbone/tree/develop/packages/kbone-ui/src/components/"
    click WeUIComponents "https://github.com/Tencent/kbone/tree/develop/packages/kbone-ui/src/weui-components/"
    click Styles "https://github.com/Tencent/kbone/tree/develop/packages/kbone-ui/src/styles/"
    click KboneCLI "https://github.com/Tencent/kbone/tree/develop/packages/kbone-cli/"
    click VueCLIPlugin "https://github.com/Tencent/kbone/tree/develop/packages/vue-cli-plugin-kbone/"
    click VueLoader "https://github.com/Tencent/kbone/tree/develop/packages/vue-improve-loader/"
    click GlobalVarHandler "https://github.com/Tencent/kbone/tree/develop/packages/replace-global-var-loader/"

    %% Legend
    subgraph Legend
        L1["Platform Components"]:::platform
        L2["Core Components"]:::core
        L3["Framework Components"]:::framework
        L4["Build Tools"]:::tools
        L5["UI Components"]:::ui
    end
```
