# jgraph/mxgraph-js architecture

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

- Interactive diagram: https://gitdiagram.com/jgraph/mxgraph-js
- Repository: https://github.com/jgraph/mxgraph-js

## Overview

##### Main Components
- Model: Files under “javascript/src/js/model” that manage graph data (cells, geometry, etc.).
- View: Components under “javascript/src/js/view” that handle rendering, cell states, selections, and outlining.
- Layout: Multiple layout engines found in “javascript/src/js/layout” (such as hierarchical, circle, organic, etc.).
- Utilities and Infrastructure: “javascript/src/js/util” contains utilities for events, animations, AJAX (mxXmlRequest), and other helper functions.
- IO/Codecs: Under “javascript/src/js/io” which manage encoding/decoding of graph and style configurations.

- Examples / Demos – The “javascript/examples” directory is filled with HTML demos, different configuration files for editors, and even a “grapheditor” folder which contains both client-side scripts and a Java-based backend. These demos clearly show how consumers of the library integrate and use the provided components.

- Resource and Configuration Files – Files such as configuration XMLs, CSS files, and resource bundles (found in “javascript/src/resources” and similar folders in examples) support customization and internationalization.

##### Relationships and Data Flow
- How different layers interact: The UI (examples/demos) calls into the Editor Components, which in turn depend on the Core Library for rendering, layout, and graph manipulation.
- Feedback loop between user events (via handler files) and updates to the view and model.
- For the demos, demonstrate how external scripts (HTML pages and sample JS files) instantiate and use instances of the mxGraph core classes.

##### Architectural Patterns and Design Principles
- Modular Architecture: The code is clearly separated by functionality (model, view, controller – via event handlers).
- Reusability and Extensibility: The structure supports multiple editors and sample usage scenarios, demonstrating layered design. The separation into core utility, I/O, layout engines, etc., is key.
- Event-Driven Interaction: The handlers’ folder shows that user interaction triggers events that propagate through the system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Library Module
    subgraph "Core Library Module"
        A["Graph Model"]:::core
        B["Graph View"]:::core
        C["Layout Engine"]:::core
        D["Shapes & Stencils"]:::core
        E["Utilities & Infrastructure"]:::core
        F["IO/Codecs"]:::core
    end

    %% Event Handling & Interaction Layer
    subgraph "Event Handling & Interaction"
        G["Event Handlers"]:::interaction
    end

    %% Editor Components
    subgraph "Editor Components"
        H["Editor (Source)"]:::editor
        I["Editor (Examples)"]:::editor
    end

    %% Demo & External Integration
    subgraph "Demo & External Integration"
        J["Demo Applications"]:::example
        K["Graph Editor (Java)"]:::external
    end

    %% Resources & Configuration
    subgraph "Resources & Configuration"
        L["JS Resources"]:::resource
        M["Editor Config"]:::resource
    end

    %% Relationships
    %% Editor components trigger event handling
    H -->|"triggers"| G
    I -->|"triggers"| G
    J -->|"triggers"| G

    %% Resources injected into Editors
    L -->|"configures"| H
    L -->|"configures"| I
    M -->|"configures"| H
    M -->|"configures"| I

    %% Event Handlers update Core Library
    G -->|"updates"| A
    G -->|"updates"| B
    G -->|"updates"| C
    G -->|"updates"| D
    G -->|"updates"| E
    G -->|"updates"| F

    %% Core Library internal interactions
    A -->|"render"| B
    C -->|"layout-update"| B

    %% External Integration
    K -->|"integrates"| J

    %% Styling Classes
    classDef core fill:#B3E5FC,stroke:#0277BD,stroke-width:2px;
    classDef interaction fill:#FFCC80,stroke:#FB8C00,stroke-width:2px;
    classDef editor fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef example fill:#FFF9C4,stroke:#F9A825,stroke-width:2px;
    classDef external fill:#F8BBD0,stroke:#C2185B,stroke-width:2px;
    classDef resource fill:#D1C4E9,stroke:#7E57C2,stroke-width:2px;

    %% Click Events for Component Mapping
    click A "https://github.com/jgraph/mxgraph-js/tree/master/javascript/src/js/model"
    click B "https://github.com/jgraph/mxgraph-js/tree/master/javascript/src/js/view"
    click C "https://github.com/jgraph/mxgraph-js/tree/master/javascript/src/js/layout"
    click D "https://github.com/jgraph/mxgraph-js/tree/master/javascript/src/js/shape"
    click E "https://github.com/jgraph/mxgraph-js/tree/master/javascript/src/js/util"
    click F "https://github.com/jgraph/mxgraph-js/tree/master/javascript/src/js/io"
    click G "https://github.com/jgraph/mxgraph-js/tree/master/javascript/src/js/handler"
    click H "https://github.com/jgraph/mxgraph-js/tree/master/javascript/src/js/editor"
    click I "https://github.com/jgraph/mxgraph-js/tree/master/javascript/examples/editors"
    click J "https://github.com/jgraph/mxgraph-js/tree/master/javascript/examples"
    click K "https://github.com/jgraph/mxgraph-js/tree/master/javascript/examples/grapheditor"
    click L "https://github.com/jgraph/mxgraph-js/tree/master/javascript/src/resources"
    click M "https://github.com/jgraph/mxgraph-js/tree/master/javascript/examples/editors/config"
```
