# jerry-tanghao/x-sheet architecture

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

- Interactive diagram: https://gitdiagram.com/jerry-tanghao/x-sheet
- Repository: https://github.com/jerry-tanghao/x-sheet

## Overview

##### Main Components
- User Interface & Initialization:
- “index.html” and assets (CSS, images, etc.) that serve as the entry point and styling for the spreadsheet.
- Initialization snippet that creates an instance of the spreadsheet (XSheet) and attaches it to the DOM.
- Core Spreadsheet Engine:
- Distinguish between subcomponents such as table engine, cell handling, screen rendering, resizing, protection, and context-menu management.
- Formula and Computation Engine:
- Src/formula folder (with Compiler.js and Formula.js) which deals with parsing and computing cell formulas.
- Drawing and Rendering Subsystem:
- IO and Import/Export Modules:
- Modules in src/io (for CSV and XLSX import/export) as separate components responsible for data persistence and interoperability.
- Auxiliary Modules and Utilities:
- Worker Processes:

##### Relationships and Interactions
- How the Core Spreadsheet Engine interacts with the formula engine for cell computations, with the drawing system for rendering visuals, and with IO modules to manage data import/export.
- How auxiliary modules support additional user interactions (context menus, alerts, etc.) and are called upon by both the UI and the core engine.

##### Architectural Patterns and Design Principles
- Modularity by grouping the project into distinct layers (UI, core engine, formula processing, rendering, import/export, and utilities).
- How iterative and asynchronous processing is implemented via the iterator submodules (both synchronous and asynchronous variants) in the table portion.

##### Relevant Technologies and Frameworks
- Usage of webpack (build/webpack configurations) for module bundling.
- That it is built in modern JavaScript, utilizes ES6 modules (as seen by .babelrc and ESLint configuration files), and employs various libraries for DOM manipulation and event handling.
- Mention that integration with external tools like exceljs is highlighted in the README for XLSX parsing.

##### Elements
- Clearly labeled nodes for each major component (UI, Core Spreadsheet Engine, Formula Engine, Drawing System, IO Modules, Auxiliary Modules, and Worker Processes).
- Annotation for each component mentioning key file paths or directories where their logic resides (e.g., “Core Table Components (src/core/table/*)”).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "UI Layer"
        U1["index.html"]:::ui
        U2["assets"]:::ui
    end

    subgraph "Core Spreadsheet Engine"
        C1["Core Table Components"]:::core
        C2["Core Work & Sheet Management"]:::core
        X["XSheet Engine"]:::core
    end

    subgraph "Formula Engine"
        F1["Formula Engine"]:::formula
    end

    subgraph "Drawing and Rendering"
        D1["Drawing System"]:::drawing
    end

    subgraph "IO Modules"
        IO1["CSV Import/Export"]:::io
        IO2["XLSX Import/Export"]:::io
    end

    subgraph "Auxiliary Modules & Utilities"
        A1["Utility Libraries"]:::aux
        A2["Helper Utilities"]:::aux
        A3["Additional UI Modules"]:::aux
    end

    subgraph "Worker Processes"
        W1["Worker Processes"]:::worker
    end

    U1 --> X
    U2 --> X
    C1 --> X
    C2 --> X

    X --> F1
    X --> D1
    X --> IO1
    X --> IO2
    X --> A1
    X --> A2
    X --> A3
    X --> W1

    click U1 "https://github.com/jerry-tanghao/x-sheet/blob/main/index.html"
    click U2 "https://github.com/jerry-tanghao/x-sheet/tree/main/assets"
    click C1 "https://github.com/jerry-tanghao/x-sheet/tree/main/src/core/table"
    click C2 "https://github.com/jerry-tanghao/x-sheet/tree/main/src/core/work"
    click F1 "https://github.com/jerry-tanghao/x-sheet/tree/main/src/formula"
    click D1 "https://github.com/jerry-tanghao/x-sheet/tree/main/src/draw"
    click IO1 "https://github.com/jerry-tanghao/x-sheet/tree/main/src/io/csv"
    click IO2 "https://github.com/jerry-tanghao/x-sheet/tree/main/src/io/xlsx"
    click A1 "https://github.com/jerry-tanghao/x-sheet/tree/main/src/lib"
    click A2 "https://github.com/jerry-tanghao/x-sheet/tree/main/src/utils"
    click A3 "https://github.com/jerry-tanghao/x-sheet/tree/main/src/module"
    click W1 "https://github.com/jerry-tanghao/x-sheet/tree/main/src/worker"

    classDef ui fill:#DFF0D8,stroke:#3C763D,color:#3C763D;
    classDef core fill:#D9EDF7,stroke:#31708F,color:#31708F;
    classDef formula fill:#FCF8E3,stroke:#8A6D3B,color:#8A6D3B;
    classDef drawing fill:#D1ECF1,stroke:#0C5460,color:#0C5460;
    classDef io fill:#F2DEDE,stroke:#A94442,color:#A94442;
    classDef aux fill:#F5F5F5,stroke:#666666,color:#666666;
    classDef worker fill:#FCE4EC,stroke:#AD1457,color:#AD1457;
```
