# odoo/o-spreadsheet architecture

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

- Interactive diagram: https://gitdiagram.com/odoo/o-spreadsheet
- Repository: https://github.com/odoo/o-spreadsheet

## Overview

##### High-Level Architecture

a) Core Components:
- Model Layer (src/model.ts)
- Plugin System (src/plugins/)
- Evaluation Engine (src/formulas/, src/functions/)
- UI Components (src/components/)

- Blue: Core Model/State
- Green: Business Logic/Plugins
- Orange: UI Components
- Purple: External Integrations

##### Key Subsystems
And represent major subsystems:

a) Data Processing:
- Formula Evaluation Engine
- Cell Computation
- Data Validation
- Conditional Formatting

b) UI Components:
- Grid System
- Top Bar
- Side Panel
- Bottom Bar
- Composer
- Figures (Charts, Images)

c) Collaboration Features:
- Real-time Sync
- History Management
- OT (Operational Transform)

##### Integration Points
External integration capabilities:

a) Import/Export:
- XLSX Import/Export
- File Handling
- Custom Data Integration

b) Extensibility:
- Plugin System
- Custom Functions
- Business Features
- Translation System

##### Data Flow

a) User Input Flow:
- UI Events → Plugins → Model → State Updates → UI Refresh

b) Collaboration Flow:
- Local Changes → Transport Service → Remote Peers
- Remote Changes → Local Model → UI Updates

##### Component Relationships
Interactions between:

- Grid ↔ Selection Manager
- Formula Engine ↔ Cell Evaluation
- Plugins ↔ Core Model
- UI Components ↔ Stores

##### Specific Implementation Details

Technical details in subsections:
**Core:**
- Model (TypeScript-based state management)
- Plugin System (Core, UI, Feature plugins)
- Event Bus System
- Command Pattern Implementation

**UI Layer:**
- Component Registry
- Store Management
- XML Templates
- Event Handling

**Extensions:**
- Custom Function Registry
- Menu Registry
- Side Panel Registry
- Figure Registry

**□ Core Components**
**○ Plugins**
**◇ UI Components**
**↔ Bidirectional Data Flow**
**→ Unidirectional Data Flow**
- Plugin Registration

##### Important Notes
Annotations for:
- Real-time collaboration capabilities
- Excel compatibility
- Plugin extension points
- State management approach
- Component lifecycle

##### Data flow patterns

Remember to:
- Keep the abstraction level consistent
- Clear boundaries between systems
- Extension points
- Major subsystems
- Document data flow patterns

This will provide a clear understanding of the system's architecture while maintaining the necessary detail level for a principal software engineer to understand the complete system.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#a8d1f0,stroke:#333
    classDef plugin fill:#90EE90,stroke:#333
    classDef ui fill:#FFB366,stroke:#333
    classDef collab fill:#DDA0DD,stroke:#333
    classDef data fill:#FFE4B5,stroke:#333

    subgraph Core
        Model["Model Layer"]:::core
        PluginSystem["Plugin System"]:::core
        EventSystem["Event System"]:::core
        StateManagement["State Management"]:::core
    end

    subgraph "Processing Layer"
        EvalEngine["Evaluation Engine"]:::core
        FormulaEngine["Formula Evaluation Engine"]:::core
        CellComputation["Cell Computation"]:::plugin
        DataValidation["Data Validation"]:::plugin
    end

    subgraph "UI Layer"
        Grid["Grid System"]:::ui
        TopBar["Top Bar"]:::ui
        SidePanel["Side Panel"]:::ui
        BottomBar["Bottom Bar"]:::ui
        Composer["Composer"]:::ui
        Figures["Figures (Charts, Images)"]:::ui
    end

    subgraph "Collaboration Layer"
        CollabFeatures["Collaboration Features"]:::collab
        HistoryMgmt["History Management"]:::collab
        OT["Operational Transform"]:::collab
    end

    subgraph "Integration Layer"
        XLSXHandler["XLSX Import/Export"]:::data
        FileHandler["File Handling"]:::data
        CustomIntegration["Custom Data Integration"]:::plugin
    end

    %% Relationships
    Model --> StateManagement
    PluginSystem --> Model
    EventSystem --> Model
    EvalEngine --> Model
    FormulaEngine --> EvalEngine
    CellComputation --> FormulaEngine
    DataValidation --> Model

    Grid --> EventSystem
    TopBar --> EventSystem
    SidePanel --> EventSystem
    BottomBar --> EventSystem
    Composer --> EventSystem
    Figures --> EventSystem

    CollabFeatures --> Model
    HistoryMgmt --> Model
    OT --> CollabFeatures

    XLSXHandler --> Model
    FileHandler --> Model
    CustomIntegration --> Model

    %% Click Events
    click Model "https://github.com/odoo/o-spreadsheet/blob/18.0/src/model.ts"
    click PluginSystem "https://github.com/odoo/o-spreadsheet/tree/18.0/src/plugins/"
    click EvalEngine "https://github.com/odoo/o-spreadsheet/tree/18.0/src/formulas/"
    click Grid "https://github.com/odoo/o-spreadsheet/tree/18.0/src/components/grid/"
    click TopBar "https://github.com/odoo/o-spreadsheet/tree/18.0/src/components/top_bar/"
    click SidePanel "https://github.com/odoo/o-spreadsheet/tree/18.0/src/components/side_panel/"
    click BottomBar "https://github.com/odoo/o-spreadsheet/tree/18.0/src/components/bottom_bar/"
    click Composer "https://github.com/odoo/o-spreadsheet/tree/18.0/src/components/composer/"
    click FormulaEngine "https://github.com/odoo/o-spreadsheet/tree/18.0/src/plugins/ui_core_views/cell_evaluation/"
    click CollabFeatures "https://github.com/odoo/o-spreadsheet/tree/18.0/src/collaborative/"
    click XLSXHandler "https://github.com/odoo/o-spreadsheet/tree/18.0/src/xlsx/"
    click StateManagement "https://github.com/odoo/o-spreadsheet/tree/18.0/src/stores/"
    click EventSystem "https://github.com/odoo/o-spreadsheet/tree/18.0/src/selection_stream/"
    click HistoryMgmt "https://github.com/odoo/o-spreadsheet/tree/18.0/src/history/"
    click OT "https://github.com/odoo/o-spreadsheet/tree/18.0/src/collaborative/ot/"

    %% Legend
    subgraph Legend
        L1["Core Component"]:::core
        L2["Plugin Component"]:::plugin
        L3["UI Component"]:::ui
        L4["Collaboration Component"]:::collab
        L5["Data Component"]:::data
    end
```
