# taogreat/vue architecture

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

- Interactive diagram: https://gitdiagram.com/taogreat/vue
- Repository: https://github.com/taogreat/vue

## Overview

##### Project Type and Purpose
- This is the **Vue.js** core repository—a progressive, framework-style **UI library** rather than a traditional full-stack application.
- It provides:
- A core runtime & reactivity system (src/core & src/observer)
- A template compiler (src/compiler)
- Platform-specific adaptors (src/platforms/web, src/platforms/weex)
- A server‐side renderer (src/server & packages/vue-server-renderer)
- Bundled outputs in `dist/` for browser and Node
- Auxiliary packages for template‐only compilation, Weex framework, and renderers

##### File Structure Analysis
- Top-level folders:
- **src/** – source code grouped by responsibility:
– src/compiler – parses Vue templates into render functions
– src/core – the reactive data system, component API, VDOM implementation
– src/platforms – web & Weex compile/runtime adaptations
– src/server – SSR code & webpack integration
– src/sfc – single‐file component parser
– src/shared – cross‐cutting utilities & constants
- **packages/** – independent NPM packages (vue-server-renderer, vue-template-compiler, weex-template-compiler, weex-vue-framework)
- **dist/** – compiled bundles (UMD, ESM, runtime-only, full build)
- **scripts/** – build and release automation
- **benchmarks/** & **examples/** – demonstration and performance testing
- **test/** – unit, SSR, e2e, and Weex test suites
- Build pipeline:   `src/` → **scripts/build.js** & **scripts/config.js** → **dist/** outputs
- CI/config files: CircleCI, ESLint, Flow, TypeScript definitions

##### README Insights
- Emphasizes Vue’s role as a **progressive framework** and lists related ecosystem projects.

- Main Components:
A. **Developer API Layer**
- Global API (Vue.use, mixin, extend)
- Component API (data, props, computed, lifecycle hooks)
B. **Compiler** (src/compiler & vue-template-compiler)
- Template Parser → AST → Codegen → Render Functions
C. **Runtime Core** (src/core + src/observer + src/vdom)
- Reactive state & watcher dispatch
- Virtual DOM creation & patch
D. **Platform Adapters**
- Web runtime & compiler modules (src/platforms/web)
- Weex runtime & compiler modules (src/platforms/weex)
E. **Server‐Side Renderer** (src/server & vue-server-renderer)
- Bundle runner
- Template‐to‐stream / string renderers
F. **Build System & Packaging** (scripts/, Rollup/Webpack plugins in src/server/webpack-plugin)
G. **Distribution** (dist/* bundles)
H. **Examples & Benchmarks** (illustrative frontends, performance tests)
I. **Testing** (test suites verifying each module)

- Relationships & Data Flow:
1. **Source Code** is consumed by **Build Scripts** → produces **dist Bundles** & **NPM Packages**.
2. At runtime (Browser / Node):
- **User Code** → uses **Compiled Vue** (dist/vue.js or runtime-only)
- Vue API invokes **Reactive System** → **VDOM** → **Platform Patch** (DOM ops for web, Weex ops for weex)
3. On SSR:
- **User Components** + **Render Context** → **Server‐Side Renderer** → HTML string/stream

- Architectural Patterns & Principles:
- **Modularization**: clear separation of compiler, core, platform layers
- **Pluggable Platform**: abstraction over DOM operations, directives, patch modules
- **Reactivity + VDOM**: one-way data flow with dependency tracking
- **Incremental Adoption**: runtime-only vs compiler+runtime builds

- Technologies & Frameworks:
- JavaScript w/ Flow types
- Build via Rollup/Webpack (scripts/config.js)
- Linting (ESLint), CI (CircleCI)
- Testing (Jasmine, Nightwatch, e2e harness)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Source Code Modules
    subgraph "Source Code (src/)" 
        direction TB
        subgraph "Compiler" 
            direction TB
            C_index["index.js"]:::core
            C_create["create-compiler.js"]:::core
            C_parser["parser/"]:::core
            C_codegen["codegen/"]:::core
            C_optimizer["optimizer.js"]:::core
        end
        subgraph "Runtime Core" 
            direction TB
            Core_index["index.js"]:::core
            subgraph "Observer"
                direction TB
                Obs_index["index.js"]:::core
                Obs_watcher["watcher.js"]:::core
                Obs_dep["dep.js"]:::core
            end
            subgraph "VDOM"
                direction TB
                VDOM_patch["patch.js"]:::core
                VDOM_create["create-element.js"]:::core
                VDOM_vnode["vnode.js"]:::core
            end
        end
        subgraph "Global API Layer"
            direction TB
            GA_index["global-api/index.js"]:::core
            GA_use["global-api/use.js"]:::core
            GA_mixin["global-api/mixin.js"]:::core
            GA_extend["global-api/extend.js"]:::core
            subgraph "Instance API"
                direction TB
                Inst_events["instance/events.js"]:::core
                Inst_init["instance/init.js"]:::core
                Inst_lifecycle["instance/lifecycle.js"]:::core
                Inst_state["instance/state.js"]:::core
            end
        end
        subgraph "Platform Adapters"
            direction TB
            subgraph "Web"
                direction TB
                Web_runtime["runtime/index.js"]:::platform
                Web_modules["runtime/modules/"]:::platform
                Web_directives["runtime/directives/"]:::platform
                Web_patch["runtime/patch.js"]:::platform
                Web_compiler["compiler/index.js"]:::platform
                Web_cmod["compiler/modules/"]:::platform
                Web_cdir["compiler/directives/"]:::platform
            end
            subgraph "Weex"
                direction TB
                Weex_runtime["runtime/index.js"]:::platform
                Weex_modules["runtime/modules/"]:::platform
                Weex_directives["runtime/directives/"]:::platform
                Weex_patch["runtime/patch.js"]:::platform
                Weex_compiler["compiler/index.js"]:::platform
                Weex_cmod["compiler/modules/"]:::platform
                Weex_cdir["compiler/directives/"]:::platform
            end
        end
        subgraph "Server-Side Renderer"
            direction TB
            SSR_create["create-renderer.js"]:::server
            SSR_render["render.js"]:::server
            SSR_stream["render-stream.js"]:::server
            SSR_bundle["bundle-renderer/"]:::server
        end
    end

    %% Packages
    subgraph "Packages" 
        direction TB
        P_template["vue-template-compiler"]:::core
        P_server["vue-server-renderer"]:::server
    end

    %% Build System
    subgraph "Build System & Packaging"
        direction TB
        Build_scripts["scripts/build.js"]:::build
        Build_config["scripts/config.js"]:::build
        Build_flags["scripts/feature-flags.js"]:::build
        subgraph "Webpack Plugin"
            direction TB
            WP_client["src/server/webpack-plugin/client.js"]:::build
            WP_server["src/server/webpack-plugin/server.js"]:::build
        end
    end

    %% Distribution
    subgraph "Distribution Bundles (dist/)"
        direction TB
        Dist_vue["vue.js"]:::grey
        Dist_runtime["vue.runtime.js"]:::grey
        Dist_common["vue.common.js"]:::grey
        Dist_esm["vue.esm.js"]:::grey
    end

    %% Build Flow
    Source_Code -->|"build"| Build_scripts
    Build_scripts --> Build_config
    Build_config --> WP_client
    Build_config --> WP_server
    Build_scripts -->|"outputs"| Dist_vue
    Build_scripts --> Dist_runtime
    Build_scripts --> Dist_common
    Build_scripts --> Dist_esm
    Build_scripts --> P_template
    Build_scripts --> P_server

    %% Runtime Flow
    UserApp["User Application"]:::grey
    UserApp -->|"imports"| Dist_vue
    Dist_vue -->|"calls API"| GA_index
    GA_index --> Core_index
    Core_index --> Obs_index
    Obs_index --> VDOM_patch
    VDOM_patch -->|"patch DOM"| Web_patch
    VDOM_patch -->|"patch Weex"| Weex_patch

    %% SSR Flow
    UserApp -->|"SSR render"| SSR_create
    SSR_create --> SSR_bundle
    SSR_bundle --> SSR_render
    SSR_render --> SSR_stream

    %% Examples & Tests
    Examples["examples/"]:::grey
    Benchmarks["benchmarks/"]:::grey
    Tests["test/"]:::grey

    Build_scripts --> Examples
    Build_scripts --> Benchmarks
    Build_scripts --> Tests

    %% Click Events
    click C_index "https://github.com/taogreat/vue/blob/dev/src/compiler/index.js"
    click C_create "https://github.com/taogreat/vue/blob/dev/src/compiler/create-compiler.js"
    click C_parser "https://github.com/taogreat/vue/tree/dev/src/compiler/parser/"
    click C_codegen "https://github.com/taogreat/vue/tree/dev/src/compiler/codegen/"
    click C_optimizer "https://github.com/taogreat/vue/blob/dev/src/compiler/optimizer.js"
    click P_template "https://github.com/taogreat/vue/blob/dev/packages/vue-template-compiler/index.js"
    click Build_scripts "https://github.com/taogreat/vue/blob/dev/scripts/build.js"
    click Build_config "https://github.com/taogreat/vue/blob/dev/scripts/config.js"
    click WP_client "https://github.com/taogreat/vue/blob/dev/src/server/webpack-plugin/client.js"
    click WP_server "https://github.com/taogreat/vue/blob/dev/src/server/webpack-plugin/server.js"
    click Dist_vue "https://github.com/taogreat/vue/blob/dev/dist/vue.js"
    click Dist_runtime "https://github.com/taogreat/vue/blob/dev/dist/vue.runtime.js"
    click Dist_common "https://github.com/taogreat/vue/blob/dev/dist/vue.common.js"
    click Dist_esm "https://github.com/taogreat/vue/blob/dev/dist/vue.esm.js"
    click GA_index "https://github.com/taogreat/vue/blob/dev/src/core/global-api/index.js"
    click GA_use "https://github.com/taogreat/vue/blob/dev/src/core/global-api/use.js"
    click GA_mixin "https://github.com/taogreat/vue/blob/dev/src/core/global-api/mixin.js"
    click GA_extend "https://github.com/taogreat/vue/blob/dev/src/core/global-api/extend.js"
    click Inst_events "https://github.com/taogreat/vue/blob/dev/src/core/instance/events.js"
    click Inst_init "https://github.com/taogreat/vue/blob/dev/src/core/instance/init.js"
    click Inst_lifecycle "https://github.com/taogreat/vue/blob/dev/src/core/instance/lifecycle.js"
    click Inst_state "https://github.com/taogreat/vue/blob/dev/src/core/instance/state.js"
    click Core_index "https://github.com/taogreat/vue/blob/dev/src/core/index.js"
    click Obs_index "https://github.com/taogreat/vue/blob/dev/src/core/observer/index.js"
    click Obs_watcher "https://github.com/taogreat/vue/blob/dev/src/core/observer/watcher.js"
    click Obs_dep "https://github.com/taogreat/vue/blob/dev/src/core/observer/dep.js"
    click VDOM_patch "https://github.com/taogreat/vue/blob/dev/src/core/vdom/patch.js"
    click VDOM_create "https://github.com/taogreat/vue/blob/dev/src/core/vdom/create-element.js"
    click VDOM_vnode "https://github.com/taogreat/vue/blob/dev/src/core/vdom/vnode.js"
    click Web_runtime "https://github.com/taogreat/vue/blob/dev/src/platforms/web/runtime/index.js"
    click Web_modules "https://github.com/taogreat/vue/tree/dev/src/platforms/web/runtime/modules/"
    click Web_directives "https://github.com/taogreat/vue/tree/dev/src/platforms/web/runtime/directives/"
    click Web_patch "https://github.com/taogreat/vue/blob/dev/src/platforms/web/runtime/patch.js"
    click Web_compiler "https://github.com/taogreat/vue/blob/dev/src/platforms/web/compiler/index.js"
    click Web_cmod "https://github.com/taogreat/vue/tree/dev/src/platforms/web/compiler/modules/"
    click Web_cdir "https://github.com/taogreat/vue/tree/dev/src/platforms/web/compiler/directives/"
    click Weex_runtime "https://github.com/taogreat/vue/blob/dev/src/platforms/weex/runtime/index.js"
    click Weex_modules "https://github.com/taogreat/vue/tree/dev/src/platforms/weex/runtime/modules/"
    click Weex_directives "https://github.com/taogreat/vue/tree/dev/src/platforms/weex/runtime/directives/"
    click Weex_patch "https://github.com/taogreat/vue/blob/dev/src/platforms/weex/runtime/patch.js"
    click Weex_compiler "https://github.com/taogreat/vue/blob/dev/src/platforms/weex/compiler/index.js"
    click Weex_cmod "https://github.com/taogreat/vue/tree/dev/src/platforms/weex/compiler/modules/"
    click Weex_cdir "https://github.com/taogreat/vue/tree/dev/src/platforms/weex/compiler/directives/"
    click SSR_create "https://github.com/taogreat/vue/blob/dev/src/server/create-renderer.js"
    click SSR_render "https://github.com/taogreat/vue/blob/dev/src/server/render.js"
    click SSR_stream "https://github.com/taogreat/vue/blob/dev/src/server/render-stream.js"
    click SSR_bundle "https://github.com/taogreat/vue/tree/dev/src/server/bundle-renderer/"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef platform fill:#90EE90,stroke:#333,stroke-width:1px
    classDef build fill:#FFA500,stroke:#333,stroke-width:1px
    classDef server fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef grey fill:#D3D3D3,stroke:#333,stroke-width:1px
```
