# magento/meta-for-magento2 architecture

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

- Interactive diagram: https://gitdiagram.com/magento/meta-for-magento2
- Repository: https://github.com/magento/meta-for-magento2

## Overview

##### And list the main components
- Magento Core and Admin Panel – representing the base Magento platform where the extension is installed.
- Meta Modules:
- BusinessExtension: Handles the initial setup, configuration, and management of the Facebook & Instagram connection.
- Catalog: Deals with product data, catalog syncing, and feed generation for Facebook.
- Conversion: Implements tracking functionalities (Pixel, Conversion events) and integrates with the Facebook API to capture user actions.
- Promotions: Manages promotional feeds and the integration for advertising campaigns.
- Sales: Handles API endpoints and business logic for cart operations, checkout, orders, refunds, and order syncing with Facebook.
- External Services:
- Facebook Business SDK / Meta Business API (Graph API): Used to connect, send data, and receive responses from the Meta platform.

##### Interactions and relationships
- Magento Admin Panel triggers actions (via Controllers and Ajax calls) that interact with the respective module’s Blocks and Helpers.
- Each module is designed using Magento’s service contracts (API interfaces defined in the code) and dependency injection (see extensive use of “di.xml” for both adminhtml and frontend areas).
- Cron jobs in modules such as BusinessExtension, Catalog, Conversion, Sales, and Promotions periodically synchronize data, update configurations, or trigger log actions.
- Observers and Plugins are integrated into Magento’s event-driven system to intercept certain actions such as product updates, order creation, or configuration changes.
- External API calls (via Helper classes like GraphAPIAdapter and SDK integrations) bridge the Magento system with Facebook’s advertising and analytics endpoints.

##### Important architectural patterns and design principles
- Modular Architecture – each functional area is encapsulated into distinct modules (BusinessExtension, Catalog, etc.) to promote separation of concerns.
- Dependency Injection – the project uses di.xml files extensively to manage class dependencies and configuration.
- Service Contracts – interfaces under the Api and Model directories define clear APIs for internal and external communication.
- Event-Driven Design – use of Observers and Plugins allows seamless integration with Magento’s event system.
- Cron and Asynchronous Processing – scheduled tasks handle background operations like data sync and cleanup.
- UI Separation – Adminhtml Blocks, Controllers, and templates manage the presentation logic, especially for setting up and configuring Meta features.

##### Additional details to capture
- Use of configuration files (xml files such as acl.xml, routes.xml, module.xml), which dictate module behavior and integrations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Magento Core & Admin Panel"]:::magento

    subgraph "Meta Extension Modules"
        B["Meta_BusinessExtension"]:::module
        C["Meta_Catalog"]:::module
        D["Meta_Conversion"]:::module
        E["Meta_Promotions"]:::module
        F["Meta_Sales"]:::module
    end

    G["External Facebook Services"]:::external
    CR["Cron Jobs"]:::cron

    A -->|"triggers configuration"| B
    A -->|"triggers catalog_sync"| C
    A -->|"triggers_conversion_tracking"| D
    A -->|"triggers_promotions_setup"| E
    A -->|"triggers_sales_operations"| F

    B -->|"API_call"| G
    D -->|"tracking_events"| G

    CR -->|"data_sync"| B
    CR -->|"data_sync"| C
    CR -->|"data_sync"| D
    CR -->|"data_sync"| E
    CR -->|"data_sync"| F

    click B "https://github.com/magento/meta-for-magento2/tree/main/app/code/Meta/BusinessExtension"
    click C "https://github.com/magento/meta-for-magento2/tree/main/app/code/Meta/Catalog"
    click D "https://github.com/magento/meta-for-magento2/tree/main/app/code/Meta/Conversion"
    click E "https://github.com/magento/meta-for-magento2/tree/main/app/code/Meta/Promotions"
    click F "https://github.com/magento/meta-for-magento2/tree/main/app/code/Meta/Sales"
    click G "https://github.com/magento/meta-for-magento2/blob/main/app/code/Meta/BusinessExtension/Helper/GraphAPIAdapter.php"

    classDef magento fill:#fce,stroke:#333,stroke-width:2px;
    classDef module fill:#bbf,stroke:#000,stroke-width:2px;
    classDef external fill:#faa,stroke:#800,stroke-width:2px;
    classDef cron fill:#cfc,stroke:#080,stroke-width:2px;
```
