# prestaconcept/prestasitemapbundle architecture

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

- Interactive diagram: https://gitdiagram.com/prestaconcept/prestasitemapbundle
- Repository: https://github.com/prestaconcept/prestasitemapbundle

## Overview

##### Project type and purpose
- It’s a Symfony “bundle” (i.e., a reusable package) plugged into any Symfony application.
- Purpose: collect configured routes (static & dynamic), decorate them (images, video, mobile, multilang), then expose sitemaps via HTTP or dump them to XML files (optionally via Symfony Messenger).

##### File structure
- config/ (XML/YML DI, routing & messenger configs)
- src/
- DependencyInjection (bundle extension, config definition)
- Controller (SitemapController serving on-the-fly)
- Command (CLI entry DumpSitemapsCommand)
- Messenger (DumpSitemapMessage & handler)
- Service (Generator, Dumper, UrlContainer interfaces + implementations)
- EventListener (hook into routing & static routes)
- Sitemap (domain classes: Urlset, Url, Decorators, Sitemapindex)
- Tests (Integration using test Symfony apps; Unit tests)

##### README insights
- Describes two delivery modes: HTTP (Controller) and dumped files (Command + Messenger + Dumper).
- No database; it relies on Symfony Router + user callbacks (events) for dynamic URLs.

##### Main architectural components
A. Host Symfony Application
- Kernel
- Router → identifies routes matching “presta_sitemap” patterns
- EventDispatcher → dispatches SitemapPopulateEvent & custom events
- DI Container → loads services.xml, messenger.xml, routing.yml, services.xml
- Messenger Transport (if enabled)
B. PrestaSitemapBundle Components
1. Configuration & Extension (DependencyInjection)
– Reads bundle config (which routes to include)
– Registers services, routing, messenger handlers
2. Event Listeners
– RouteAnnotationEventListener (discovers annotated controllers)
– StaticRoutesAlternateEventListener (adds extra URLs)
3. UrlContainer (in-memory store)
4. Generator (builds Urlset & Sitemapindex objects by iterating UrlContainer)
5. Decorators (UrlDecorator, GoogleImage, GoogleVideo, etc.)
6. Controller (SitemapController)
– Calls Generator → returns HTTP Response with XML
7. Command (DumpSitemapsCommand)
– Optionally dispatches DumpSitemapMessage to Messenger
8. Messenger Handler (DumpSitemapMessageHandler)
– Invokes Dumper → writes files to disk
9. Dumper (implements file-based dumping, respects limits 50k URLs/10MB/file)
C. External Services / Systems
– Filesystem (local or cloud storage)
– Optional message queue (e.g., RabbitMQ, Redis) used by Messenger

##### Relationships & data flow
- HTTP Flow: Browser → Symfony Kernel → Router → SitemapController → Generator → UrlContainer ← (EventDispatcher) ← EventListeners → Decorated Url objects → Xml builder (Utils) → HTTP XML Response
- CLI + Async Flow: Console → DumpSitemapsCommand → (dispatch message) → Messenger Transport → DumpSitemapMessageHandler → Generator → Dumper → Filesystem (writes sitemapindex + urlset XML files)

##### Architectural patterns & design principles
- Dependency Injection (services wired via XML/YML)
- Event‐Driven (Symfony EventDispatcher for URL collection hooks)
- Command Bus / Messaging (Symfony Messenger for async dumping)
- Decorator Pattern (UrlDecorator classes for media enrichments)
- Single Responsibility (separate Generator vs Dumper vs Controller vs Handler)

##### Essential elements
- Clear component names matching code (e.g., SitemapController, DumpSitemapsCommand, DumpSitemapMessageHandler)
- Notes on extension points (events, decorators)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actors
    Browser["Browser (HTTP Request)"]:::external
    Console["Console (CLI)"]:::external

    %% Symfony Application Container
    subgraph "Symfony Application"
        direction TB
        subgraph "Core Symfony Services"
            direction TB
            Kernel["Kernel"]:::core
            Router["Router"]:::core
            EventDispatcher["EventDispatcher"]:::core
            DIContainer["DI Container"]:::core
            MessengerTransport["Messenger Transport"]:::core
        end

        subgraph "PrestaSitemapBundle" 
            direction TB
            subgraph "Configuration & Extension"
                direction TB
                ConfigDef["Configuration.php"]:::bundle
                click ConfigDef "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/DependencyInjection/Configuration.php"
                Extension["PrestaSitemapExtension.php"]:::bundle
                click Extension "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/DependencyInjection/PrestaSitemapExtension.php"
                ServicesXML["services.xml"]:::bundle
                click ServicesXML "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/config/services.xml"
                MessengerXML["messenger.xml"]:::bundle
                click MessengerXML "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/config/messenger.xml"
                RoutingYML["routing.yml"]:::bundle
                click RoutingYML "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/config/routing.yml"
                RouteAnnotationListenerXML["route_annotation_listener.xml"]:::bundle
                click RouteAnnotationListenerXML "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/config/route_annotation_listener.xml"
                AlternateListenerXML["alternate_listener.xml"]:::bundle
                click AlternateListenerXML "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/config/alternate_listener.xml"
            end

            subgraph "Event Listeners"
                direction TB
                RouteAnnotationListener["RouteAnnotationEventListener"]:::bundle
                click RouteAnnotationListener "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/EventListener/RouteAnnotationEventListener.php"
                StaticRoutesListener["StaticRoutesAlternateEventListener"]:::bundle
                click StaticRoutesListener "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/EventListener/StaticRoutesAlternateEventListener.php"
            end

            UrlContainer["UrlContainerInterface"]:::bundle
            click UrlContainer "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Service/UrlContainerInterface.php"

            subgraph "Generator"
                direction TB
                GeneratorInterface["GeneratorInterface"]:::bundle
                click GeneratorInterface "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Service/GeneratorInterface.php"
                AbstractGenerator["AbstractGenerator"]:::bundle
                click AbstractGenerator "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Service/AbstractGenerator.php"
                Generator["Generator"]:::bundle
                click Generator "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Service/Generator.php"
            end

            subgraph "Dumper"
                direction TB
                DumperInterface["DumperInterface"]:::bundle
                click DumperInterface "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Service/DumperInterface.php"
                Dumper["Dumper"]:::bundle
                click Dumper "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Service/Dumper.php"
            end

            subgraph "Decorators"
                direction TB
                UrlDecorator["UrlDecorator"]:::bundle
                click UrlDecorator "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Sitemap/Url/UrlDecorator.php"
                ImgDecorator["GoogleImageUrlDecorator"]:::bundle
                click ImgDecorator "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Sitemap/Url/GoogleImageUrlDecorator.php"
                VideoDecorator["GoogleVideoUrlDecorator"]:::bundle
                click VideoDecorator "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Sitemap/Url/GoogleVideoUrlDecorator.php"
                NewsDecorator["GoogleNewsUrlDecorator"]:::bundle
                click NewsDecorator "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Sitemap/Url/GoogleNewsUrlDecorator.php"
                MobileDecorator["GoogleMobileUrlDecorator"]:::bundle
                click MobileDecorator "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Sitemap/Url/GoogleMobileUrlDecorator.php"
                MultilangDecorator["GoogleMultilangUrlDecorator"]:::bundle
                click MultilangDecorator "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Sitemap/Url/GoogleMultilangUrlDecorator.php"
            end

            Controller["SitemapController"]:::bundle
            click Controller "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Controller/SitemapController.php"

            Command["DumpSitemapsCommand"]:::bundle
            click Command "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Command/DumpSitemapsCommand.php"

            subgraph "Messenger (Async Dump)"
                direction TB
                Message["DumpSitemapMessage"]:::bundle
                click Message "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Messenger/DumpSitemapMessage.php"
                Handler["DumpSitemapMessageHandler"]:::bundle
                click Handler "https://github.com/prestaconcept/prestasitemapbundle/blob/4.x/src/Messenger/DumpSitemapMessageHandler.php"
            end
        end
    end

    %% External Resources
    FileSystem[(Filesystem)]:::external
    MessageQueue((Message Queue)):::external

    %% HTTP Flow
    Browser --> Kernel
    Kernel --> Router
    Router --> Controller
    Controller --> Generator
    Generator --> EventDispatcher
    EventDispatcher --> UrlContainer
    UrlContainer --> Decorators
    Decorators --> Controller

    %% CLI + Async Flow
    Console --> Command
    Command --> MessengerTransport
    MessengerTransport --> MessageQueue
    MessageQueue --> Handler
    Handler --> Generator
    Generator --> Dumper
    Dumper --> FileSystem

    %% Dependency Injection wiring
    DIContainer --> ConfigDef
    DIContainer --> Extension
    DIContainer --> ServicesXML
    DIContainer --> MessengerXML
    DIContainer --> RoutingYML

    %% Event Listeners registration
    DIContainer --> RouteAnnotationListener
    DIContainer --> StaticRoutesListener

    %% Class Definitions
    classDef core fill:#D6E9F8,stroke:#333,stroke-width:1px;
    classDef bundle fill:#D4FCDD,stroke:#333,stroke-width:1px;
    classDef external fill:#EBEBEB,stroke:#333,stroke-width:1px;
```
