# onlyoffice/sdkjs-forms architecture

> Architecture diagram of the GitHub repository onlyoffice/sdkjs-forms, 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-forms
- Repository: https://github.com/onlyoffice/sdkjs-forms

## Overview

##### Main Components
- API Layer: Include the components defined in api.js, apiBuilder.js, and apiPlugins.js. This layer is likely responsible for exposing endpoints or functionalities that interact with other parts of the system.
- Configuration Module: Represented by the configs directory (e.g., word.json), which likely provides settings or metadata utilized by other modules.
- OForm Core Library: The oform folder is a central component containing the core logic:
– OForm.js and Role.js: These files probably set up the overall object form or manage roles/permissions.
– Format Submodule: Under oform/format, you have several files (BaseFormatObject.js, Document.js, FieldGroup.js, FieldMaster.js, User.js, UserMaster.js) which represent different document components or entities.
– Changes Submodule: Within oform/format/changes, the different “Changes” files (e.g., DocumentChanges.js, FieldGroupChanges.js, etc.) are likely concerned with tracking or applying modifications to the base formats.
– XML Submodule: The oform/xml directory (with XmlContext.js and XmlPackage.js) handles XML processing, context-setups, or packaging of data into XML formats.

##### Relationships and Data Flow
- The API layer likely serves as the entry point for external requests. It will interact with the OForm module by using the API builder and plugin files to map requests to the proper core functionalities.
- The Configuration component provides necessary settings (e.g., document language specifics from word.json) to both the API and OForm modules.
- Inside OForm, the “format” and “changes” submodules work together: the “format” files define the document structures, and the “changes” files handle modifications, versioning, or tracking of those structures.
- The XML component interfaces with the core OForm functionality for converting or interfacing document data into XML, likely as part of a final output or intermediary data stage.

##### Architectural Patterns & Principles
- Modularity: The project cleanly separates concerns (API, configuration, domain logic via OForm).
- Layered Architecture: There is a clear separation between the interface (API layer), business logic (OForm core), and data/format handling (XML).
- Emphasis on Object Representations: The existence of “format” objects and their corresponding “changes” versions suggests an object-oriented design that might mirror the state and transformational changes of a document.

##### Relevant Technologies and Frameworks
- JavaScript is the primary language.
- The naming conventions and structure hint at a design that might be used within a server-side environment (e.g., Node.js) hosting OnlyOffice functionalities.
- Configuration is managed externally via JSON files, suggesting ease of dynamic behavior changes without code modifications.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration
    Config["configs/word.json"]:::config

    %% API Layer
    subgraph "API Layer"
        API1["api.js"]:::api
        API2["apiBuilder.js"]:::api
        API3["apiPlugins.js"]:::api
    end

    %% OForm Core Library
    subgraph "OForm Core Library"
        %% Core Submodule
        subgraph "Core"
            OForm["OForm.js"]:::core
            Role["Role.js"]:::core
        end
        %% Format Submodule
        subgraph "Format Module"
            BaseFormat["BaseFormatObject.js"]:::format
            Document["Document.js"]:::format
            FieldGroup["FieldGroup.js"]:::format
            FieldMaster["FieldMaster.js"]:::format
            User["User.js"]:::format
            UserMaster["UserMaster.js"]:::format
        end
        %% Changes Submodule
        subgraph "Changes Module"
            DocumentChanges["DocumentChanges.js"]:::changes
            FieldGroupChanges["FieldGroupChanges.js"]:::changes
            FieldMasterChanges["FieldMasterChanges.js"]:::changes
            UserChanges["UserChanges.js"]:::changes
            UserMasterChanges["UserMasterChanges.js"]:::changes
        end
        %% XML Submodule
        subgraph "XML Module"
            XmlContext["XmlContext.js"]:::xml
            XmlPackage["XmlPackage.js"]:::xml
        end
    end

    %% Connections
    %% Configuration flows
    Config -->|"settings"| API1
    Config -->|"settings"| OForm

    %% API Layer calls OForm Core
    API3 -->|"handles_request"| OForm

    %% Format Module to Changes Module (modification tracking)
    Document -->|"tracks_changes"| DocumentChanges

    %% Core to XML Module (data conversion)
    OForm -->|"data_conversion"| XmlContext

    %% Class definitions with colours
    classDef api fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef config fill:#90EE90,stroke:#008000,stroke-width:2px;
    classDef core fill:#FFA500,stroke:#FF8C00,stroke-width:2px;
    classDef format fill:#FFDAB9,stroke:#FF8C00,stroke-width:2px;
    classDef changes fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
    classDef xml fill:#DDA0DD,stroke:#800080,stroke-width:2px;

    %% Click Events for API Layer
    click API1 "https://github.com/onlyoffice/sdkjs-forms/blob/master/api.js"
    click API2 "https://github.com/onlyoffice/sdkjs-forms/blob/master/apiBuilder.js"
    click API3 "https://github.com/onlyoffice/sdkjs-forms/blob/master/apiPlugins.js"

    %% Click Event for Configuration
    click Config "https://github.com/onlyoffice/sdkjs-forms/blob/master/configs/word.json"

    %% Click Events for OForm Core (Core Submodule)
    click OForm "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/OForm.js"
    click Role "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/Role.js"

    %% Click Events for Format Module
    click BaseFormat "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/format/BaseFormatObject.js"
    click Document "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/format/Document.js"
    click FieldGroup "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/format/FieldGroup.js"
    click FieldMaster "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/format/FieldMaster.js"
    click User "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/format/User.js"
    click UserMaster "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/format/UserMaster.js"

    %% Click Events for Changes Module
    click DocumentChanges "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/format/changes/DocumentChanges.js"
    click FieldGroupChanges "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/format/changes/FieldGroupChanges.js"
    click FieldMasterChanges "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/format/changes/FieldMasterChanges.js"
    click UserChanges "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/format/changes/UserChanges.js"
    click UserMasterChanges "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/format/changes/UserMasterChanges.js"

    %% Click Events for XML Module
    click XmlContext "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/xml/XmlContext.js"
    click XmlPackage "https://github.com/onlyoffice/sdkjs-forms/blob/master/oform/xml/XmlPackage.js"
```
