# visgl/react-map-gl architecture

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

- Interactive diagram: https://gitdiagram.com/visgl/react-map-gl
- Repository: https://github.com/visgl/react-map-gl

## Overview

##### Project Type and Purpose
- This is an open-source monorepo library (“react-map-gl”) that provides a React component API for two mapping engines (Mapbox-GL and MapLibre-GL).
- It is organized with Lerna, delivering three core packages:
- modules/main – the shared core logic for both engines
- modules/react-mapbox – the React façade for Mapbox-GL
- modules/react-maplibre – the React façade for MapLibre-GL
- The repo also includes: examples (playgrounds), docs (API reference & guides), a website (Docusaurus-based), tests, CI/CD workflows, and build scripts.

##### File-Structure Analysis
- Top-level:
- modules/ (actual NPM packages)
- examples/ (many sub-folders showing usage scenarios)
- docs/ & website/ (documentation and marketing site source)
- test/ & modules/*/test (unit, integration, rendering tests)
- .github/workflows (CI pipelines), scripts/ (release management)
- Key patterns:
- Monorepo with Lerna + Yarn/NPM workspaces
- Modular architecture: core + two platform-specific adapters
- Standard React component library: src/components, src/utils, src/types

##### README Insights
- Describes installation, usage examples for both Mapbox and MapLibre back ends.
- Points to online documentation for design philosophy and getting started guides.

##### Diagramming the Architecture
a. Main Components
- Core Package (modules/main)
- Adapter Packages (modules/react-mapbox, modules/react-maplibre)
- External Dependencies (mapbox-gl, maplibre-gl, React, D3?)
- Consumers:
- Examples (apps under examples/)
- Documentation Site (website/)
- End-user apps (via npm install react-map-gl)
- CI/CD: GitHub Actions, release scripts
- Testing Harness (test/ folder, Jest/Mocha, snapshots)
b. Relationships & Data Flow
- Core exports low-level bindings and shared utilities → imported by both adapter packages
- Adapters wrap core exports into React components → published to NPM
- Examples & website import adapter packages → build and serve via Vite / Docusaurus
- CI workflows trigger tests → build → release scripts update npm packages and website
c. Architectural Patterns / Principles
- Monorepo modularization (single source, multi-package)
- Adapter (core logic + two separate platform adapters)
- Facade pattern (React components abstracting Mapbox/MapLibre APIs)
- Separation of concerns (core vs. adapters vs. docs vs. examples vs. CI)
d. Technologies / Frameworks
- React (>=16.3), TypeScript
- mapbox-gl / maplibre-gl
- Lerna (monorepo), NPM/Yarn workspaces
- Vite (dev server for examples), Docusaurus (website)
- Jest / React Testing Library / snapshot testing
- GitHub Actions (test, release, website deploy)

- Core → Adapters (import relationship)
- Adapters → Examples/Website/End-User (usage)
- CI/CD → Tests → Build → Release (workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Monorepo Packages
  subgraph "Monorepo Packages"
    direction TB
    Core["modules/main<br/>Core Package"]:::core
    Adapter1["modules/react-mapbox<br/>React Mapbox Adapter"]:::adapter
    Adapter2["modules/react-maplibre<br/>React MapLibre Adapter"]:::adapter
  end

  %% Consumers
  subgraph "Consumers"
    direction TB
    Examples["examples/ (Playgrounds)"]:::consumer
    Docs["docs/ (API Documentation)"]:::consumer
    Website["website/ (Docusaurus Site)"]:::consumer
    EndUser["End-user Apps"]:::consumer
  end

  %% CI/CD & Scripts
  subgraph "CI/CD & Scripts"
    direction TB
    Workflows[".github/workflows/"]:::cicd
    Scripts["scripts/"]:::cicd
    Build["Build & Release"]:::cicd
  end

  %% Tests
  subgraph "Test Suites"
    direction TB
    SharedTests["test/ (Shared Tests Harness)"]:::test
    CoreTests["modules/main/test/"]:::test
    Adapter1Tests["modules/react-mapbox/test/"]:::test
    Adapter2Tests["modules/react-maplibre/test/"]:::test
  end

  %% Monorepo Config
  Config["Monorepo Config<br/>lerna.json, package.json, tsconfig.json"]:::config

  %% External Dependencies
  subgraph "External Dependencies"
    direction TB
    MapboxGL["mapbox-gl"]:::external
    MapLibreGL["maplibre-gl"]:::external
    ReactDep["React"]:::external
    D3["D3"]:::external
    TS["TypeScript"]:::external
  end

  %% Relationships
  Core -->|"provides bindings"| Adapter1
  Core -->|"provides bindings"| Adapter2
  Adapter1 -->|"wraps into React components"| ReactDep
  Adapter2 -->|"wraps into React components"| ReactDep
  Adapter1 -->|"imports"| MapboxGL
  Adapter2 -->|"imports"| MapLibreGL
  Examples -->|"imports adapters"| Adapter1
  Examples -->|"imports adapters"| Adapter2
  Docs -->|"imports adapters"| Adapter1
  Docs -->|"imports adapters"| Adapter2
  Website -->|"renders docs site"| Docs
  EndUser -->|"npm install packages"| Adapter1
  EndUser -->|"npm install packages"| Adapter2

  Workflows -->|"runs tests"| SharedTests
  Workflows -->|"runs tests"| CoreTests
  Workflows -->|"runs tests"| Adapter1Tests
  Workflows -->|"runs tests"| Adapter2Tests
  Workflows -->|"runs build"| Build
  Build -->|"updates packages & site"| Scripts
  Scripts -->|"deploys site"| Website

  Config -->|"configures monorepo"| Core
  Config -->|"configures monorepo"| Adapter1
  Config -->|"configures monorepo"| Adapter2

  %% Click Events
  click Core "https://github.com/visgl/react-map-gl/tree/master/modules/main"
  click Adapter1 "https://github.com/visgl/react-map-gl/tree/master/modules/react-mapbox"
  click Adapter2 "https://github.com/visgl/react-map-gl/tree/master/modules/react-maplibre"
  click Examples "https://github.com/visgl/react-map-gl/tree/master/examples/"
  click Docs "https://github.com/visgl/react-map-gl/tree/master/docs/"
  click Website "https://github.com/visgl/react-map-gl/tree/master/website/"
  click Workflows "https://github.com/visgl/react-map-gl/tree/master/.github/workflows/"
  click Scripts "https://github.com/visgl/react-map-gl/tree/master/scripts/"
  click Config "https://github.com/visgl/react-map-gl/blob/master/lerna.json"
  click SharedTests "https://github.com/visgl/react-map-gl/tree/master/test/"
  click CoreTests "https://github.com/visgl/react-map-gl/tree/master/modules/main/test/"
  click Adapter1Tests "https://github.com/visgl/react-map-gl/tree/master/modules/react-mapbox/test/"
  click Adapter2Tests "https://github.com/visgl/react-map-gl/tree/master/modules/react-maplibre/test/"

  %% Styles
  classDef core fill:#FFD966,stroke:#333,stroke-width:1px;
  classDef adapter fill:#8FAADC,stroke:#333,stroke-width:1px;
  classDef consumer fill:#C6E0B4,stroke:#333,stroke-width:1px;
  classDef cicd fill:#F4B183,stroke:#333,stroke-width:1px;
  classDef test fill:#D9D2E9,stroke:#333,stroke-width:1px;
  classDef config fill:#CCCCCC,stroke:#333,stroke-width:1px;
  classDef external fill:#FFFFFF,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5;
```
