# antvis/g6 architecture

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

- Interactive diagram: https://gitdiagram.com/antvis/g6
- Repository: https://github.com/antvis/g6

## Overview

Based on our review of the file tree and README, we’re dealing with a large, monorepo‐based graph visualization engine written in TypeScript known as G6. Its purpose is to provide a comprehensive engine for graph visualization, analysis, layout, and interaction. The overall architecture is modular and extensible, built around a core engine with a rich plugin and extension system, plus several supporting packages for CLI tools, bundling, testing, and documentation.

##### Main Components and Their Roles
- Core Graph Engine – Represented by the “packages/g6” directory. This is the heart of the framework and includes all the essential logic for rendering nodes, edges, combos, layouts (e.g., force-directed, radial, and custom layouts), animations, and interactions.
- Plugin System – Found inside “packages/g6/src/plugins”. These plugins add extra capabilities like tooltips, minimap, grid lines, history, watermark, and more. They are built to work on top of the core engine.
- Extensions and Additional Modules – There are multiple extension packages such as “packages/g6-extension-3d”, “packages/g6-extension-react”, and “packages/g6-ssr”. These packages extend the functionality of the core engine to support 3D rendering, React integration, and server-side rendering.
- CLI and Build Tools – The “packages/cli” package provides a command-line interface and scaffolding capabilities for users to extend or integrate custom behaviors. Additionally, “packages/bundle” contains configurations (like Rollup, Vite, and Webpack) that package the final library for different runtime environments.
- Documentation and Website – “packages/site” holds the website, API docs, examples, and demos. This serves as the front-facing documentation for users.
- Build and Continuous Integration (CI) Infrastructure – The presence of GitHub workflow files (in “.github/workflows”) and scripts (in “scripts” and “turbo.json”) indicates automated builds, tests, and deployments.
- Testing and Utilities – The extensive “tests” directory and numerous test setups within packages ensure high code quality and reliable feature behavior.

##### Relationships and Interactions
- The Core Graph Engine is the foundational layer that all other components depend upon. It exposes APIs and events that are consumed by the plugin system and extensions.
- The Plugin System dynamically augments the engine with additional behaviors and visual features. Plugins can be added or removed without modifying the core code.
- Extension packages (3D, React, SSR) “wrap” or integrate with the core engine to provide specialized rendering or integration with specific client-side frameworks.
- The CLI tool interacts directly with the core modules (or with extension templates) to help developers scaffold and build custom features. It might also interact with build tools.
- The Bundling tools and configurations (Rollup, Vite, Webpack) take the code from the core and its extensions to produce distributable bundles for various environments.
- The Documentation Website pulls together examples and API details that are generated from source code and markdown files to present a user-friendly interface.

##### Architectural Patterns and Design Principles
- Modular/Monorepo Architecture: The project is organized into well-defined packages, each responsible for a distinct capability.
- Plugin/Extension Pattern: A clear separation between the core engine and additional functionalities encourages extensibility.
- Separation of Concerns: Different packages handle rendering, behavior, models, and build automation separately.
- Automated Testing and CI: Dedicated directories and GitHub workflows indicate a robust pipeline for quality assurance.

##### Technologies and Tools to Highlight
- TypeScript – Primary language for the project.
- Bundling Tools: Rollup, Vite, Webpack (various configuration files in packages).
- Testing Frameworks – Jest (e.g., jest.config.js in many packages) and other test utilities.
- Build and CI Infrastructure – GitHub Actions workflows and associated scripts.
- React Integration – Notable in the “g6-extension-react” package.

##### Final Checklist
- Clearly label every component using descriptive names (“Core Engine – packages/g6”, “Plugin System – packages/g6/src/plugins”, “Extension: 3D Rendering – packages/g6-extension-3d”, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core Engine Layer"
        CoreEngine["Core Engine – packages/g6"]:::core
        PluginSystem["Plugin System – packages/g6/src/plugins"]:::plugin
    end

    subgraph "Extension Layer"
        Extension3D["Extension: 3D Rendering – packages/g6-extension-3d"]:::extension
        ExtensionReact["Extension: React Integration – packages/g6-extension-react"]:::extension
        ExtensionSSR["Extension: SSR – packages/g6-ssr"]:::extension
    end

    subgraph "Tools and Bundling"
        CLITool["CLI Tool – packages/cli"]:::tool
        BundlingTools["Bundling Tools – packages/bundle"]:::tool
    end

    subgraph "Support and Infrastructure"
        Documentation["Documentation & Website – packages/site"]:::support
        CI["CI & Build Infrastructure – .github/workflows, scripts, turbo.json"]:::support
        Testing["Testing & Utilities – tests/g6"]:::support
    end

    PluginSystem -->|"extends"| CoreEngine
    Extension3D -->|"integrates"| CoreEngine
    ExtensionReact -->|"integrates"| CoreEngine
    ExtensionSSR -->|"integrates"| CoreEngine
    CLITool -->|"scaffolds"| CoreEngine
    BundlingTools -->|"packages"| CoreEngine
    Documentation -->|"documents"| CoreEngine
    Documentation -->|"documents"| Extension3D
    Documentation -->|"documents"| ExtensionReact
    Documentation -->|"documents"| ExtensionSSR
    Testing -->|"tests"| CoreEngine
    CI -->|"automates"| CLITool
    CI -->|"automates"| BundlingTools
    CI -->|"automates"| Testing

    classDef core fill:#bbdefb,stroke:#1e88e5,stroke-width:2px;
    classDef plugin fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef extension fill:#e1bee7,stroke:#8e24aa,stroke-width:2px;
    classDef tool fill:#ffe082,stroke:#ffa000,stroke-width:2px;
    classDef support fill:#eeeeee,stroke:#757575,stroke-width:2px;

    click CoreEngine "https://github.com/antvis/g6/tree/v5/packages/g6"
    click PluginSystem "https://github.com/antvis/g6/tree/v5/packages/g6/src/plugins"
    click Extension3D "https://github.com/antvis/g6/tree/v5/packages/g6-extension-3d"
    click ExtensionReact "https://github.com/antvis/g6/tree/v5/packages/g6-extension-react"
    click ExtensionSSR "https://github.com/antvis/g6/tree/v5/packages/g6-ssr"
    click CLITool "https://github.com/antvis/g6/tree/v5/packages/cli"
    click BundlingTools "https://github.com/antvis/g6/tree/v5/packages/bundle"
    click Documentation "https://github.com/antvis/g6/tree/v5/packages/site"
    click CI "https://github.com/antvis/g6/tree/v5/.github/workflows"
    click Testing "https://github.com/antvis/g6/tree/v5/tests/g6"
```
