# ant-design/ant-design-charts architecture

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

- Interactive diagram: https://gitdiagram.com/ant-design/ant-design-charts
- Repository: https://github.com/ant-design/ant-design-charts

## Overview

##### Project Type and Purpose
- It’s an open‑source, React‑based charting library published under one npm package (@ant‑design/charts) and composed of several internal packages.
- Purpose: provide ready‑made chart and graph components (statistical charts, graph layouts) on top of AntV engines (G2, G6, X6, L7), plus documentation site, examples, build & release tooling.

##### File Structure
- Root:
– Configuration: babel, eslint, prettier, tsconfig, pnpm-workspace.yaml
– CI/CD: .github/workflows (lint, test, release, site‐publish)
– Scripts: code generators (ast3.0), docs/tools, website build
– Tests: unit tests under tests/ and package‑specific tests
- packages/ (monorepo packages):
– charts/ – aggregation of high‑level React components (Line, Bar, etc.)
– graphs/ – graph layouts (dendrogram, mind‑map, network)
– plots/ – statistical plots (pie, histogram, scatter, etc.)
– util/  – shared utilities and common React wrappers (error boundary, loading)
- site/ – Dumi‑powered documentation & demo website, built from site/docs, site/examples
- public/, template/ – static assets & template engines used during site build

##### README Insights
- Confirms React + TypeScript stack
- Uses pnpm for workspace management
- Build: webpack & vite for local dev, tsconfig for type checking
- Testing: Jest + Playwright
- Publication: automated via GitHub Actions

##### Main Components to Illustrate
a. Package Modules (monorepo packages):
– util (core helpers, React wrappers)
– plots (imports util, core adaptor, renderers)
– graphs (imports util, graph core, behaviors, registry)
– charts (public API, re‑exports selected plots & graphs)
b. External Dependencies:
– AntV engines: G2 (for plots), G6/X6 (for graphs), L7 (for geo, maps)
– React & ReactDOM
– Styling linters, bundlers
c. Developer Tooling:
– Build pipelines (webpack/vite configurations per package)
– Scripts: ast3.0 (example codegen), docs generators
– Documentation site (Dumi)
– CI/CD workflows: lint → test → build → deploy (npm, GitHub Pages)
d. Consumers:
– npm install @ant‑design/charts → import specific components (e.g. import { Line } from '@ant-design/charts')
– Documentation site to browse options, examples

##### Relationships & Data Flow
- util → plots & graphs (shared code)
- plots & graphs → charts (charts package re‑exports both)
- scripts (ast3.0) → generate example code → site/examples
- site/docs + site/examples + Dumi config → documentation site build → GitHub Pages
- CI/CD pipeline triggers on push:
1. lint (eslint, stylelint)
2. unit tests (Jest)
3. build packages (webpack, tsc)
4. publish to npm
5. deploy docs site
- Consumer apps ↔ charts package (via npm)

##### Architectural Patterns & Principles
- Monorepo managed by pnpm-workspace.yaml
- Modular micro‑packages for clear separation of concerns
- Shared utilities to avoid duplication
- Automated generation of examples & docs for consistency
- CI/CD as code (GitHub Actions workflows)
- Documentation-first approach (Dumi / mdx)

##### Detailed Capture
- Don’t just show “charts → React”; drill into “charts package” and its direct use of plots & graphs.
- How util sits at the foundation.
- Scripts feeding into site/examples and then into site build.
- Which GitHub Actions workflows target which components (e.g. test.yml vs. publish.yml).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Core Packages"
        util["util"]:::package
        plots["plots"]:::package
        graphs["graphs"]:::package
        charts["charts"]:::package
    end

    subgraph "External Dependencies"
        G2["G2"]:::external
        G6["G6/X6"]:::external
        L7["L7"]:::external
        React["React & ReactDOM"]:::external
    end

    subgraph "Tooling & Scripts"
        pnpm["pnpm-workspace.yaml"]:::config
        babel[".babelrc"]:::config
        eslint[".eslintrc.js"]:::config
        prettier[".prettierrc.js"]:::config
        tsconfig["tsconfig.json"]:::config
        jestconfig["jest.config.js"]:::config
        webpackcfg["config/webpack.js"]:::config
        jestsetup1["config/jest.js"]:::config
        jestsetup2["config/setup.js"]:::config
        ast["AST Codegen (scripts/ast3.0)"]:::script
        docsgen["Docs Generator (scripts/docs/g2plot.mjs)"]:::script
        examplesParser["Examples Parser (scripts/ast3.0/examples-parser)"]:::script
    end

    subgraph "Documentation Site"
        docs["site/docs"]:::docs
        examples["site/examples"]:::examples
        dumi["Dumi Site Build"]:::docs
        public["public"]:::static
        template["template"]:::static
    end

    subgraph "CI/CD Pipeline"
        workflows[".github/workflows"]:::ci
    end

    subgraph "Consumers"
        consumer["Consumer App"]:::consumer
    end

    util -->|imports| plots
    util -->|imports| graphs
    plots -->|re-exports| charts
    graphs -->|re-exports| charts
    charts -->|published npm package| consumer
    charts -->|depends on| React
    plots -->|render with| G2
    graphs -->|render with| G6
    graphs -->|render with| L7

    ast -->|generates examples into| examples
    docsgen -->|generates docs into| docs
    examples -->|included in| dumi
    docs -->|included in| dumi
    public -->|assets for| dumi
    template -->|templates for| dumi

    babel -->|used in| workflows
    eslint -->|used in| workflows
    prettier -->|used in| workflows
    tsconfig -->|used in| workflows
    jestconfig -->|used in| workflows
    webpackcfg -->|used in| workflows
    jestsetup1 -->|used in| workflows
    jestsetup2 -->|used in| workflows
    workflows -->|build & publish packages| charts
    workflows -->|deploy docs site| dumi

    classDef package fill:#a2d2ff,stroke:#1d3557
    classDef external fill:#ffafcc,stroke:#9d0208
    classDef config fill:#caffbf,stroke:#2b9348
    classDef script fill:#ffd6a5,stroke:#e85d04
    classDef docs fill:#bde0fe,stroke:#457b9d
    classDef static fill:#ffc8dd,stroke:#c9184a
    classDef ci fill:#d0f4de,stroke:#2f5233
    classDef consumer fill:#f0efeb,stroke:#6d6875

    click util "https://github.com/ant-design/ant-design-charts/tree/v2/packages/util"
    click plots "https://github.com/ant-design/ant-design-charts/tree/v2/packages/plots"
    click graphs "https://github.com/ant-design/ant-design-charts/tree/v2/packages/graphs"
    click charts "https://github.com/ant-design/ant-design-charts/tree/v2/packages/charts"
    click pnpm "https://github.com/ant-design/ant-design-charts/blob/v2/pnpm-workspace.yaml"
    click babel "https://github.com/ant-design/ant-design-charts/blob/v2/.babelrc"
    click eslint "https://github.com/ant-design/ant-design-charts/blob/v2/.eslintrc.js"
    click prettier "https://github.com/ant-design/ant-design-charts/blob/v2/.prettierrc.js"
    click tsconfig "https://github.com/ant-design/ant-design-charts/blob/v2/tsconfig.json"
    click jestconfig "https://github.com/ant-design/ant-design-charts/blob/v2/jest.config.js"
    click workflows "https://github.com/ant-design/ant-design-charts/tree/v2/.github/workflows"
    click webpackcfg "https://github.com/ant-design/ant-design-charts/blob/v2/config/webpack.js"
    click jestsetup1 "https://github.com/ant-design/ant-design-charts/blob/v2/config/jest.js"
    click jestsetup2 "https://github.com/ant-design/ant-design-charts/blob/v2/config/setup.js"
    click ast "https://github.com/ant-design/ant-design-charts/blob/v2/scripts/ast3.0"
    click docsgen "https://github.com/ant-design/ant-design-charts/blob/v2/scripts/docs/g2plot.mjs"
    click examplesParser "https://github.com/ant-design/ant-design-charts/tree/v2/scripts/ast3.0/examples-parser"
    click docs "https://github.com/ant-design/ant-design-charts/tree/v2/site/docs"
    click examples "https://github.com/ant-design/ant-design-charts/tree/v2/site/examples"
    click dumi "https://github.com/ant-design/ant-design-charts/blob/v2/site/.dumirc.ts"
    click public "https://github.com/ant-design/ant-design-charts/tree/v2/public"
    click template "https://github.com/ant-design/ant-design-charts/tree/v2/template"
```
