# alibaba/bizcharts architecture

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

- Interactive diagram: https://gitdiagram.com/alibaba/bizcharts
- Repository: https://github.com/alibaba/bizcharts

## Overview

##### Main Components
- Core Engine and API:
- The chart “core” (found in src/core.ts and related modules) that initializes and manages chart instances.
- The createPlot.tsx and src/index.tsx that serve as entry points.
- Presentation/UI Components:
- Chart and View components (in src/components/Chart, src/components/View).
- g-components and geometry components (e.g., src/g-components, src/geometry) which render lower-level graphics.
- Plot Types:
- A rich set of specific chart types (in src/plots) for area, bar, line, pie, scatter, etc.
- Adapters and Connectors:
- Adapters (in src/adapter) which translate or bridge data and configuration.
- Connectors (in src/connector) that likely help in setting up cross-component interactions such as tooltips.
- Context and State Management:
- Context providers (in src/context) that manage shared state such as canvas, view, and group.
- Utils and Helpers:
- Data transformation utilities (in src/utils/ and src/utils/data-transform) that aid in processing input data.
- Theming and Extensions:
- The theme management files (in src/theme) that define default styles and potentially allow injection of custom themes.

##### Testing and Demos
- Demo Files (demos folder) serve as usage examples and proofs-of-concept for various charts and features.
- Storybook and Story files (in __stories__ and .storybook) show UI states and component interactions.
- Tests (uitest and unittest) indicate how the system is verified at multiple layers (unit tests for components, integration tests for charts).

##### Relationships and Interactions
- The Core Engine receives initialization from createPlot and then orchestrates rendering by invoking geometry components and graphics (g-components).
- Adapters and Context Providers are used throughout to propagate configuration and data updates.
- Utility functions (for data transformation) support the data flow from raw input to visualization.
- The system’s extensibility and error resilience is supported through boundaries (ErrorBoundary components) and connectors that manage cross-component communication (e.g., for synchronized tooltips).

##### Architectural Patterns and Design Principles
- Modular separation: distinct directories (components, g-components, geometry, plots) show that BizCharts is architected in a highly modular fashion.
- Layered abstraction: core engine -> UI components (presentational) -> charts (specific implementations) following a loose “MVC-ish” or “view-controller” separation.
- React Composition: emphasis on reusable, composable components, as seen by the use of numerous React components and context providers.
- Extensibility: the extend folder and adapter patterns suggest a design made to be extended or customized by third-party developers.

##### Details
- Use call-outs or annotations to note the use of React, and mark libraries or frameworks (e.g., the explicit reliance on React, integration with Storybook for component testing, and extensive unit/UITest support).
- Don’t shy away from highlighting the testing infrastructure (“uitest,” “unittest”) separately if it’s relevant to overall system quality assurance.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Core Engine & API
    subgraph "Core Engine & API"
        Core["Chart Core / API Engine"]:::core
    end

    %% UI Components Cluster
    subgraph "UI Components Cluster"
        Chart["Chart Component"]:::ui
        Axis["Axis Component"]:::ui
        Tooltip["Tooltip Component"]:::ui
        Legend["Legend Component"]:::ui
        View["View Component"]:::ui
    end

    %% Graphics Rendering Cluster
    subgraph "Graphics Rendering Cluster"
        GComponents["g-components"]:::graphics
        Geometry["Geometry Components"]:::graphics
    end

    %% Plot Types
    subgraph "Plot Types"
        Plot["Plot Implementations (Chart Types)"]:::plot
    end

    %% Context & State Management
    subgraph "Context & State"
        Context["Context Providers"]:::context
    end

    %% Adapters & Connectors
    subgraph "Adapters & Connectors"
        Adapters["Adapters"]:::adapter
        Connectors["Connectors"]:::adapter
    end

    %% Utilities & Data Transformation
    subgraph "Utilities & Data Transformation"
        Utils["Utilities & Data Transformation"]:::util
    end

    %% Theming & Extensions
    subgraph "Theming & Extensions"
        Theme["Theme Management"]:::theme
        Extensions["Extensions"]:::theme
    end

    %% Testing & Demos / User Input
    subgraph "Testing & Demos"
        Testing["Test & Demos (Storybook, UnitTest, UITest, Demos)"]:::testing
        UserInput["User/Configuration Input"]:::testing
    end

    %% Data Flow and Interactions
    UserInput -->|"data_flow"| Chart
    Chart -->|"init_config"| Core
    Core -->|"internal_state"| Context
    Context -->|"update_state"| Chart

    Chart -->|"render_call"| GComponents
    Chart -->|"render_call"| Geometry

    Chart -->|"compose_chart"| Plot

    Chart -->|"use_adapter"| Adapters
    Chart -->|"use_connector"| Connectors
    Adapters -->|"bridge_data"| Chart
    Connectors -->|"link_events"| Chart

    Tooltip -->|"event_propagation"| Core
    Legend -->|"event_propagation"| Core

    Utils -->|"process_data"| Core
    Utils -->|"process_data"| Chart

    Theme -->|"apply_theme"| Chart
    Extensions -->|"extend_component"| Chart

    Testing -->|"validate"| Core
    Testing -->|"validate"| Chart

    %% Click Events
    click Core "https://github.com/alibaba/bizcharts/blob/master/src/core.ts"
    click Core "https://github.com/alibaba/bizcharts/blob/master/src/createPlot.tsx"
    click Core "https://github.com/alibaba/bizcharts/blob/master/src/index.tsx"
    click Chart "https://github.com/alibaba/bizcharts/tree/master/src/components/Chart"
    click Axis "https://github.com/alibaba/bizcharts/tree/master/src/components/Axis"
    click Tooltip "https://github.com/alibaba/bizcharts/tree/master/src/components/Tooltip"
    click Legend "https://github.com/alibaba/bizcharts/tree/master/src/components/Legend"
    click View "https://github.com/alibaba/bizcharts/tree/master/src/components/View"
    click GComponents "https://github.com/alibaba/bizcharts/tree/master/src/g-components"
    click Geometry "https://github.com/alibaba/bizcharts/tree/master/src/geometry"
    click Plot "https://github.com/alibaba/bizcharts/tree/master/src/plots"
    click Adapters "https://github.com/alibaba/bizcharts/tree/master/src/adapter"
    click Connectors "https://github.com/alibaba/bizcharts/tree/master/src/connector"
    click Context "https://github.com/alibaba/bizcharts/tree/master/src/context"
    click Utils "https://github.com/alibaba/bizcharts/tree/master/src/utils"
    click Utils "https://github.com/alibaba/bizcharts/tree/master/src/utils/data-transform"
    click Theme "https://github.com/alibaba/bizcharts/tree/master/src/theme"
    click Extensions "https://github.com/alibaba/bizcharts/tree/master/src/extend"

    %% Styles
    classDef core fill:#FFC0CB,stroke:#333,stroke-width:2px;
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef graphics fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef plot fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef context fill:#F0E68C,stroke:#333,stroke-width:2px;
    classDef adapter fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef util fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef theme fill:#E6E6FA,stroke:#333,stroke-width:2px;
    classDef testing fill:#F5DEB3,stroke:#333,stroke-width:2px;
```
