# radarlabs/radar-sdk-js architecture

> Architecture diagram of the GitHub repository radarlabs/radar-sdk-js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/radarlabs/radar-sdk-js
- Repository: https://github.com/radarlabs/radar-sdk-js

## Overview

##### Component Breakdown

Client Integration Layer:
- Two main integration methods:
- NPM Package Integration
- Direct Script Tag Integration

SDK Core (divide into these subsystems):
- API Module:

- UI Module:
- RadarMap, RadarMarker, RadarPopup, and Autocomplete components
- Their relationship with the core map rendering system

- Core Services:
- Configuration Management (config.ts)
- Session Management (session.ts)
- Device Management (device.ts)
- HTTP Client (http.ts)
- Storage Service (storage.ts)

- Utilities:
- GeoJSON Processing
- JWT Handling
- Network Utilities
- Polyline Processing

##### External Services Layer

Connections to:
- MapLibre GL (required dependency)
- Radar Backend Services
- Browser APIs (Geolocation, Storage)

##### Technical Details

- TypeScript usage (indicated by .ts files)
- Build system components (Rollup, Babel)
- Testing framework (Jest)
- CI/CD pipeline (CircleCI)

##### Implementation Notes

Annotations for:
- Initialization process
- Error handling
- Event system
- Storage mechanisms

Use these visual elements:
- Rectangles: Main components
- Rounded rectangles: Services
- Hexagons: External dependencies

- Light blue: UI components
- Green: API services
- Yellow: Core services
- Gray: External services
- Red: Critical paths

- Grouping related components
- Using consistent spacing
- Adding clear labels
- Using layers to show hierarchy

- Handles location services
- Manages map rendering
- Processes geofencing
- Integrates with external services
- Maintains state and configuration

Remember to include version information and note any deprecated or beta features, as indicated by the MIGRATION.md file's presence in the project.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef api fill:#90EE90,stroke:#333,stroke-width:2px
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef core fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef util fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef entry fill:#FFA07A,stroke:#333,stroke-width:2px

    %% Client Integration Layer
    subgraph Integration
        NPM["NPM Package"]
        Script["Script Tag"]
    end

    %% Main Entry Point
    Entry["SDK Entry Point"]:::entry
    click Entry "https://github.com/radarlabs/radar-sdk-js/blob/master/src/index.ts"

    %% Core Services
    subgraph CoreServices
        Config["Configuration Management"]:::core
        Session["Session Management"]:::core
        Device["Device Management"]:::core
        HTTP["HTTP Client"]:::core
        Storage["Storage Service"]:::core
        Navigator["Navigation Service"]:::core
        Logger["Logging System"]:::core
        ErrorHandler["Error Handling"]:::core
        Version["Version Management"]:::core

        click Config "https://github.com/radarlabs/radar-sdk-js/blob/master/src/config.ts"
        click Session "https://github.com/radarlabs/radar-sdk-js/blob/master/src/session.ts"
        click Device "https://github.com/radarlabs/radar-sdk-js/blob/master/src/device.ts"
        click HTTP "https://github.com/radarlabs/radar-sdk-js/blob/master/src/http.ts"
        click Storage "https://github.com/radarlabs/radar-sdk-js/blob/master/src/storage.ts"
        click Navigator "https://github.com/radarlabs/radar-sdk-js/blob/master/src/navigator.ts"
        click Logger "https://github.com/radarlabs/radar-sdk-js/blob/master/src/logger.ts"
        click ErrorHandler "https://github.com/radarlabs/radar-sdk-js/blob/master/src/errors.ts"
        click Version "https://github.com/radarlabs/radar-sdk-js/blob/master/src/version.ts"
    end

    %% API Module
    subgraph APIModule
        Addresses["Addresses API"]:::api
        Geocoding["Geocoding API"]:::api
        Routing["Routing API"]:::api
        Search["Search API"]:::api
        Track["Track API"]:::api
        Trips["Trips API"]:::api
        Verify["Verify API"]:::api

        click Addresses "https://github.com/radarlabs/radar-sdk-js/blob/master/src/api/addresses.ts"
        click Geocoding "https://github.com/radarlabs/radar-sdk-js/blob/master/src/api/geocoding.ts"
        click Routing "https://github.com/radarlabs/radar-sdk-js/blob/master/src/api/routing.ts"
        click Search "https://github.com/radarlabs/radar-sdk-js/blob/master/src/api/search.ts"
        click Track "https://github.com/radarlabs/radar-sdk-js/blob/master/src/api/track.ts"
        click Trips "https://github.com/radarlabs/radar-sdk-js/blob/master/src/api/trips.ts"
        click Verify "https://github.com/radarlabs/radar-sdk-js/blob/master/src/api/verify.ts"
    end

    %% UI Module
    subgraph UIModule
        Map["RadarMap"]:::ui
        Marker["RadarMarker"]:::ui
        Popup["RadarPopup"]:::ui
        Autocomplete["Autocomplete"]:::ui
        LineFeature["Line Feature"]:::ui
        PolygonFeature["Polygon Feature"]:::ui

        click Map "https://github.com/radarlabs/radar-sdk-js/blob/master/src/ui/RadarMap.ts"
        click Marker "https://github.com/radarlabs/radar-sdk-js/blob/master/src/ui/RadarMarker.ts"
        click Popup "https://github.com/radarlabs/radar-sdk-js/blob/master/src/ui/RadarPopup.ts"
        click Autocomplete "https://github.com/radarlabs/radar-sdk-js/blob/master/src/ui/autocomplete.ts"
        click LineFeature "https://github.com/radarlabs/radar-sdk-js/blob/master/src/ui/RadarLineFeature.ts"
        click PolygonFeature "https://github.com/radarlabs/radar-sdk-js/blob/master/src/ui/RadarPolygonFeature.ts"
    end

    %% Utilities
    subgraph Utils
        GeoJSON["GeoJSON Processing"]:::util
        JWT["JWT Handling"]:::util
        Network["Network Utilities"]:::util
        Polyline["Polyline Processing"]:::util

        click GeoJSON "https://github.com/radarlabs/radar-sdk-js/blob/master/src/util/geojson.ts"
        click JWT "https://github.com/radarlabs/radar-sdk-js/blob/master/src/util/jwt.ts"
        click Network "https://github.com/radarlabs/radar-sdk-js/blob/master/src/util/net.ts"
        click Polyline "https://github.com/radarlabs/radar-sdk-js/blob/master/src/util/polyline.ts"
    end

    %% External Services
    subgraph External
        MapLibre["MapLibre GL"]:::external
        RadarBackend["Radar Backend"]:::external
        BrowserAPIs["Browser APIs"]:::external
    end

    %% Connections
    NPM --> Entry
    Script --> Entry
    Entry --> CoreServices
    Entry --> APIModule
    Entry --> UIModule
    CoreServices --> External
    APIModule --> CoreServices
    UIModule --> CoreServices
    UIModule --> Utils
    APIModule --> Utils
    CoreServices --> Utils

    %% Legend
    subgraph Legend
        L1["API Components"]:::api
        L2["UI Components"]:::ui
        L3["Core Services"]:::core
        L4["Utilities"]:::util
        L5["External Services"]:::external
        L6["Entry Points"]:::entry
    end
```
