# rnmapbox/maps architecture

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

- Interactive diagram: https://gitdiagram.com/rnmapbox/maps
- Repository: https://github.com/rnmapbox/maps

## Overview

##### Main Components
- React Native Components: In the “src/” folder, you find the higher-level components (MapView, various layers, sources, and modules). These are the JavaScript/TypeScript interfaces that app developers use.
- Native Modules: In the “android/” and “ios/” directories, the native code (in Java/Kotlin for Android, Objective-C/Swift for iOS) implements modules exposed to React Native. This includes detailed packages for Mapbox integration (e.g., components for camera, annotations, layers, offline, and style management).
- Bridging Layer: Both native directories and the “src/specs/” indicate that there is a well-defined bridging mechanism that translates JS calls to native operations.
- Testing & Examples: The “__tests__” and “example/” directories provide integration tests and usage examples that demonstrate how the components interact and operate in a real app.
- Build and Automation Tools: Directories like “scripts/”, “plugin/”, and CI workflows in “.github/workflows” reveal the build, test automation, and code generation processes.
- Documentation: The “docs/” folder and README illustrate available features and external documentation for developers.

##### Relationships and Interactions
- Integration Points: The native modules are tightly coupled with the underlying Mapbox SDKs (different implementations for v10 and beta v11 are supported) and expose functionality used by React Native components.
- Testing and Debugging: Include interactions with Jest testing modules and automated workflows (CI/CD pipelines) which validate both the JS and native parts.
- Build & Code Generation: Illustrate how scripts (in “scripts/” and the plugin directory) auto-generate code, templates, and help produce native bindings.
- Offline and Snapshot Management: Represent these modules as specialized services that manage data cache and image snapshot generation, interacting with both native and JavaScript layers.

##### Architectural Patterns
- Bridge Pattern: Emphasize the clear separation between the cross-platform JavaScript layer and the platform-specific native implementations.
- Modularization: The file tree reveals a strong modular design where each type of Mapbox functionality (e.g., layers, sources, offline functionality) has its own directory, keeping the architecture maintainable.
- Cross-Platform Abstraction: The layering that abstracts native implementations for iOS and Android into a common React Native interface.
- Testing and CI Integration: Automated tests, code generation scripts, and continuous integration workflows reinforce good engineering practices.

##### Relevant Technologies and Frameworks
- React Native and JavaScript/TypeScript: The primary framework and language used in “src/” and “example/”.
- Native Android (Java/Kotlin) and iOS (Objective-C/Swift) SDKs: Found in the “android/” and “ios/” directories.
- Mapbox Native SDKs: The underlying mapping SDKs (from Mapbox for Android and iOS).
- Build Tools: Gradle for Android, Xcode build configurations for iOS, and Node.js/NPM scripts for JavaScript builds.
- Testing Frameworks: Jest (with provided mocks) and additional test scripts in “__tests__/”.

##### Specific Elements
- Clear labels for every component: React Native components (MapView, Layers, Annotations), native modules (Android packages, iOS classes), bridge layer, testing examples, and CI/CD pipeline.

Summary:
- The top layer of public-facing React Native components (from “src/” and usage in “example/”).
- The bridging layer that links these components to the platform-specific native modules.
- Two distinct native layers (Android and iOS) that implement the Mapbox Maps SDK APIs.
- Auxiliary components such as documentation, testing, build scripts, and the plugin code that facilitates integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% React Native API Layer
    subgraph "React Native API"
        MapView["MapView"]:::js
        Annotation["Annotation"]:::js
        SymbolLayer["SymbolLayer"]:::js
    end

    %% Bridging Layer
    subgraph "Bridging Layer"
        JSBridge["JS Bridge"]:::bridge
        iOSBridge["iOS Bridge"]:::bridge
    end

    %% Native Modules Layer
    subgraph "Native Modules"
        AndroidNative["Android Native Modules"]:::native
        iOSNative["iOS Native Modules"]:::native
    end

    %% Auxiliary Tools and Documentation
    subgraph "Auxiliary Tools"
        Testing["Testing & Examples"]:::aux
        BuildAutomation["Build & Automation Tools"]:::aux
        Documentation["Documentation"]:::aux
    end

    %% Data Flow from React Native Components to the Bridge
    MapView -->|"calls"| JSBridge
    Annotation -->|"calls"| JSBridge
    SymbolLayer -->|"calls"| JSBridge

    %% Bridge invoking Native Modules
    JSBridge -->|"invokes"| AndroidNative
    JSBridge -->|"invokes"| iOSNative
    iOSBridge -->|"invokes"| iOSNative

    %% Testing validates across layers
    Testing -->|"validates"| MapView
    Testing -->|"validates"| JSBridge
    Testing -->|"validates"| AndroidNative
    Testing -->|"validates"| iOSNative

    %% Build Automation generates code for bridge and native modules
    BuildAutomation -->|"generates"| JSBridge
    BuildAutomation -->|"generates"| AndroidNative
    BuildAutomation -->|"generates"| iOSNative

    %% Documentation describes components and flows
    Documentation -->|"describes"| MapView
    Documentation -->|"describes"| JSBridge
    Documentation -->|"describes"| AndroidNative
    Documentation -->|"describes"| iOSNative

    %% Click Events for Component Mapping
    click MapView "https://github.com/rnmapbox/maps/blob/main/src/components/MapView.tsx"
    click Annotation "https://github.com/rnmapbox/maps/blob/main/src/components/Annotation.tsx"
    click SymbolLayer "https://github.com/rnmapbox/maps/blob/main/src/components/SymbolLayer.tsx"
    click JSBridge "https://github.com/rnmapbox/maps/tree/main/src/specs"
    click iOSBridge "https://github.com/rnmapbox/maps/tree/main/ios/RNMBX/Bridge"
    click AndroidNative "https://github.com/rnmapbox/maps/tree/main/android/src/main/java/com/rnmapbox/rnmbx"
    click iOSNative "https://github.com/rnmapbox/maps/tree/main/ios/RNMBX"
    click Testing "https://github.com/rnmapbox/maps/tree/main/__tests__"
    click BuildAutomation "https://github.com/rnmapbox/maps/tree/main/scripts/"
    click Documentation "https://github.com/rnmapbox/maps/tree/main/docs/"

    %% Styles
    classDef js fill:#fdf6e3,stroke:#333,stroke-width:2px;
    classDef bridge fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef native fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef aux fill:#fff3cd,stroke:#333,stroke-width:2px;
```
