# meituan-dianping/mpvue architecture

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

- Interactive diagram: https://gitdiagram.com/meituan-dianping/mpvue
- Repository: https://github.com/meituan-dianping/mpvue

## Overview

##### Project type and purpose
- This is an open-source front-end framework (“mpvue”) that ports Vue.js (2.x) to multiple mini-program platforms (WeChat, Baidu, Toutiao, Alipay).
- It provides a compiler + runtime core, plus platform-specific plugins and build tooling so that Vue single-file components and render functions output code that runs in each mini-program environment.

##### File structure
- Top-level directories:
- src/         – core compiler, runtime, platform adapters, server (SSR) code
- packages/    – published npm packages (mpvue core, template-compilers, server-renderer, weex framework)
- build/       – build scripts, release automation, CI hooks
- dist/        – compiled bundles for direct CDN/browser use
- examples/    – sample apps demonstrating features
- benchmarks/  – performance tests for big-table, SSR, SVG, etc.
- test/        – unit & e2e tests separated by feature/platform
- Key patterns:
- Monorepo style – multiple related packages under one repo
- Compiler+runtime separation – src/compiler vs src/core
- Platform adapters – src/platforms/{mp,web,weex}
- Server-side rendering – src/server
- Configuration files:
- .babelrc, .eslintrc, flowconfig, package.json
- build/config.js, build/build.js
- circle.yml for CI

##### Insights from the README
- States mpvue is “Vue in mini programs,” preserving runtime reactivity & component model.
- Highlights support for multiple mini-program platforms and integration with webpack, Vue CLI, Vuex.
- Mentions companion projects (mpvue-loader, mpvue-webpack-target).

##### Top-level components
a. Core compiler & runtime
- Compiler: template parser → AST → codegen → render functions
- Runtime: reactive system, virtual DOM, component lifecycle, global API
b. Platform adapters
- mp (mini-program): compiler plugin + runtime shim mapping VDOM → mini-program API
- web: standard DOM runtime + full compiler
- weex: weex-specific runtime + compiler modules
c. Server-Side Rendering
- bundle-renderer, optimizing-compiler, template-renderer
d. Published packages (npm)
- mpvue (entry point for mp)
- mpvue-template-compiler, vue-template-compiler, weex-template-compiler
- vue-server-renderer
- weex-vue-framework
e. Build & Tooling
- build scripts (build/, dist/)
- webpack loader target (mpvue-loader, mpvue-webpack-target)
- CLI integration (vue-cli plugin)
f. Tests & Examples
- test/ for unit/e2e, examples/ and benchmarks/

##### Relationships and interactions
- Developer writes .vue files + Vuex store
- webpack + mpvue-loader invokes template compiler → produces JS render functions + JSON/ WXML/ WXSS
- Code invokes mpvue runtime (core + platform-adapter)
- Runtime renders to platform API (mini-program lifecycle, setData calls)
- SSR path: server create-renderer uses optimizing-compiler + renderers to produce HTML/stream
- Packaging: build scripts roll up source into dist/*.js for direct browser use

##### Architectural patterns & design principles
- Layered architecture: core → platform plugins → entry packages
- Plugin/adapter pattern: each platform implements the same compiler/runtime interface
- Monorepo modularization: share code via src/shared, src/sfc, types, build common code once
- CI/CD integration: automated builds, tests per platform

##### Final advice
- Be detailed: break “src/platforms/mp” into compiler vs runtime sub-components
- Monorepo structure and how each sub-package is published and consumed

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Developer flow
    Developer["Developer (.vue files, Vuex)"]:::other
    CLI["Vue CLI / Webpack"]:::other
    Loader["mpvue-loader"]:::other

    %% Core pipeline
    CoreComp["Core Compiler"]:::core
    AST["AST Parser"]:::core
    Codegen["Codegen"]:::core
    Bundle["Render Functions + JSON/WXML/WXSS"]:::core
    CoreRuntime["Core Runtime"]:::core

    %% Platform adapters
    subgraph "Platform Adapters"
        MPComp["MP Compiler"]:::adapter
        MPRuntime["MP Runtime"]:::adapter
        WebComp["Web Compiler"]:::adapter
        WebRuntime["Web Runtime"]:::adapter
        WeexComp["Weex Compiler"]:::adapter
        WeexRuntime["Weex Runtime"]:::adapter
    end
    PlatformAPI["Platform API\n(mini-program, DOM, Weex)"]:::other

    %% SSR modules
    subgraph "Server-Side Rendering"
        BundleRenderer["Bundle Renderer"]:::ssr
        OptCompiler["Optimizing Compiler"]:::ssr
        TemplateRenderer["Template Renderer"]:::ssr
        SSROut["HTML/Stream Output"]:::ssr
    end

    %% Packaging & tools
    subgraph "Build & Packaging"
        BuildScript["build/build.js"]:::packaging
        Config["build/config.js"]:::packaging
        Dist["dist/"]:::packaging
    end

    %% Published packages
    subgraph "Published NPM Packages"
        PkgMPVue["mpvue (entry)"]:::other
        PkgMPComp["mpvue-template-compiler"]:::other
        PkgVueComp["vue-template-compiler"]:::other
        PkgWeexComp["weex-template-compiler"]:::other
        PkgSSR["vue-server-renderer"]:::other
        PkgWeexFW["weex-vue-framework"]:::other
    end

    %% Examples & tests
    subgraph "Examples & Tests"
        Examples["examples/"]:::other
        Bench["benchmarks/"]:::other
        Tests["test/"]:::other
    end

    %% Build-time flow
    Developer --> CLI --> Loader --> CoreComp --> AST --> Codegen --> Bundle --> CoreRuntime
    CoreRuntime --> MPComp --> MPRuntime --> PlatformAPI
    CoreRuntime --> WebComp --> WebRuntime --> PlatformAPI
    CoreRuntime --> WeexComp --> WeexRuntime --> PlatformAPI

    %% SSR flow
    Developer --> BundleRenderer --> OptCompiler --> TemplateRenderer --> SSROut

    %% Packaging flow
    BuildScript --> Dist
    Config --> Dist

    %% Package mappings
    PkgMPVue --> MPComp
    PkgMPVue --> MPRuntime
    PkgMPComp --> MPComp
    PkgVueComp --> WebComp
    PkgWeexComp --> WeexComp
    PkgSSR --> BundleRenderer
    PkgWeexFW --> WeexRuntime

    %% Click events
    click CoreComp "https://github.com/meituan-dianping/mpvue/blob/master/src/compiler/index.js"
    click CoreRuntime "https://github.com/meituan-dianping/mpvue/blob/master/src/core/index.js"
    click MPComp "https://github.com/meituan-dianping/mpvue/blob/master/src/platforms/mp/compiler/index.js"
    click MPRuntime "https://github.com/meituan-dianping/mpvue/blob/master/src/platforms/mp/runtime/index.js"
    click WebComp "https://github.com/meituan-dianping/mpvue/blob/master/src/platforms/web/compiler/index.js"
    click WebRuntime "https://github.com/meituan-dianping/mpvue/blob/master/src/platforms/web/runtime/index.js"
    click WeexComp "https://github.com/meituan-dianping/mpvue/blob/master/src/platforms/weex/compiler/index.js"
    click WeexRuntime "https://github.com/meituan-dianping/mpvue/blob/master/src/platforms/weex/runtime/index.js"
    click BundleRenderer "https://github.com/meituan-dianping/mpvue/blob/master/src/server/bundle-renderer/create-bundle-renderer.js"
    click OptCompiler "https://github.com/meituan-dianping/mpvue/blob/master/src/server/optimizing-compiler/index.js"
    click TemplateRenderer "https://github.com/meituan-dianping/mpvue/blob/master/src/server/template-renderer/index.js"
    click PkgMPVue "https://github.com/meituan-dianping/mpvue/blob/master/packages/mpvue/index.js"
    click PkgMPComp "https://github.com/meituan-dianping/mpvue/blob/master/packages/mpvue-template-compiler/index.js"
    click PkgVueComp "https://github.com/meituan-dianping/mpvue/blob/master/packages/vue-template-compiler/index.js"
    click PkgWeexComp "https://github.com/meituan-dianping/mpvue/blob/master/packages/weex-template-compiler/index.js"
    click PkgSSR "https://github.com/meituan-dianping/mpvue/blob/master/packages/vue-server-renderer/index.js"
    click PkgWeexFW "https://github.com/meituan-dianping/mpvue/blob/master/packages/weex-vue-framework/index.js"
    click BuildScript "https://github.com/meituan-dianping/mpvue/blob/master/build/build.js"
    click Config "https://github.com/meituan-dianping/mpvue/blob/master/build/config.js"
    click Dist "https://github.com/meituan-dianping/mpvue/tree/master/dist/"
    click Examples "https://github.com/meituan-dianping/mpvue/tree/master/examples/"
    click Bench "https://github.com/meituan-dianping/mpvue/tree/master/benchmarks/"
    click Tests "https://github.com/meituan-dianping/mpvue/tree/master/test/"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000000
    classDef adapter fill:#90EE90,stroke:#000000
    classDef ssr fill:#FFA500,stroke:#000000
    classDef packaging fill:#DDA0DD,stroke:#000000
    classDef other fill:#D3D3D3,stroke:#000000
```
