# symfony/brevo-mailer architecture

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

- Interactive diagram: https://gitdiagram.com/symfony/brevo-mailer
- Repository: https://github.com/symfony/brevo-mailer

## Overview

##### Main Components and Their Purpose
- Symfony Mailer Integration: At the highest level, this library plugs into Symfony Mailer to allow easy configuration for outgoing emails.
- Transport Layer: This is the core of the integration.
- BrevoApiTransport: Handles sending emails using Brevo’s API.
- BrevoSmtpTransport: Manages email delivery via SMTP.
- BrevoTransportFactory: Implements a factory or strategy pattern to instantiate the appropriate transport (SMTP or API) based on the DSN configuration.
- Webhook Component: Contains BrevoRequestParser, which is responsible for parsing incoming webhooks (delivery reports, bounces, etc.) from Brevo.
- Remote Event Handling: The RemoteEvent/BrevoPayloadConverter acts to transform or convert payloads (or events) received from Brevo, ensuring they’re in the valid format for further processing.
- Testing: The Tests folder contains extensive test cases with fixtures for both transport and webhook functionalities. This layer validates the expected behavior of the integration.

##### Diagramming Relationships and Interactions
- Inside the Brevo Bridge block, identify two major subcomponents:
- Transport Layer (with sub-components: BrevoTransportFactory, BrevoApiTransport, and BrevoSmtpTransport)
- Webhook Processor (BrevoRequestParser and, implicitly, RemoteEvent/BrevoPayloadConverter for processing events)
- How email messages flow: from the Mailer to the chosen transport, then out to Brevo.
- Additionally, show the callback flow for inbound events where webhook events are parsed by BrevoRequestParser and potentially transformed by BrevoPayloadConverter before being returned to the application’s event-handling system.
- Optionally, include a “Testing” section on the side to represent all the tests that simulate these flows and validate component interactions.

##### Highlighting Architectural Patterns and Technologies
- Factory Pattern used in BrevoTransportFactory for dynamic transport selection.
- Strategy or Adapter mechanisms that let the system support different transport protocols (SMTP vs. API) seamlessly.
- Mention that configuration is driven by DSNs (as provided in the README), so an external configuration management aspect is inherent to this design.
- Integration with Symfony’s existing mailing and header management constructs, such as custom metadata and tag headers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A("Application/Symfony Mailer"):::mailer

    subgraph "Brevo Bridge"
        subgraph "Transport Layer"
            B1["BrevoTransportFactory"]:::transportFactory
            B2["BrevoApiTransport"]:::transport
            B3["BrevoSmtpTransport"]:::transport
        end
        subgraph "Webhook Processor"
            W1["BrevoRequestParser"]:::webhook
            W2["BrevoPayloadConverter"]:::webhook
        end
    end

    B4["Brevo (External)"]:::external
    T["Testing"]:::testing

    A -->|"sendsEmail"| B1
    B1 -->|"usesAPI"| B2
    B1 -->|"usesSMTP"| B3
    B2 -->|"deliversEmail"| B4
    B3 -->|"deliversEmail"| B4
    B4 -->|"webhookEvent"| W1
    W1 -->|"parsesWebhook"| W2

    T --- B1
    T --- B2
    T --- B3
    T --- W1
    T --- W2

    click B1 "https://github.com/symfony/brevo-mailer/blob/7.2/Transport/BrevoTransportFactory.php"
    click B2 "https://github.com/symfony/brevo-mailer/blob/7.2/Transport/BrevoApiTransport.php"
    click B3 "https://github.com/symfony/brevo-mailer/blob/7.2/Transport/BrevoSmtpTransport.php"
    click W1 "https://github.com/symfony/brevo-mailer/blob/7.2/Webhook/BrevoRequestParser.php"
    click W2 "https://github.com/symfony/brevo-mailer/blob/7.2/RemoteEvent/BrevoPayloadConverter.php"
    click T "https://github.com/symfony/brevo-mailer/tree/7.2/Tests"

    classDef mailer fill:#ffd966,stroke:#333,stroke-width:2px;
    classDef transportFactory fill:#9fc5e8,stroke:#333,stroke-width:2px;
    classDef transport fill:#6d9eeb,stroke:#333,stroke-width:2px;
    classDef webhook fill:#b6d7a8,stroke:#333,stroke-width:2px;
    classDef external fill:#aba7d5,stroke:#333,stroke-width:2px;
    classDef testing fill:#bbbbbb,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
```
