# rungwiroon/blazorgooglemaps architecture

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

- Interactive diagram: https://gitdiagram.com/rungwiroon/blazorgooglemaps
- Repository: https://github.com/rungwiroon/blazorgooglemaps

## Overview

This project is a Blazor-based library and demonstration suite that provides interop with the Google Maps JavaScript API. In other words, it is a specialized open-source tool designed to enable Blazor applications to easily integrate Google Maps functionality. The repository contains a core library (GoogleMapsComponents) that encapsulates all of the map types, markers, overlays, event-handling and other related classes, plus two demo applications (ClientSideDemo and ServerSideDemo) that illustrate how to use the library in both Blazor WebAssembly and Blazor Server contexts.

##### Main components
- Core Library – GoogleMapsComponents: This is where nearly all of the functionality is encapsulated. It contains various namespaces, classes, and helper functions related to maps, markers, overlays, event objects, and even serialization.
- Client-Side Demo – ClientSideDemo: A Blazor WebAssembly application demonstrating usage of the library. It includes pages (for example, Maps.razor, MapMarker.razor, etc.), shared components for layout/navigation and uses the library through dependency injection.
- Server-Side Demo – ServerSideDemo: A Blazor Server application with similar pages to the client-side demo, also showcasing the library’s features. It uses standards like _Host.cshtml for server-side hosting.
- Configuration and Build Infrastructure – Including GitHub workflows, package.json, and solution-level files (BlazorGoogleMaps.sln) for project management and CI/CD.

##### Component Relationships and Interactions
- The GoogleMapsComponents library is the core that provides the map components (like GoogleMap, AdvancedGoogleMap, MarkerComponent, etc.) and the supporting classes representing different map features (e.g., markers, overlays, layers).
- Both Demo projects (ClientSideDemo and ServerSideDemo) consume the library. They set up a dependency injection container (via Startup.cs) that registers the Google Maps key service (IBlazorGoogleMapsKeyService) and load options.
- The demos interact with the library’s components in their pages by including the UI components (e.g., <GoogleMap>, <AdvancedGoogleMap>) and passing configuration options and event handlers.
- Deployment and pipeline configuration is handled in the .github directory, which ensures continuous integration builds run when changes occur.

##### Architectural Patterns and Design Principles
- Component-Based Architecture: The project is built around reusable Blazor components that encapsulate both the display logic and mapping functionality.
- Dependency Injection: Services are added and managed (for example, Google Maps API key services) ensuring the application is configurable, testable, and maintainable.
- Separation of Concerns: The core mapping functionalities are split into multiple dedicated classes and namespaces (e.g., Maps/Data, Maps/Controls, Maps/Places, etc.), which then get consumed by higher-level UI components.

##### Technologies and Frameworks
- Blazor (WebAssembly for ClientSideDemo and Server for ServerSideDemo) serves as the foundation for the UI.
- .NET (with migrations to .NET 8) forms the runtime environment.
- Google Maps JavaScript API (integrated via external script loading, along with additional extras like MarkerClusterer) provides the underlying mapping engine.
- JavaScript interop: The library includes JavaScript files (e.g., objectManager.js) to manage direct interactions with the Google Maps API.
- System.Text.Json for JSON serialization (note the migration from Newtonsoft.Json).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "DevOps & Config"
        CD["CI/CD & Workflows"]:::config
        SOL["Solution & Package Management"]:::config
    end

    CS["ClientSideDemo (Blazor WebAssembly)"]:::demo
    GS["GoogleMapsComponents (Core Library)"]:::library
    SS["ServerSideDemo (Blazor Server)"]:::demo
    API["Google Maps JavaScript API"]:::external

    %% Demo projects use the core library
    CS -->|"uses"| GS
    SS -->|"uses"| GS

    %% Core library makes external JS interop calls
    GS -->|"JSInterop"| API

    %% DevOps & Config manage all projects
    SOL -->|"ProjMgmt"| CS
    SOL -->|"ProjMgmt"| GS
    SOL -->|"ProjMgmt"| SS
    CD -->|"CI/CD"| CS
    CD -->|"CI/CD"| GS
    CD -->|"CI/CD"| SS

    %% Click Events
    click GS "https://github.com/rungwiroon/blazorgooglemaps/tree/master/GoogleMapsComponents/"
    click CS "https://github.com/rungwiroon/blazorgooglemaps/tree/master/ClientSideDemo/"
    click SS "https://github.com/rungwiroon/blazorgooglemaps/tree/master/ServerSideDemo/"
    click CD "https://github.com/rungwiroon/blazorgooglemaps/blob/master/.github/workflows/main.yml"
    click SOL "https://github.com/rungwiroon/blazorgooglemaps/blob/master/BlazorGoogleMaps.sln"

    %% Styles
    classDef demo fill:#bbf,stroke:#333,stroke-width:2px;
    classDef library fill:#f9c,stroke:#333,stroke-width:2px;
    classDef external fill:#cfc,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef config fill:#fcc,stroke:#333,stroke-width:2px;
    
    %% Arrange vertical layout
    CS --- GS
    GS --- SS
```
