# antvis/s2 architecture

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

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

## Overview

##### Project Type and Purpose
- The README alongside the packages (s2-core, s2-react, s2-react-components, s2-vue, and s2-site) makes it clear that the project provides a core engine plus user interface components and a comprehensive playground/documentation website.

##### File Structure to Determine Major Components
- Monorepo Structure: At the root, there is a “pnpm-workspace.yaml” which indicates the repository is managed as a monorepo – with packages for core functionality, UI components for React, Vue, documentation (s2-site), and tools/scripts.
- Core Library (packages/s2-core): Contains the engine, cell rendering logic, datasets processing, interaction handlers, layout, facet management, and extension support. It is the foundation that drives the pivot table capabilities.
- Vue Integration (packages/s2-vue): Although stated as “停止维护” (maintenance stopped), this package nonetheless illustrates the intent to support multiple frameworks.
- Documentation/Website (s2-site): Contains pages for guides, API docs, demos, examples, and integration configurations.
- Tests and Configurations: Numerous “__tests__” directories, Jest configs, Rollup and TypeScript configurations appear, hinting at rigorous testing and bundling strategies.
- Supporting Scripts and Configurations: There are husky pre-commit hooks, GitHub workflows, ESLint, Prettier, and build scripts that underline CI/CD and code quality support.

##### Key Architectural Patterns and Relationships
- Separation of Concerns: The system is divided into a core engine (for heavy computations, rendering, interactions) and separate front-end UI libraries (React, Vue) that wrap or integrate with the core.
- Extensibility: The engine is built with extensibility in mind (see directories for “extends” and “facet”, “renderer”, “interaction”) so custom behaviors (custom cell rendering, custom layouts, plugins) can be seamlessly added.
- Monorepo Communication: Packages are clearly decoupled. They depend on the core (e.g., s2-react-components and s2-react) to perform data processing and rendering while applying framework-specific wrappers.
- Data-Driven Approach: The README highlights that S2 is “完全基于数据驱动的方式” – meaning that data configuration, event handling, and customization are determined by data hooks and configuration objects rather than hardcoded views.
- Testing Strategy: The structure includes extensive unit, integration, and visual regression tests which play a major role in ensuring reliability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Supporting Infrastructure"
        pnpm["pnpm-workspace.yaml"]:::support
        workflows[".github/workflows"]:::support
        build["scripts"]:::support
    end

    subgraph "Core Engine"
        s2core["s2-core – Data Engine\n(Rendering, layout, interactions)\nExtensions & Data Transformation"]:::core
    end

    subgraph "UI Integration"
        s2react["s2-react – React Integration"]:::integration
        s2reactcomp["s2-react-components – React UI Components"]:::integration
        s2vue["s2-vue – Vue Integration (Deprecated)"]:::integration
    end

    subgraph "Documentation & Playground"
        s2site["s2-site – Documentation & Playground"]:::documentation
    end

    pnpm --> s2core
    workflows --> s2core
    build --> s2core

    s2core -->|"providesCore"| s2react
    s2core -->|"providesCore"| s2reactcomp
    s2core -->|"providesCore"| s2vue

    s2core -->|"engineOutput"| s2site
    s2react -->|"demo"| s2site
    s2reactcomp -->|"demo"| s2site
    s2vue -->|"demo"| s2site

    click s2core "https://github.com/antvis/s2/tree/next/packages/s2-core"
    click s2react "https://github.com/antvis/s2/tree/next/packages/s2-react"
    click s2reactcomp "https://github.com/antvis/s2/tree/next/packages/s2-react-components"
    click s2vue "https://github.com/antvis/s2/tree/next/packages/s2-vue"
    click s2site "https://github.com/antvis/s2/tree/next/s2-site"
    click pnpm "https://github.com/antvis/s2/blob/next/pnpm-workspace.yaml"
    click workflows "https://github.com/antvis/s2/tree/next/.github/workflows"
    click build "https://github.com/antvis/s2/tree/next/scripts"

    classDef core fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef integration fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef documentation fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef support fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px,stroke-dasharray: 5 5;
```
