# baidu/san architecture

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

- Interactive diagram: https://gitdiagram.com/baidu/san
- Repository: https://github.com/baidu/san

## Overview

##### Main components
- Core API & Component Definition: This is where developers call san.defineComponent (as shown in the README’s quick start). It acts as the entry point and is defined in the “src/main.js” and “src/view/define-component.js” files.
- Template Parser: In the “src/parser” directory, you have multiple specialized modules (like parse-template.js, parse-text.js, and several “read-*.js” files) that work together to convert a component’s template (possibly expressed in HTML-like ANode structures) into an internal/intermediate representation.
- Runtime/Data Binding: The “src/runtime” directory contains modules (data-proxy.js, eval-expr.js, default-filters.js, etc.) that manage the reactive data-binding, changes detection, and evaluation of expressions.
- View & Virtual DOM Management: The “src/view” directory contains logic that transforms parsed templates and runtime changes into actual DOM operations. It includes functions responsible for creating nodes, hydrating components, handling transitions, and managing slots.
- Browser Utilities: The “src/browser” directory includes helper modules for DOM manipulation, event handling, compatibility (like “ie-old-than-9.js”), and other browser-specific operations.
- Utility Functions: The “src/util” directory has helper functions (like bind.js, extend.js, warn.js) that support various tasks across the framework.
- Tooling & Build Process: While not part of the runtime, the “tool” and “types” directories include scripts for building, packaging, development utilities and TypeScript definitions that enable smooth ecosystem integration.

##### Relationships and interactions
- View Layer Integration: From the Runtime, show data and template information being passed to the View module, where components are actually rendered, mounted, and updated. The View layer then interacts with the Browser Utilities to perform DOM operations.

##### Important architectural patterns
- Modular Design: Notice that functionalities are clearly separated into independent modules (parser, runtime, view, browser, util), reflecting a layered architecture.
- Template-to-VM Flow: Emphasize the pattern where the template is first parsed and then becomes a reactive model (ANode) that eventually drives the view updates.
- Cross-Cutting Tools: Recognize that testing, documentation, and build/packaging are handled separately, underscoring good open-source project practices.

##### Relevant technologies/frameworks
- JavaScript is the primary language.
- The framework supports different module systems (examples include AMD, ESNext, TypeScript, and store patterns) as evidenced by the multiple “example/todos-*” directories.
- Browser compatibility utilities in “src/browser” indicate an emphasis on cross-browser support.
- Build and packaging tools are integrated for both development and distribution (look at package.json, appveyor.yml, and the “tool” directory).

- Clear labels on each component (e.g., “Core API”, “Parser”, “Runtime”, “View”, “Browser Utilities”, “Tooling”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    dev["Developer"]:::devStyle
    
    %% Core API & Component Definition Subgraph
    subgraph "Core API & Component Definition"
        direction TB
        coreMain["Core API"]
        defineComponent["Component Definition"]
    end

    %% Main Pipeline Components
    templateParser["Template Parser"]:::parserStyle
    runtime["Runtime/Data Binding"]:::runtimeStyle
    view["View & Virtual DOM Management"]:::viewStyle
    browser["Browser Utilities"]:::browserStyle

    %% Supporting Utility Functions (side support)
    util["Utility Functions"]:::utilStyle

    %% Tooling & Build Process Subgraph
    subgraph "Tooling & Build Process"
        direction TB
        buildTools["Build Tools"]
        typeDefs["Type Definitions"]
    end

    %% Connections for Main Pipeline
    dev -->|"defines"| coreMain
    coreMain -->|"initializes"| defineComponent
    defineComponent -->|"parses"| templateParser
    templateParser -->|"binds"| runtime
    runtime -->|"updates"| view
    view -->|"operatesDOM"| browser

    %% Dashed connections for Utility support
    util -.-> templateParser
    util -.-> runtime
    util -.-> view

    %% Developer interaction with Tooling
    dev -.->|"buildscripts"| buildTools

    %% Styles
    classDef devStyle fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
    classDef coreStyle fill:#AED6F1,stroke:#3498DB,stroke-width:2px;
    classDef parserStyle fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef runtimeStyle fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef viewStyle fill:#F5CBA7,stroke:#E59866,stroke-width:2px;
    classDef browserStyle fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;
    classDef utilStyle fill:#D7DBDD,stroke:#7F8C8D,stroke-dasharray: 5,5,stroke-width:2px;
    classDef toolingStyle fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;

    %% Click Events
    click coreMain "https://github.com/baidu/san/blob/master/src/main.js"
    click defineComponent "https://github.com/baidu/san/blob/master/src/view/define-component.js"
    click templateParser "https://github.com/baidu/san/tree/master/src/parser"
    click runtime "https://github.com/baidu/san/tree/master/src/runtime"
    click view "https://github.com/baidu/san/tree/master/src/view"
    click browser "https://github.com/baidu/san/tree/master/src/browser"
    click util "https://github.com/baidu/san/tree/master/src/util"
    click buildTools "https://github.com/baidu/san/tree/master/tool"
    click typeDefs "https://github.com/baidu/san/tree/master/types"
```
