# spatie/laravel-sitemap architecture

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

- Interactive diagram: https://gitdiagram.com/spatie/laravel-sitemap
- Repository: https://github.com/spatie/laravel-sitemap

## Overview

##### Main Components Identification
The system should be represented with these key components:

a. Core Components:
- SitemapGenerator (Central orchestrator)
- Sitemap (Base sitemap handler)
- SitemapIndex (Index handler)
- Crawler System (URL discovery and processing)
- Tag System (URL, Image, Video, News handlers)

b. External Integrations:
- Laravel Framework
- Filesystem Interface
- Headless Chrome (for JavaScript execution)
- HTTP Client (Guzzle)

**Top Layer: Entry Points**

**Middle Layer: Core Services**

**Bottom Layer: Storage & External Services**

##### Component Relationships

a. Entry Points:
- How SitemapGenerator can be accessed via Laravel's service provider
- Command-line interface for scheduled generation

b. Core Processing Flow:
- SitemapGenerator → Crawler → URL Discovery
- URL Processing → Tag System → XML Generation
- Sitemap/SitemapIndex → Storage Interface

##### Specific Implementation Details

Key architectural patterns:

a. Service Layer:
- SitemapServiceProvider as the entry point
- Configuration injection system

b. Contract/Interface Layer:
- Sitemapable interface implementation
- Crawler profiles system

c. Tag System:
- Inheritance hierarchy for different tag types (URL, Image, Video, News)

##### Key Processes to Highlight

a. Sitemap Generation Flow:
**URL Input → Crawler → URL Discovery → Tag Generation → XML Output**

b. Custom Implementation Flow:
**Model → Sitemapable Interface → Tag Generation → Sitemap Integration**

##### Important Notes

- Flexibility of the crawler configuration
- Multiple output options (file/disk storage)
- JavaScript execution capability
- Index generation process

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Entry
        SP[SitemapServiceProvider]
        CLI[Command Line Interface]
        Config[Configuration]
    end

    subgraph Core
        SG[SitemapGenerator]
        SM[Sitemap]
        SI[SitemapIndex]
    end

    subgraph "Crawler System"
        CO[Crawler Observer]
        CP[Crawler Profile]
    end

    subgraph "Tag System"
        TG[Base Tag]
        UT[URL Tag]
        IT[Image Tag]
        VT[Video Tag]
        NT[News Tag]
        AT[Alternate Tag]
    end

    subgraph "Contracts"
        SI_C[Sitemapable Interface]
    end

    subgraph "External Services"
        HC[Headless Chrome]
        FS[Filesystem]
        GZ[Guzzle HTTP]
    end

    subgraph "Templates"
        ST["Sitemap Templates"]
        SIT["SitemapIndex Templates"]
    end

    %% Relationships
    SP --> SG
    CLI --> SG
    Config --> SG
    
    SG --> CO
    SG --> SM
    SG --> SI
    
    CO --> CP
    CP --> GZ
    CP --> HC
    
    SM --> TG
    SI --> SIT
    
    TG --> UT
    TG --> IT
    TG --> VT
    TG --> NT
    TG --> AT
    
    UT --> ST
    IT --> ST
    VT --> ST
    NT --> ST
    
    SM --> FS
    SI --> FS
    
    SI_C --> SG

    %% Styling
    classDef core fill:#a8d1ff,stroke:#333
    classDef external fill:#90EE90,stroke:#333
    classDef contract fill:#FFE5CC,stroke:#333
    classDef template fill:#FFB6C1,stroke:#333
    
    class SG,SM,SI core
    class HC,FS,GZ external
    class SI_C contract
    class ST,SIT template

    %% Click events
    click SP "https://github.com/spatie/laravel-sitemap/blob/main/src/SitemapServiceProvider.php"
    click Config "https://github.com/spatie/laravel-sitemap/blob/main/config/sitemap.php"
    click SG "https://github.com/spatie/laravel-sitemap/blob/main/src/SitemapGenerator.php"
    click SM "https://github.com/spatie/laravel-sitemap/blob/main/src/Sitemap.php"
    click SI "https://github.com/spatie/laravel-sitemap/blob/main/src/SitemapIndex.php"
    click CO "https://github.com/spatie/laravel-sitemap/blob/main/src/Crawler/Observer.php"
    click CP "https://github.com/spatie/laravel-sitemap/blob/main/src/Crawler/Profile.php"
    click TG "https://github.com/spatie/laravel-sitemap/blob/main/src/Tags/Tag.php"
    click UT "https://github.com/spatie/laravel-sitemap/blob/main/src/Tags/Url.php"
    click IT "https://github.com/spatie/laravel-sitemap/blob/main/src/Tags/Image.php"
    click VT "https://github.com/spatie/laravel-sitemap/blob/main/src/Tags/Video.php"
    click NT "https://github.com/spatie/laravel-sitemap/blob/main/src/Tags/News.php"
    click AT "https://github.com/spatie/laravel-sitemap/blob/main/src/Tags/Alternate.php"
    click SI_C "https://github.com/spatie/laravel-sitemap/blob/main/src/Contracts/Sitemapable.php"
    click ST "https://github.com/spatie/laravel-sitemap/tree/main/resources/views"
    click SIT "https://github.com/spatie/laravel-sitemap/tree/main/resources/views/sitemapIndex"
```
