# onlyoffice/sdkjs-plugins architecture

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

- Interactive diagram: https://gitdiagram.com/onlyoffice/sdkjs-plugins
- Repository: https://github.com/onlyoffice/sdkjs-plugins

## Overview

Based on your repository’s file tree and README, this project is a collection of sample plugins designed for the ONLYOFFICE document editor. Each directory (such as helloworld, templates, cbr, example_autocomplete, etc.) represents a self-contained example that demonstrates a particular plugin functionality (e.g., inserting content, search–replace, working with content controls, external integration, etc.).

##### Project Type and Purpose
- This is not a single monolithic application but rather a repository of multiple example plugins.
- Its main purpose is to serve as a reference toolkit for developers:
– Demonstrating how to insert text, interact with the document, perform search–replace operations, work with comments and content controls, and integrate with third-party services.
- The examples target the ONLYOFFICE API, so the central idea is enhancing or manipulating documents in the ONLYOFFICE editor environment.

##### File Structure
- Notice that at the top level you have various directories corresponding to different examples (helloworld, templates, cbr, chrome_extension_example, and many more).
- Each example directory is almost self-contained and includes:
– Configuration files (config.json) for settings.
– An index.html file which serves as the main entry point.
– Scripts (in the scripts folder) that implement the plugin’s logic.
– Resources (such as CSS files, images, and sometimes translations) that determine the plugin’s UI and assets.
- There are also folders like “archive”, “externallistener”, and “licenses” which indicate historical examples, external scripts, or third-party validations, respectively.

##### Extracting Architectural Insights from the README
- The README outlines a categorized list of examples—ranging from inserting content to search–replace features, handling comments, and integrating third-party services.
- This indicates the architecture heavily relies on a single pattern: self-contained plugins that extend the functionality of ONLYOFFICE.

a. Main Components to Include:
- ONLYOFFICE Editor / Host Application – Represented as the central system that loads plugins.
- Plugin Examples – Each example (e.g., helloworld, templates, cbr, example_autocomplete, etc.) can be represented as separate modules/components.
- Common layers within each plugin:
- Frontend Entry Point (index.html)
- Configuration (config.json)
- Business/Logic layer (scripts folder)
- Presentation/Asset layer (resources folder with CSS, images, translations, etc.)
- External Integration Points:
- Chrome Extension example showing integration with the cloud version.
- externallistener example for external 3rd party control panels.

b. Relationships and Interactions:

c. Highlighting Architectural Patterns and Design Principles:
- Modular / Plugin Architecture: Emphasize that each example is an independent module providing isolated functionality.
- Separation of Concerns: Different folders handle configuration, assets, and logic separately (mirroring an MVC-like structure in many examples).
- Reusability and Extensibility: The use of a shared API (ONLYOFFICE API) allows each module to extend the editor without overlapping concerns.
- Consistent Template: The consistent structure across examples (html + config + scripts + resources) shows a design guideline that contributes to maintainability and scalability.

d. Technologies, Frameworks, or Libraries:
- ONLYOFFICE API is a central dependency.
- Some plugins incorporate third-party libraries (indicated by files like jQuery licenses, select2, or external scripts).
- The use of standard web technologies: HTML, JavaScript, and CSS.
- Optional integration with Chrome extension technology in the chrome_extension_example.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Central Component
    Editor["ONLYOFFICE Editor"]:::editor

    %% HelloWorld Plugin
    subgraph "HelloWorld Plugin"
        H_Config["config.json"]:::config
        H_Script["helloworld.js"]:::script
        H_Index["index.html"]:::entry
        H_Config --> H_Script
        H_Script --> H_Index
    end
    Editor -->|"loads"| H_Index

    %% Templates Plugin
    subgraph "Templates Plugin"
        T_Config["config.json"]:::config
        T_Script["templates.js"]:::script
        T_Index["index.html"]:::entry
        T_Assets["Layouts"]:::assets
        T_Config --> T_Script
        T_Script --> T_Index
        T_Script --> T_Assets
    end
    Editor -->|"loads"| T_Index

    %% CBR Plugin
    subgraph "CBR Plugin"
        C_Config["config.json"]:::config
        C_Script["cbr.js"]:::script
        C_Index["index.html"]:::entry
        C_Config --> C_Script
        C_Script --> C_Index
    end
    Editor -->|"loads"| C_Index

    %% Chrome Extension Example
    subgraph "Chrome Extension Example"
        CE_Main["main.js"]:::external
        CE_Manifest["manifest.json"]:::external
        CE_Readme["README.md"]:::doc
        CE_Manifest --> CE_Main
        CE_Main --> CE_Readme
    end
    Editor -->|"integrates"| CE_Main

    %% Example Autocomplete Plugin
    subgraph "Example Autocomplete Plugin"
        EA_Config["config.json"]:::config
        EA_Script["Autocomplete Scripts"]:::script
        EA_Index["index.html"]:::entry
        EA_Config --> EA_Script
        EA_Script --> EA_Index
    end
    Editor -->|"loads"| EA_Index

    %% External Listener Plugin
    subgraph "External Listener Plugin"
        EL_Config["config.json"]:::config
        EL_Script["Listener Scripts"]:::script
        EL_Index["index.html"]:::entry
        EL_Config --> EL_Script
        EL_Script --> EL_Index
    end
    Editor -->|"integrates"| EL_Index

    %% Other Sample Plugins
    subgraph "Other Sample Plugins"
        O1["Add Comment in Cell"]:::other
        O2["Add Content Controls"]:::other
        O3["Extended Comments Integration"]:::other
        O4["Insert Content and Document"]:::other
        O5["Jitsi Integration"]:::other
        O6["Move Cursor"]:::other
        O7["Search & Replace"]:::other
        O8["Speech Input"]:::other
        O9["Work with Content Controls"]:::other
        O10["Work with Content Controls Combo"]:::other
        O11["Work with Content Controls Content"]:::other
        O12["Work with Content Controls Navigation"]:::other
        O13["Work with Content Controls Tags"]:::other
    end
    Editor -->|"loads"| O1
    Editor -->|"loads"| O2
    Editor -->|"loads"| O3
    Editor -->|"loads"| O4
    Editor -->|"loads"| O5
    Editor -->|"loads"| O6
    Editor -->|"loads"| O7
    Editor -->|"loads"| O8
    Editor -->|"loads"| O9
    Editor -->|"loads"| O10
    Editor -->|"loads"| O11
    Editor -->|"loads"| O12
    Editor -->|"loads"| O13

    %% Legacy/Archive Examples
    subgraph "Legacy / Archived Examples"
        Archive["Archive Directory"]:::other
    end
    Editor -->|"references"| Archive

    %% Click Events
    click H_Index "https://github.com/onlyoffice/sdkjs-plugins/blob/master/helloworld/index.html"
    click H_Config "https://github.com/onlyoffice/sdkjs-plugins/blob/master/helloworld/config.json"
    click H_Script "https://github.com/onlyoffice/sdkjs-plugins/blob/master/helloworld/scripts/helloworld.js"

    click T_Index "https://github.com/onlyoffice/sdkjs-plugins/blob/master/templates/index.html"
    click T_Config "https://github.com/onlyoffice/sdkjs-plugins/blob/master/templates/config.json"
    click T_Script "https://github.com/onlyoffice/sdkjs-plugins/blob/master/templates/scripts/templates.js"
    click T_Assets "https://github.com/onlyoffice/sdkjs-plugins/tree/master/templates/templates/"

    click C_Index "https://github.com/onlyoffice/sdkjs-plugins/blob/master/cbr/index.html"
    click C_Config "https://github.com/onlyoffice/sdkjs-plugins/blob/master/cbr/config.json"
    click C_Script "https://github.com/onlyoffice/sdkjs-plugins/blob/master/cbr/scripts/cbr.js"

    click CE_Main "https://github.com/onlyoffice/sdkjs-plugins/blob/master/chrome_extension_example/main.js"
    click CE_Manifest "https://github.com/onlyoffice/sdkjs-plugins/blob/master/chrome_extension_example/manifest.json"
    click CE_Readme "https://github.com/onlyoffice/sdkjs-plugins/blob/master/chrome_extension_example/README.md"

    click EA_Index "https://github.com/onlyoffice/sdkjs-plugins/blob/master/example_autocomplete/index.html"
    click EA_Config "https://github.com/onlyoffice/sdkjs-plugins/blob/master/example_autocomplete/config.json"
    click EA_Script "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_autocomplete/scripts/"

    click EL_Index "https://github.com/onlyoffice/sdkjs-plugins/blob/master/externallistener/index.html"
    click EL_Config "https://github.com/onlyoffice/sdkjs-plugins/blob/master/externallistener/config.json"
    click EL_Script "https://github.com/onlyoffice/sdkjs-plugins/blob/master/externallistener/scripts/code.js"

    click O1 "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_add_comment_in_cell/"
    click O2 "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_add_content_controls/"
    click O3 "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_extended_comments/"
    click O4 "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_insert_content_and_document/"
    click O5 "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_jitsi/"
    click O6 "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_move_cursor/"
    click O7 "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_search_replace/"
    click O8 "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_speech_input/"
    click O9 "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_work_with_content_controls/"
    click O10 "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_work_with_content_controls_combo/"
    click O11 "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_work_with_content_controls_content/"
    click O12 "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_work_with_content_controls_navigation/"
    click O13 "https://github.com/onlyoffice/sdkjs-plugins/tree/master/example_work_with_content_controls_tags/"

    click Archive "https://github.com/onlyoffice/sdkjs-plugins/tree/master/archive/"

    %% Styles
    classDef editor fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef config fill:#ADD8E6,stroke:#00008B,stroke-width:1px;
    classDef entry fill:#90EE90,stroke:#006400,stroke-width:1px;
    classDef script fill:#FFFACD,stroke:#BDB76B,stroke-width:1px;
    classDef assets fill:#FFB6C1,stroke:#FF69B4,stroke-width:1px;
    classDef external fill:#FFA500,stroke:#FF8C00,stroke-width:1px;
    classDef doc fill:#DDA0DD,stroke:#9932CC,stroke-width:1px;
    classDef other fill:#AFEEEE,stroke:#20B2AA,stroke-width:1px;
```
