# mageprince/magento2-mage-ai architecture

> Architecture diagram of the GitHub repository mageprince/magento2-mage-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mageprince/magento2-mage-ai
- Repository: https://github.com/mageprince/magento2-mage-ai

## Overview

MageAI is a Magento admin extension for generating product descriptions and creating or editing product and category images with OpenAI, Anthropic, and Gemini. The principal workflow begins in the catalog editor, reaches an admin controller, prepares prompts and catalog context, calls an AI operation, then returns content or form-compatible image data for review and saving. The graph preserves the separate product and category image paths and shared configuration, prompt, and storage layers. Some frontend wiring and dependency injection are not excerpted, so their connections are omitted or documented from the README.

Main entry points: [`Helper/Data.php`](https://github.com/mageprince/magento2-mage-ai/blob/master/Helper/Data.php) (AI settings), [`Model/Query/ImageGeneration.php`](https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/ImageGeneration.php) (Image generation APIs), [`Model/Query/ImageModification.php`](https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/ImageModification.php) (Image editing APIs), [`Controller/Adminhtml/Index/GenerateImage.php`](https://github.com/mageprince/magento2-mage-ai/blob/master/Controller/Adminhtml/Index/GenerateImage.php) (Product image generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_admin["Admin workflows"]
  node_description_ui["Description editor<br/>[Editor.php]"]
  node_product_description["Product descriptions<br/>[Generate.php]"]
  node_product_image_generate["Product image generation<br/>[GenerateImage.php]"]
  node_product_image_modify["Product image editing<br/>[ModifyImage.php]"]
  node_category_image_generate["Category image generation<br/>[GenerateImage.php]"]
  node_category_image_modify["Category image editing<br/>[ModifyImage.php]"]
end

subgraph group_prompt["Prompt and settings"]
  node_settings["AI settings<br/>[Data.php]"]
  node_attribute_format["Attribute formatting<br/>[Formatter.php]"]
  node_category_prompt["Category prompt rendering<br/>[PromptRenderer.php]"]
  node_config_options["Provider and model options"]
end

subgraph group_ai["AI operations"]
  node_completions["Text completion APIs<br/>[Completions.php]"]
  node_image_generation["Image generation APIs"]
  node_image_modification["Image editing APIs"]
end

subgraph group_media["Image media"]
  node_storage_interface["Image storage contract"]
  node_shared_storage["Shared media handling"]
  node_product_storage[("Product gallery storage<br/>[ImageStorage.php]")]
  node_category_storage[("Category image storage")]
end

node_catalog_user(("Catalog editor user"))
node_ai_providers{{"AI providers"}}

node_catalog_user -->|"opens editor"| node_description_ui
node_description_ui -->|"requests text"| node_product_description
node_catalog_user -->|"requests image"| node_product_image_generate
node_catalog_user -->|"requests edit"| node_product_image_modify
node_catalog_user -->|"requests banner"| node_category_image_generate
node_catalog_user -->|"requests edit"| node_category_image_modify
node_product_description -->|"reads settings"| node_settings
node_product_description -->|"requests completion"| node_completions
node_completions -->|"reads settings"| node_settings
node_completions -->|"formats attributes"| node_attribute_format
node_product_image_generate -->|"reads settings"| node_settings
node_product_image_generate -->|"formats attributes"| node_attribute_format
node_product_image_generate -->|"requests image"| node_image_generation
node_product_image_modify -->|"reads settings"| node_settings
node_product_image_modify -->|"formats attributes"| node_attribute_format
node_product_image_modify -->|"requests edit"| node_image_modification
node_category_image_generate -->|"reads settings"| node_settings
node_category_image_generate -->|"renders prompt"| node_category_prompt
node_category_image_generate -->|"requests image"| node_image_generation
node_category_image_modify -->|"reads settings"| node_settings
node_category_image_modify -->|"renders prompt"| node_category_prompt
node_category_image_modify -->|"requests edit"| node_image_modification
node_image_generation -->|"reads settings"| node_settings
node_image_generation -->|"persists image"| node_storage_interface
node_image_modification -->|"reads settings"| node_settings
node_image_modification -->|"reads and persists"| node_storage_interface
node_image_generation -->|"calls provider"| node_ai_providers
node_image_modification -->|"calls provider"| node_ai_providers
node_completions -->|"calls provider"| node_ai_providers
node_shared_storage -->|"implements"| node_storage_interface
node_product_storage -->|"extends"| node_shared_storage
node_category_storage -->|"extends"| node_shared_storage
node_settings -->|"supplies options"| node_config_options

click node_description_ui "https://github.com/mageprince/magento2-mage-ai/blob/master/Data/Form/Element/Editor.php"
click node_product_description "https://github.com/mageprince/magento2-mage-ai/blob/master/Controller/Adminhtml/Index/Generate.php"
click node_product_image_generate "https://github.com/mageprince/magento2-mage-ai/blob/master/Controller/Adminhtml/Index/GenerateImage.php"
click node_product_image_modify "https://github.com/mageprince/magento2-mage-ai/blob/master/Controller/Adminhtml/Index/ModifyImage.php"
click node_category_image_generate "https://github.com/mageprince/magento2-mage-ai/blob/master/Controller/Adminhtml/Category/GenerateImage.php"
click node_category_image_modify "https://github.com/mageprince/magento2-mage-ai/blob/master/Controller/Adminhtml/Category/ModifyImage.php"
click node_settings "https://github.com/mageprince/magento2-mage-ai/blob/master/Helper/Data.php"
click node_attribute_format "https://github.com/mageprince/magento2-mage-ai/blob/master/Model/AttributeData/Formatter.php"
click node_category_prompt "https://github.com/mageprince/magento2-mage-ai/blob/master/Model/CategoryData/PromptRenderer.php"
click node_config_options "https://github.com/mageprince/magento2-mage-ai/tree/master/Model/Config/Source"
click node_completions "https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/Completions.php"
click node_image_generation "https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/ImageGeneration.php"
click node_image_modification "https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/ImageModification.php"
click node_storage_interface "https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/ImageStorageInterface.php"
click node_shared_storage "https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/AbstractImageStorage.php"
click node_product_storage "https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/ImageStorage.php"
click node_category_storage "https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/CategoryImageStorage.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_description_ui,node_product_description,node_product_image_generate,node_product_image_modify,node_category_image_generate,node_category_image_modify,node_catalog_user toneBlue
class node_settings,node_attribute_format,node_category_prompt,node_config_options toneAmber
class node_completions,node_image_generation,node_image_modification toneMint
class node_storage_interface,node_shared_storage,node_product_storage,node_category_storage toneRose
class node_ai_providers toneIndigo
```

## Components

### Admin workflows

- [Description editor](https://github.com/mageprince/magento2-mage-ai/blob/master/Data/Form/Element/Editor.php): `Data/Form/Element/Editor.php`
- [Product descriptions](https://github.com/mageprince/magento2-mage-ai/blob/master/Controller/Adminhtml/Index/Generate.php): `Controller/Adminhtml/Index/Generate.php`
- [Product image generation](https://github.com/mageprince/magento2-mage-ai/blob/master/Controller/Adminhtml/Index/GenerateImage.php): `Controller/Adminhtml/Index/GenerateImage.php`
- [Product image editing](https://github.com/mageprince/magento2-mage-ai/blob/master/Controller/Adminhtml/Index/ModifyImage.php): `Controller/Adminhtml/Index/ModifyImage.php`
- [Category image generation](https://github.com/mageprince/magento2-mage-ai/blob/master/Controller/Adminhtml/Category/GenerateImage.php): `Controller/Adminhtml/Category/GenerateImage.php`
- [Category image editing](https://github.com/mageprince/magento2-mage-ai/blob/master/Controller/Adminhtml/Category/ModifyImage.php): `Controller/Adminhtml/Category/ModifyImage.php`

### Prompt and settings

- [AI settings](https://github.com/mageprince/magento2-mage-ai/blob/master/Helper/Data.php): `Helper/Data.php`
- [Attribute formatting](https://github.com/mageprince/magento2-mage-ai/blob/master/Model/AttributeData/Formatter.php): `Model/AttributeData/Formatter.php`
- [Category prompt rendering](https://github.com/mageprince/magento2-mage-ai/blob/master/Model/CategoryData/PromptRenderer.php): `Model/CategoryData/PromptRenderer.php`
- [Provider and model options](https://github.com/mageprince/magento2-mage-ai/tree/master/Model/Config/Source): `Model/Config/Source`

### AI operations

- [Text completion APIs](https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/Completions.php): `Model/Query/Completions.php`
- [Image generation APIs](https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/ImageGeneration.php): `Model/Query/ImageGeneration.php`
- [Image editing APIs](https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/ImageModification.php): `Model/Query/ImageModification.php`

### Image media

- [Image storage contract](https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/ImageStorageInterface.php): `Model/Query/ImageStorageInterface.php`
- [Shared media handling](https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/AbstractImageStorage.php): `Model/Query/AbstractImageStorage.php`
- [Product gallery storage](https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/ImageStorage.php): `Model/Query/ImageStorage.php`
- [Category image storage](https://github.com/mageprince/magento2-mage-ai/blob/master/Model/Query/CategoryImageStorage.php): `Model/Query/CategoryImageStorage.php`

### Other components

- **Catalog editor user**
- **AI providers**

## Connections

- Catalog editor user → Description editor: opens editor (evidence: `README.md`)
- Description editor → Product descriptions: requests text (evidence: `README.md`)
- Catalog editor user → Product image generation: requests image (evidence: `README.md`)
- Catalog editor user → Product image editing: requests edit (evidence: `README.md`)
- Catalog editor user → Category image generation: requests banner (evidence: `README.md`)
- Catalog editor user → Category image editing: requests edit (evidence: `README.md`)
- Product descriptions → AI settings: reads settings (evidence: `Controller/Adminhtml/Index/Generate.php`)
- Product descriptions → Text completion APIs: requests completion (evidence: `Controller/Adminhtml/Index/Generate.php`)
- Text completion APIs → AI settings: reads settings (evidence: `Model/Query/Completions.php`)
- Text completion APIs → Attribute formatting: formats attributes (evidence: `Model/Query/Completions.php`)
- Product image generation → AI settings: reads settings (evidence: `Controller/Adminhtml/Index/GenerateImage.php`)
- Product image generation → Attribute formatting: formats attributes (evidence: `Controller/Adminhtml/Index/GenerateImage.php`)
- Product image generation → Image generation APIs: requests image (evidence: `Controller/Adminhtml/Index/GenerateImage.php`)
- Product image editing → AI settings: reads settings (evidence: `Controller/Adminhtml/Index/ModifyImage.php`)
- Product image editing → Attribute formatting: formats attributes (evidence: `Controller/Adminhtml/Index/ModifyImage.php`)
- Product image editing → Image editing APIs: requests edit (evidence: `Controller/Adminhtml/Index/ModifyImage.php`)
- Category image generation → AI settings: reads settings (evidence: `Controller/Adminhtml/Category/GenerateImage.php`)
- Category image generation → Category prompt rendering: renders prompt (evidence: `Controller/Adminhtml/Category/GenerateImage.php`)
- Category image generation → Image generation APIs: requests image (evidence: `Controller/Adminhtml/Category/GenerateImage.php`)
- Category image editing → AI settings: reads settings (evidence: `Controller/Adminhtml/Category/ModifyImage.php`)
- Category image editing → Category prompt rendering: renders prompt (evidence: `Controller/Adminhtml/Category/ModifyImage.php`)
- Category image editing → Image editing APIs: requests edit (evidence: `Controller/Adminhtml/Category/ModifyImage.php`)
- Image generation APIs → AI settings: reads settings (evidence: `Model/Query/ImageGeneration.php`)
- Image generation APIs → Image storage contract: persists image (evidence: `Model/Query/ImageGeneration.php`)
- Image editing APIs → AI settings: reads settings (evidence: `Model/Query/ImageModification.php`)
- Image editing APIs → Image storage contract: reads and persists (evidence: `Model/Query/ImageModification.php`)
- Image generation APIs → AI providers: calls provider (evidence: `README.md`)
- Image editing APIs → AI providers: calls provider (evidence: `README.md`)
- Text completion APIs → AI providers: calls provider (evidence: `README.md`)
- Shared media handling → Image storage contract: implements (evidence: `Model/Query/AbstractImageStorage.php`)
- Product gallery storage → Shared media handling: extends (evidence: `Model/Query/ImageStorage.php`)
- Category image storage → Shared media handling: extends (evidence: `Model/Query/CategoryImageStorage.php`)
- AI settings → Provider and model options: supplies options (evidence: `Model/Config/Source/AIProvider.php`)
