# jgraph/mxgraph architecture

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

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

## Overview

This project is mxGraph – a client‐side JavaScript diagramming library that uses SVG and HTML for rendering. Although its development is over, its file tree shows a multi-language ecosystem: the core library is written in JavaScript while wrappers or examples exist in Java and .NET. The README emphasizes that mxGraph is designed to work in any framework “vanilla JS” style and provides extensive documentation, examples, and API specs. In short, this is both a diagramming library’s source code and an ecosystem of examples and documentation.

##### Main components
- Core Client-Side Library – the central engine, including files such as mxClient.js, the model (e.g. mxGraphModel, mxCell), view (e.g. mxGraphView, mxCellRenderer), and controller aspects (event handlers, key handlers, etc.).
- Layout and Algorithm Modules – components for various layouts (hierarchical, organic, tree, etc.). Note directories like “layout” in both JavaScript and Java source trees.
- IO and Serialization – modules that encode/decode graphs (e.g. mxCodec, mxObjectCodec, XML conversion modules in both JavaScript and .NET).
- Documentation and Examples – the comprehensive “docs” directory (with manuals, API specs, and examples in various languages) and the “javascript/examples”, “java/examples”, and “dotnet” subtrees that serve as integration or demo apps.
- Cross-Platform Adapters/Wrappers – in addition to the core JavaScript code, there are examples and projects for .NET and Java that show how the library can be integrated in different environments.
- Build and Deployment Tools – configuration files like package.json, Gruntfiles, npm ignore, and various project files (.csproj, .sln for .NET or build.xml for Java) that indicate build processes.

- Core library at the center, with internal layers clearly delineated:
– A “View” layer that renders the model on the browser (SVG or HTML via mxGraphView, mxRenderer, etc.).
– A “Controller” or “Event Handling” layer managing user interactions (via mxCellTracker, mxKeyboardHandler, etc.).
- IO subsystem as a separate component that interfaces with the model – responsible for encoding/decoding graphs into XML.
- Build/deployment components as auxiliary services that package the core library and examples.

##### Architectural patterns and design principles
- MVC-like Separation – the internal structure follows a model (graph data), view (rendered display), and controller (user actions) paradigm.
- Cross-Platform Integration – by providing wrappers and examples in Java, .NET, and JavaScript, the design showcases an adaptable core engine that is technology agnostic.
- Lightweight and Framework-Free – designed to integrate into any system without third-party dependencies.

##### Relevant technologies and frameworks
- JavaScript (Vanilla JS) with SVG and HTML for rendering.
- Build tools found in package.json and Gruntfile.js.
- Examples in Java and .NET which use their native project file formats and build configuration.
- Use of XML for file storage and serialization.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Library
    CoreLib["Core Client-Side Library"]:::core

    %% MVC Layers Subgraph
    subgraph "MVC Layers"
        Model["Model (mxGraphModel, mxCell)"]:::mvc
        View["View (mxGraphView, mxCellRenderer)"]:::mvc
        Controller["Controller/Event Handlers (mxKeyHandler, mxPopupMenuHandler)"]:::mvc
    end

    %% Rendering Engine Subgraph
    subgraph "Rendering Engine"
        Rendering["Rendering Layer (SVG/HTML Canvas)"]:::rendering
        Shapes["Shape Modules (mxShape, mxRectangleShape, etc.)"]:::rendering
        Utilities["Canvas & Drawing Utilities"]:::rendering
    end

    %% Algorithm & IO Subgraph
    subgraph "Algorithm & IO"
        Layouts["Layout Algorithms (mxHierarchicalLayout, mxCircleLayout)"]:::algorithms
        Hierarchical["Hierarchical Layout Submodule"]:::algorithms
        IO["IO & Serialization (mxCodec, mxObjectCodec, mxGraphCodec)"]:::io
    end

    %% Documentation & Examples Subgraph
    subgraph "Documentation & Examples"
        Docs["Documentation (Manuals, API specs, Tutorials)"]:::docs
        JsExamples["JavaScript Examples"]:::examples
        JavaExamples["Java Examples"]:::examples
        DotnetExamples[".NET Examples"]:::examples
    end

    %% Cross-Platform Adapters Subgraph
    subgraph "Cross-Platform Adapters"
        JavaWrappers["Java Wrappers/Integration"]:::adapters
        DotnetWrappers[".NET Wrappers/Integration"]:::adapters
    end

    %% Build & Deployment Tools Subgraph
    subgraph "Build & Deployment Tools"
        JSBuild["JS Build Tools"]:::build
        DotnetBuild[".NET Project Files"]:::build
        JavaBuild["Java Build File"]:::build
    end

    %% Relationships
    CoreLib -->|"provides"| Model
    CoreLib -->|"provides"| View
    CoreLib -->|"provides"| Controller
    CoreLib -->|"integrates with"| Rendering

    Controller -->|"triggersUpdate"| Model
    Controller -->|"triggersUpdate"| View
    View -->|"rendersBasedOn"| Model

    Rendering -->|"employs"| Shapes
    Rendering -->|"employs"| Utilities

    IO -->|"encodes/decodes"| Model
    Layouts -->|"appliedTo"| Model
    Layouts -->|"uses"| Hierarchical

    Docs -->|"documents"| CoreLib
    JsExamples -->|"demonstrates"| CoreLib

    JavaExamples -->|"demonstrates"| JavaWrappers
    DotnetExamples -->|"demonstrates"| DotnetWrappers
    JavaWrappers -->|"wraps"| CoreLib
    DotnetWrappers -->|"wraps"| CoreLib

    JSBuild -->|"packages"| CoreLib
    JSBuild -->|"packages"| JsExamples
    DotnetBuild -->|"packages"| DotnetExamples
    JavaBuild -->|"packages"| JavaExamples

    %% Class connections between subgraphs (optional additional integration)
    IO --- Layouts
    Docs --- JsExamples

    %% Click Events
    click CoreLib "https://github.com/jgraph/mxgraph/blob/master/javascript/src/js/mxClient.js"
    click CoreLib "https://github.com/jgraph/mxgraph/blob/master/docs/js-api/files/mxClient-js.html"
    click Model "https://github.com/jgraph/mxgraph/tree/master/javascript/src/js/model"
    click View "https://github.com/jgraph/mxgraph/tree/master/javascript/src/js/view"
    click Controller "https://github.com/jgraph/mxgraph/tree/master/javascript/src/js/handler"
    click Shapes "https://github.com/jgraph/mxgraph/tree/master/javascript/src/js/shape"
    click Utilities "https://github.com/jgraph/mxgraph/tree/master/javascript/src/js/util"
    click Layouts "https://github.com/jgraph/mxgraph/tree/master/javascript/src/js/layout"
    click Hierarchical "https://github.com/jgraph/mxgraph/tree/master/javascript/src/js/layout/hierarchical"
    click IO "https://github.com/jgraph/mxgraph/tree/master/javascript/src/js/io"
    click Docs "https://github.com/jgraph/mxgraph/tree/master/docs"
    click JsExamples "https://github.com/jgraph/mxgraph/tree/master/javascript/examples"
    click DotnetExamples "https://github.com/jgraph/mxgraph/tree/master/dotnet"
    click JavaExamples "https://github.com/jgraph/mxgraph/tree/master/java/examples"
    click JavaWrappers "https://github.com/jgraph/mxgraph/tree/master/java"
    click DotnetWrappers "https://github.com/jgraph/mxgraph/tree/master/dotnet"
    click JSBuild "https://github.com/jgraph/mxgraph/blob/master/package.json"
    click JSBuild "https://github.com/jgraph/mxgraph/blob/master/etc/build/Gruntfile.js"
    click DotnetBuild "https://github.com/jgraph/mxgraph/blob/master/dotnet/mxgraph-dotnet.csproj"
    click DotnetBuild "https://github.com/jgraph/mxgraph/blob/master/dotnet/aspnet/aspnet.csproj"
    click DotnetBuild "https://github.com/jgraph/mxgraph/blob/master/mxgraph-dotnet.sln"
    click JavaBuild "https://github.com/jgraph/mxgraph/blob/master/java/build.xml"

    %% Styles
    classDef core fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef mvc fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef rendering fill:#ccccff,stroke:#0000cc,stroke-width:2px;
    classDef algorithms fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
    classDef io fill:#e6ccff,stroke:#9933cc,stroke-width:2px;
    classDef docs fill:#ccffff,stroke:#009999,stroke-width:2px;
    classDef examples fill:#ffd633,stroke:#cc6600,stroke-width:2px;
    classDef adapters fill:#d9d9d9,stroke:#808080,stroke-width:2px;
    classDef build fill:#c9daf8,stroke:#0b5394,stroke-width:2px;
```
