# geoman-io/leaflet-geoman architecture

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

- Interactive diagram: https://gitdiagram.com/geoman-io/leaflet-geoman
- Repository: https://github.com/geoman-io/leaflet-geoman

## Overview

##### Project Type and Purpose
- This is an open-source Leaflet plugin (“Leaflet-Geoman”) for creating and editing geometry layers on maps.
- Its purpose is to hook into the Leaflet API and provide drawing, editing, snapping, rotating, measuring, and other geometry-related UI controls and utilities.

##### File Structure
- Top-level source:
- Demos: demo/*.html, .js, .css – sample pages that integrate the plugin with Leaflet.
- Tests: cypress/ – end-to-end tests covering each drawing/editing feature.
- Build & config: bundle.mjs (build script), package.json, pnpm-lock.yaml, .github/workflows (CI), eslint, husky, etc.

##### README Insights
- Confirms it’s a Leaflet plugin with Pro/Demo sites, docs, and cypress-based tests.
- Build commands (start, prepare, test, lint) and development workflow.

##### Main Components
a. Core Plugin Layers
- Edit Modules (L.PM.Edit.*)
- Toolbar & Controls (L.PM.Toolbar, L.Controls)
- Mixins (shared behaviors: Events, Dragging, Snapping, Keyboard, Modes)
- Utils & Helpers (Matrix, ModeHelper, turfHelper, polyfills)
b. Assets Layer
- CSS files (controls.css, layers.css)
- Translations (JSON files)
c. Host Application
- Leaflet Map (external dependency)
- Demo pages or downstream app integrating the plugin
d. Testing & CI
- Cypress E2E tests
- GitHub Actions workflows (nodejs.yml, release.yml)
e. Build Pipeline
- bundle.mjs (rollup or custom bundler)
- npm/pnpm scripts (start, prepare, test, lint)

##### Relationships and Data Flow
- Utilities support algorithms (geometry math, snapping, transformations).
- Demo pages import the bundled plugin, initialize on a Leaflet map, and subscribe to plugin events.
- CI pipelines trigger builds and tests on GitHub.

##### Architectural Patterns & Principles
- Mixins for cross-cutting concerns (separation of concerns).
- Event-driven: Leaflet events extended with custom events.
- Plugin pattern: leveraging Leaflet’s L namespace to register functionality.
- Internationalization via JSON translation assets.

##### Essential Elements to Capture
- External dependency on Leaflet core and any third-party libs (turf, Path.Transform)
- Asset pipeline (CSS, translations)
- Demo/consumer and test consumer
- Build & CI flow

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Host Application
    Leaflet["Leaflet Map"]:::external
    DemoPages["Demo Pages"]:::consumer
    TestSuite["Cypress E2E Tests"]:::consumer

    %% Core Plugin Library
    subgraph "Core Plugin" 
        direction TB
        Entry["L.PM.js / L.PM.Map.js / L.PM.Utils.js"]:::core
        Toolbar["Toolbar & Controls"]:::core
        Draw["Draw Modules"]:::core
        Edit["Edit Modules"]:::core
        Mixins["Mixins"]:::core
        Utils["Utils & Helpers"]:::core
    end

    %% Assets Layer
    subgraph "Assets" 
        direction TB
        CSS["CSS Files"]:::assets
        Icons["Icons"]:::assets
        Translations["Translations"]:::assets
    end

    %% Build & CI
    subgraph "Build & CI" 
        direction TB
        Bundler["bundle.mjs"]:::build
        Scripts["npm/pnpm Scripts"]:::build
        CI["GitHub Actions"]:::build
    end

    %% Consumers
    subgraph "Consumers"
        direction TB
        HostApp["Host Application"]:::consumer
        DemoPages
        TestSuite
    end

    %% Relationships
    HostApp -->|imports plugin| Entry
    Entry -->|initializes| Draw
    Entry -->|initializes| Edit
    Entry -->|initializes| Toolbar
    Entry -->|registers| Mixins
    Draw -->|uses| Utils
    Edit -->|uses| Utils
    Toolbar -->|dispatches to| Draw
    Toolbar -->|dispatches to| Edit
    Draw -->|extends| Leaflet
    Edit -->|extends| Leaflet
    CSS -->|bundled into| Bundler
    Icons -->|bundled into| Bundler
    Translations -->|bundled into| Bundler
    Bundler -->|outputs| HostApp
    Scripts -->|run| Bundler
    CI -->|triggers| Scripts
    DemoPages -->|consume| HostApp
    TestSuite -->|test| HostApp

    %% Click Events - Core Plugin
    click Draw "https://github.com/geoman-io/leaflet-geoman/tree/develop/src/js/Draw"
    click Edit "https://github.com/geoman-io/leaflet-geoman/tree/develop/src/js/Edit"
    click Mixins "https://github.com/geoman-io/leaflet-geoman/tree/develop/src/js/Mixins"
    click Utils "https://github.com/geoman-io/leaflet-geoman/tree/develop/src/js/helpers"
    click Toolbar "https://github.com/geoman-io/leaflet-geoman/tree/develop/src/js/Toolbar"
    click Entry "https://github.com/geoman-io/leaflet-geoman/blob/develop/src/js/L.PM.js"
    %% Click Events - Assets
    click CSS "https://github.com/geoman-io/leaflet-geoman/tree/develop/src/css"
    click Icons "https://github.com/geoman-io/leaflet-geoman/tree/develop/src/assets/icons"
    click Translations "https://github.com/geoman-io/leaflet-geoman/blob/develop/src/assets/translations/index.js"
    %% Click Events - Build & CI
    click Bundler "https://github.com/geoman-io/leaflet-geoman/blob/develop/bundle.mjs"
    click Scripts "https://github.com/geoman-io/leaflet-geoman/blob/develop/package.json"
    click CI "https://github.com/geoman-io/leaflet-geoman/blob/develop/.github/workflows/nodejs.yml"
    %% Click Events - Demo & Tests
    click DemoPages "https://github.com/geoman-io/leaflet-geoman/blob/develop/demo/index.html"
    click TestSuite "https://github.com/geoman-io/leaflet-geoman/blob/develop/cypress/e2e/circle.cy.js"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef core fill:#ccf,stroke:#333,stroke-width:1px
    classDef assets fill:#cfc,stroke:#333,stroke-width:1px
    classDef build fill:#fcf,stroke:#333,stroke-width:1px
    classDef consumer fill:#ffc,stroke:#333,stroke-width:1px
```
