# varioush/elementor architecture

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

- Interactive diagram: https://gitdiagram.com/varioush/elementor
- Repository: https://github.com/varioush/elementor

## Overview

##### Project type and purpose
- This is a monolithic, full-stack WordPress plugin (“Elementor Page Builder”) that provides a live, drag-and-drop frontend editor.
- It consists of a PHP backend that hooks into WordPress (admin screens, AJAX endpoints, database), a JavaScript frontend editor built on Backbone/Marionette, and a build pipeline for assets (Grunt/SCSS → CSS, ES5/JS module bundling).

##### File structure
- Top-level:
- elementor.php (plugin bootstrap & init)
- composer.json / package.json / Gruntfile.js (dependency & build configs)
- includes/ (PHP modules: admin, api, controls, widgets, templates, settings, frontend, compatibility, etc.)
- assets/dev/ & assets/css, assets/js (source SCSS/JS → compiled CSS/JS)
- tests/ (PHPUnit tests, bootstrap)
- Pattern: MVC in the JavaScript editor (models, collections, views, layouts, behaviors); modular PHP with separation by feature (controls, widgets, settings, API).

##### README insights
- Confirms WP plugin registering hooks, provides live edit via AJAX and iframe avoidance.
- Describes Template Library with local & remote sources (includes/template-library/).
- Relies on WordPress hooks & AJAX, no external microservices except remote template source.

##### Main components
a. WordPress Core
- Hook registration (actions, filters)
- Admin menu & editor entry point
- AJAX handler (wp-ajax)
- Database (wp_postmeta)
b. PHP Backend (Elementor Plugin)
- Bootstrap (elementor.php → includes/plugin.php)
- Admin module (includes/admin.php → control panel UI)
- API module (includes/api.php → REST/AJAX endpoints)
- Controls manager & controls (includes/controls-manager.php + /includes/controls/*.php)
- Elements & widgets managers (includes/elements-manager.php, /includes/widgets/*.php)
- Template-library manager (includes/template-library/…)
- Settings & system-info (includes/settings/)
- Compatibility & upgrades (includes/compatibility.php, includes/upgrades.php)
c. Frontend JavaScript Editor
- Backbone.Marionette application (assets/dev/js/editor/)
– Models (models/)
– Collections (components/template-library/collections/)
– Views & layouts (views/, layouts/panel/)
– Behaviors & utilities (behaviors/, utils/)
- CSS/SCSS for editor panel (assets/dev/scss/editor/, editor/panel/)
d. Frontend Page Renderer
- JS Handlers (assets/dev/js/frontend/handlers/*.js)
- Utilities (assets/dev/js/frontend/utils.js)
- Compiled CSS for frontend widgets (assets/css/frontend.css)
e. Build Pipeline & Dependencies
- Grunt tasks (Gruntfile.js) for compilation, minification
- package.json & composer.json for JS/PHP dependencies
- assets/lib/ third-party libraries loaded in appropriate contexts
f. External Services
- Remote Template Library API (source: includes/template-library/sources/remote.php)
- WordPress REST/AJAX endpoints

##### Relationships & interactions
- WordPress loads Elementor on init → registers admin menu and AJAX hooks → enqueues editor JS/CSS.
- User clicks “Edit with Elementor” → editor panel loads in iframe-less live view → Backbone app boots → models fetch data via AJAX to PHP API.
- User actions (drag, drop, config) → JS sends AJAX requests → PHP updates postmeta → returns JSON → JS re-renders.
- Template Library: Backbone models fetch from local (DB) and remote sources via API modules.
- On “Publish/Save” → PHP finalizes post content, persists configuration.
- Frontend page load → enqueues compiled frontend JS & CSS → handlers activate dynamic widget behaviors.

##### Architectural patterns & design principles
- Modular PHP by feature (SRP).
- MVC/MV* pattern on JS side (Backbone + Marionette).
- Build separation: dev source vs. compiled assets.
- WordPress plugin standards (hooks, filters, REST/AJAX).
- Extensibility: interfaces (includes/interfaces/), sources for templates, group controls.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    subgraph "WordPress Core" 
        WP["WordPress Core"]:::external
    end

    subgraph "Elementor Plugin (PHP)" 
        direction TB
        Bootstrap["Bootstrap\n(elementor.php)"]:::php
        Admin["Admin Module\n(includes/admin.php)"]:::php
        API["API Module\n(includes/api.php)"]:::php
        ControlsMgr["Controls Manager\n(includes/controls-manager.php)"]:::php
        ElementsMgr["Elements Manager\n(includes/elements-manager.php)"]:::php
        WidgetsMgr["Widgets Manager\n(includes/widgets-manager.php)"]:::php
        subgraph "Template Library"
            Manager["Template Library Manager\n(includes/template-library/manager.php)"]:::php
            LocalSource["Local Source\n(local.php)"]:::php
            BaseSource["Base Source\n(base.php)"]:::php
            RemoteSource["Remote Source\n(remote.php)"]:::php
        end
        Settings["Settings & System Info\n(includes/settings/settings.php)"]:::php
        Compatibility["Compatibility\n(includes/compatibility.php)"]:::php
        Upgrades["Upgrades\n(includes/upgrades.php)"]:::php
    end

    subgraph "Editor JS App (Backbone/Marionette)" 
        direction TB
        EditorApp["Editor App\n(editor.js)"]:::jsEditor
        Models["Models\n(models/*.js)"]:::jsEditor
        Collections["Collections\n(template-library/collections)"]:::jsEditor
        Views["Views & Layouts\n(views/, layouts/)"]:::jsEditor
        Behaviors["Behaviors\n(behaviors/*.js)"]:::jsEditor
        UtilsEditor["Utilities\n(utils/*.js)"]:::jsEditor
    end

    subgraph "Frontend Renderer" 
        direction TB
        FrontendApp["Frontend App\n(frontend.js)"]:::jsFrontend
        Handlers["Handlers\n(handlers/*.js)"]:::jsFrontend
        UtilsFrontend["Utils\n(utils.js)"]:::jsFrontend
        CSSFrontend["CSS\n(frontend.css)"]:::jsFrontend
    end

    subgraph "Build Pipeline & Dependencies"
        direction TB
        Grunt["Gruntfile.js"]:::build
        Package["package.json"]:::build
        Composer["composer.json"]:::build
        Lib["assets/lib/"]:::build
    end

    RemoteService["Remote Template Service"]:::external

    %% Connections
    WP -->|init| Bootstrap
    Bootstrap -->|register hooks| Admin
    Bootstrap --> API
    Bootstrap --> ControlsMgr
    Bootstrap --> ElementsMgr
    Bootstrap --> WidgetsMgr
    Bootstrap --> Manager
    Bootstrap --> Settings
    Bootstrap --> Compatibility
    Bootstrap --> Upgrades

    Bootstrap -->|enqueue Editor JS/CSS| EditorApp
    EditorApp -->|AJAX JSON| API
    API -->|DB reads/writes| WP

    EditorApp --> Models
    EditorApp --> Collections
    EditorApp --> Views
    EditorApp --> Behaviors
    EditorApp --> UtilsEditor

    Manager --> LocalSource
    Manager --> BaseSource
    Manager --> RemoteSource
    RemoteSource -->|REST API| RemoteService

    WP -->|load frontend assets| FrontendApp
    FrontendApp --> Handlers
    FrontendApp --> UtilsFrontend
    FrontendApp --> CSSFrontend

    Grunt -->|build assets| CSSFrontend
    Grunt -->|build assets| EditorApp
    Package --> Grunt
    Composer --> Bootstrap
    Lib --> EditorApp
    Lib --> FrontendApp

    %% Click Events
    click Bootstrap "https://github.com/varioush/elementor/blob/master/elementor.php"
    click Admin "https://github.com/varioush/elementor/blob/master/includes/admin.php"
    click API "https://github.com/varioush/elementor/blob/master/includes/api.php"
    click ControlsMgr "https://github.com/varioush/elementor/blob/master/includes/controls-manager.php"
    click ElementsMgr "https://github.com/varioush/elementor/blob/master/includes/elements-manager.php"
    click WidgetsMgr "https://github.com/varioush/elementor/blob/master/includes/widgets-manager.php"
    click Manager "https://github.com/varioush/elementor/blob/master/includes/template-library/manager.php"
    click LocalSource "https://github.com/varioush/elementor/blob/master/includes/template-library/sources/local.php"
    click BaseSource "https://github.com/varioush/elementor/blob/master/includes/template-library/sources/base.php"
    click RemoteSource "https://github.com/varioush/elementor/blob/master/includes/template-library/sources/remote.php"
    click Settings "https://github.com/varioush/elementor/blob/master/includes/settings/settings.php"
    click Compatibility "https://github.com/varioush/elementor/blob/master/includes/compatibility.php"
    click Upgrades "https://github.com/varioush/elementor/blob/master/includes/upgrades.php"
    click EditorApp "https://github.com/varioush/elementor/blob/master/assets/dev/js/editor/editor.js"
    click Models "https://github.com/varioush/elementor/blob/master/assets/dev/js/editor/models/*.js"
    click Collections "https://github.com/varioush/elementor/tree/master/assets/dev/js/editor/collections"
    click Views "https://github.com/varioush/elementor/tree/master/assets/dev/js/editor/views"
    click Behaviors "https://github.com/varioush/elementor/blob/master/assets/dev/js/editor/behaviors/*.js"
    click UtilsEditor "https://github.com/varioush/elementor/blob/master/assets/dev/js/editor/utils/*.js"
    click FrontendApp "https://github.com/varioush/elementor/blob/master/assets/dev/js/frontend/frontend.js"
    click Handlers "https://github.com/varioush/elementor/blob/master/assets/dev/js/frontend/handlers/*.js"
    click UtilsFrontend "https://github.com/varioush/elementor/blob/master/assets/dev/js/frontend/utils.js"
    click CSSFrontend "https://github.com/varioush/elementor/blob/master/assets/css/frontend.css"
    click Grunt "https://github.com/varioush/elementor/blob/master/Gruntfile.js"
    click Package "https://github.com/varioush/elementor/blob/master/package.json"
    click Composer "https://github.com/varioush/elementor/blob/master/composer.json"
    click Lib "https://github.com/varioush/elementor/tree/master/assets/lib/"
    click RemoteService "https://github.com/varioush/elementor/blob/master/includes/template-library/sources/remote.php"

    %% Styles
    classDef php fill:#e0f2f1,stroke:#00695c,color:#004d40
    classDef jsEditor fill:#e3f2fd,stroke:#1e88e5,color:#0d47a1
    classDef jsFrontend fill:#e8eaf6,stroke:#3949ab,color:#1a237e
    classDef build fill:#fff3e0,stroke:#fb8c00,color:#e65100
    classDef external fill:#eceff1,stroke:#90a4ae,color:#37474f
```
