# sxguojf/three-tile architecture

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

- Interactive diagram: https://gitdiagram.com/sxguojf/three-tile
- Repository: https://github.com/sxguojf/three-tile

## Overview

##### Main Components Identification
- Core Library (packages/lib) – This is the heart of the project. It contains all the core functionalities broken into submodules like geometry (definition of terrain and tile geometries), loader (handling various tile and image loaders such as those for image, terrain LERC, and terrain RGB), map (managing the tile map, events, and projections), material (defining tile materials and shaders), source (handling tile sources), and tile (managing tile instances).
- Plugin Package (packages/plugin) – This layer extends the core library’s capabilities. It contains plugins for additional data sources (e.g., ArcGIS, Bing, Google, MapTiler, TDT, and more), utilities like geoJSON loader, compass, fog, and additional tile loaders. These modules integrate with the core library to provide extended functionality.

##### Analyzing the File Structure for Architectural Patterns
- The separation into “lib”, “plugin”, and “demo” suggests a layered architecture. The demo (presentation layer) uses the core library (domain logic and core services), which is further extensible via the plugin modules.
- Within the core library, a modular design is visible: modules like geometry, loader, map, material, source, and tile are separated into distinct directories. This modularity follows principles like separation of concerns and encapsulation of functionality.
- The use of Vite for building the demo and possibly the plugins indicates a modern front-end build system. TypeScript is used across the project ensuring type safety and maintainability.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Technologies Section
    subgraph "Technologies"
        TS("TypeScript"):::external
        Vite("Vite"):::external
        ThreeJS("Three.js"):::external
    end

    %% Core Library Section
    subgraph "Core Library"
        Geometry("Geometry Module"):::core
        Loader("Loader Module"):::core
        MapMod("Map Module"):::core
        Material("Material Module"):::core
        Source("Source Module"):::core
        Tile("Tile Module"):::core
    end

    %% Plugin Package Section
    subgraph "Plugin Package"
        MapSource("Map Source Plugins"):::plugin
        GeoJSON("GeoJSON Loader"):::plugin
        Compass("Compass Plugin"):::plugin
        Fog("Fog Plugin"):::plugin
        OtherLoaders("Other Loader Plugins"):::plugin
    end

    %% Presentation Layer Section
    subgraph "Presentation Layer"
        Demo("Demo Application"):::demo
    end

    %% Relationships: Core Library Flow
    Demo -->|"calls"| MapMod
    Demo -->|"utilizes"| Loader
    Demo -->|"utilizes"| Source
    Loader -->|"feedsData"| MapMod
    Geometry -->|"providesGeometry"| MapMod
    Material -->|"rendersWith"| ThreeJS
    MapMod -->|"outputsTo"| Material
    Source -->|"createsTiles"| Tile
    Loader -->|"suppliesData"| Source

    %% Plugin Package integrations into Core Library
    MapSource -->|"enhancesData"| Loader
    GeoJSON -->|"enhancesData"| Loader
    OtherLoaders -->|"enhancesData"| Loader
    Compass -->|"augmentsUI"| Demo
    Fog -->|"appliesEffect"| Material

    %% Underlying Technologies integration
    TS --> Geometry
    TS --> Loader
    TS --> MapMod
    TS --> Material
    TS --> Source
    TS --> Tile
    TS --> MapSource
    TS --> GeoJSON
    TS --> Compass
    TS --> Fog
    TS --> OtherLoaders
    Vite --> Demo

    %% Click Events for Component Mappings
    click Geometry "https://github.com/sxguojf/three-tile/tree/master/packages/lib/src/geometry"
    click Loader "https://github.com/sxguojf/three-tile/tree/master/packages/lib/src/loader"
    click MapMod "https://github.com/sxguojf/three-tile/tree/master/packages/lib/src/map"
    click Material "https://github.com/sxguojf/three-tile/tree/master/packages/lib/src/material"
    click Source "https://github.com/sxguojf/three-tile/tree/master/packages/lib/src/source"
    click Tile "https://github.com/sxguojf/three-tile/tree/master/packages/lib/src/tile"
    click MapSource "https://github.com/sxguojf/three-tile/tree/master/packages/plugin/src/mapSource"
    click GeoJSON "https://github.com/sxguojf/three-tile/tree/master/packages/plugin/src/geojsonLoader"
    click Compass "https://github.com/sxguojf/three-tile/tree/master/packages/plugin/src/compass"
    click Fog "https://github.com/sxguojf/three-tile/tree/master/packages/plugin/src/fog"
    click OtherLoaders "https://github.com/sxguojf/three-tile/tree/master/packages/plugin/src"
    click Demo "https://github.com/sxguojf/three-tile/tree/master/packages/demo"

    %% Styles
    classDef core fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef plugin fill:#FFCC99,stroke:#333,stroke-width:2px;
    classDef demo fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef external fill:#ffeeaa,stroke:#333,stroke-width:2px;
```
