# tencent/wujie architecture

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

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

## Overview

Based on our analysis of the file structure and the README documentation, the project “wujie” is a micro front-end framework that leverages Web Components along with iframes to provide a highly isolated and performant solution for integrating independent sub-applications into a main host. The project is set up as a monorepo and contains several packages (core functionality and framework-specific wrappers) as well as a comprehensive set of examples for various frontend frameworks (Angular, React, Vue, etc).

##### Main Components
- Core Engine (wujie-core): This package (located in packages/wujie-core) is the backbone of the framework. It implements the core APIs, lifecycle management, sandboxing (iframe and shadow DOM based isolation), event handling, and various utilities. Key modules include event management, proxy handling, and isolation mechanisms.
- Framework Integrations: Separate packages (e.g., wujie-react, wujie-vue2, wujie-vue3) provide integrations/wrappers for popular frontend frameworks. They allow developers to easily embed the micro-apps in their projects using idiomatic components.
- Examples/Demos: The “examples” folder contains multiple sample applications for various frameworks (Angular12, main-react, react16, react17, vite, vue2, vue3). These are representative of how the main framework (wujie) is consumed and integrated.
- Documentation & DevOps: The docs folder, along with configuration files (e.g., .github workflows, commit lint settings, husky hooks), represents the support system for documentation, continuous integration, and release management.

##### Relationships and Interactions
- Main Application / Host: The micro front-end host loads the sub-applications into isolated iframes or via Web Components. The host interacts with the core engine (wujie-core) to initialize and manage sub-app lifecycles.
- Core and Framework Wrappers: The core engine provides a standard API (e.g., startApp, preloadApp, destroyApp) and the wrapper packages (for React, Vue) encapsulate these API calls so that they can be easily integrated into framework-specific applications.
- Communication: There is a two-way communication mechanism between the host and sub-applications. This includes lifecycle hooks and decentralized communication channels that facilitate data sharing and synchronization across boundaries.
- Build & Deployment: The project includes scripts (in the “scripts” folder and configuration files in the root and .github directories) that facilitate local development, testing, and building of both the core engine and the sample applications.

##### Important Architectural Patterns and Principles
- Isolation via iframe and Web Components: This is a key principle ensuring that the sub-applications are sandboxed with separate window and document objects.
- Plugin and Lifecycle Management: The framework’s extensibility (through its plugin system) and strict lifecycle hooks are important architectural features.
- Monorepo Structure: Using tools like pnpm and a lerna.json file allows for consolidated dependency management across multiple packages.
- Framework Adapter Pattern: Specialized packages for React, Vue, etc., demonstrate an adapter pattern that abstracts core functionalities into components that align with the developer’s ecosystem.

##### Depicting the Technologies and Frameworks
- That the core uses modern JavaScript/TypeScript practices with supportive tooling like Babel, ESLint, and Webpack.
- The examples and wrappers reflect usage in Angular, React, Vue, and Vite environments, which might be illustrated as separate nodes or modules connected to the core.
- Continuous integration using GitHub workflows and Husky hooks, which ensures code quality and proper commit messages.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host Application
    A["Host Application"]:::host

    %% Core Engine with Modules
    B["wujie-core (Core Engine)"]:::core
    subgraph "Core Modules"
        C["Event Management"]:::core
        D["Proxy Handling"]:::core
        E["Sandbox & Utilities"]:::core
    end

    %% Framework Adapters
    subgraph "Framework Adapters"
        F["wujie-react (React Adapter)"]:::adapter
        G["wujie-vue2 (Vue2 Adapter)"]:::adapter
        H["wujie-vue3 (Vue3 Adapter)"]:::adapter
    end

    %% Sub-Applications / Demos
    subgraph "Sub-Applications"
        I["Angular Sample"]:::sample
        J["Main React Sample"]:::sample
        K["React16 Sample"]:::sample
        L["React17 Sample"]:::sample
        M["Vite Sample"]:::sample
        N["Vue2 Sample"]:::sample
        O["Vue3 Sample"]:::sample
    end

    %% Support & DevOps
    subgraph "Support & DevOps"
        P["Documentation"]:::support
        Q["GitHub Workflows"]:::support
        R["Husky Hooks"]:::support
    end

    %% Annotations for key patterns
    S["iframe隔离<br>Web Components隔离<br>生命周期管理<br>插件系统"]:::note

    %% Connections
    A -->|"init"| B
    B --- S

    %% Core Modules internal connections (for illustration)
    B --> C
    B --> D
    B --> E

    %% Framework Adapters interact with Core Engine
    F -->|"wrapsAPI"| B
    G -->|"wrapsAPI"| B
    H -->|"wrapsAPI"| B

    %% Host Application communicates with Sub-Applications (two-way)
    A <-->|"communication"| I
    A <-->|"communication"| J
    A <-->|"communication"| K
    A <-->|"communication"| L
    A <-->|"communication"| M
    A <-->|"communication"| N
    A <-->|"communication"| O

    %% Support connections
    A -->|"support"| P
    P -->|"workflow"| Q
    P -->|"hooks"| R

    %% Click Events
    click B "https://github.com/tencent/wujie/tree/master/packages/wujie-core"
    click F "https://github.com/tencent/wujie/tree/master/packages/wujie-react"
    click G "https://github.com/tencent/wujie/tree/master/packages/wujie-vue2"
    click H "https://github.com/tencent/wujie/tree/master/packages/wujie-vue3"
    click I "https://github.com/tencent/wujie/tree/master/examples/angular12"
    click J "https://github.com/tencent/wujie/tree/master/examples/main-react"
    click K "https://github.com/tencent/wujie/tree/master/examples/react16"
    click L "https://github.com/tencent/wujie/tree/master/examples/react17"
    click M "https://github.com/tencent/wujie/tree/master/examples/vite"
    click N "https://github.com/tencent/wujie/tree/master/examples/vue2"
    click O "https://github.com/tencent/wujie/tree/master/examples/vue3"
    click P "https://github.com/tencent/wujie/tree/master/docs"
    click Q "https://github.com/tencent/wujie/blob/master/.github"
    click R "https://github.com/tencent/wujie/blob/master/.husky"

    %% Styles
    classDef host fill:#b3ffb3,stroke:#333,stroke-width:2px;
    classDef core fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef adapter fill:#ffd700,stroke:#333,stroke-width:2px;
    classDef sample fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef support fill:#d3d3d3,stroke:#333,stroke-width:2px;
    classDef note fill:#ffe6e6,stroke:#333,stroke-dasharray: 5,5,stroke-width:2px;
```
