Appearance
AI Content Generation Admin
Flow ID: AD-47 | Module(s): Ai (domain layer), ai (legacy module) | Complexity: High Last Updated: 2026-04-04
Business Context
The AI content generation system integrates OpenAI (and potentially other LLM providers) to help administrators generate product descriptions, blog content, category descriptions, and other text content directly within the admin panel. The system has two major subsystems:
Content Generation: The actual text generation pipeline, backed by OpenAI's completion API. Administrators provide a prompt, and the system generates text that can be applied to product fields, blog articles, or other entity fields. Every generation is logged for audit.
AI Positions: Configuration for AI-powered product recommendation widgets on the storefront. Each "position" defines a placement on a specific page (product detail, cart, homepage, etc.) with parameters for recommendation type, minimum items, and request limits.
Both subsystems have full modern domain layers with REST CRUD APIs, while the content generation also has a legacy library layer that integrates directly with OpenAI.
API Reference
REST Endpoints -- Content Generation
| Method | Path | Action | Description |
|---|---|---|---|
| GET | /rest/ai/content-generation | index | List generation log entries (paginated) |
| GET | /rest/ai/content-generation/item | item | Get single entry by filter |
| GET | /rest/ai/content-generation/{id} | show | Get entry by ID |
| POST | /rest/ai/content-generation | store | Create/log a generation entry |
| POST | /rest/ai/content-generation/{id} | update | Update a generation entry |
| DELETE | /rest/ai/content-generation/{id} | destroy | Delete a generation entry |
Filters: id (exact), user (exact), field (exact), entityType (exact), lang (exact) Sorts: id
REST Endpoints -- AI Position
| Method | Path | Action | Description |
|---|---|---|---|
| GET | /rest/ai/position | index | List positions (paginated) |
| GET | /rest/ai/position/item | item | Get single position by filter |
| GET | /rest/ai/position/{id} | show | Get position by ID |
| POST | /rest/ai/position | store | Create a position |
| POST | /rest/ai/position/{id} | update | Update a position |
| DELETE | /rest/ai/position/{id} | destroy | Delete a position |
Filters: id (exact), slug (exact), recommendationType (exact), page (exact), active (exact), title.{locale} (partial via MUI) Sorts: id, slug, title.{locale}Relations: translations (one_to_many)
Legacy Admin Routes
AI settings and content generation are managed through the legacy AI module controllers:
| Route | Controller | Purpose |
|---|---|---|
settings/advisable-ai/(.+) | AdvAdvisableAiSettings | AI provider settings page |
xml/advisable_ai | AdvAdvisableAIXml | AI data feed XML export |
Code Flow
Content Generation (Legacy Library)
- Admin triggers content generation from a product/entity edit page.
- The admin page calls the
AdvContentGenerationlibrary with a prompt string. generate($content, $user, $provider): a. If no provider specified, createsgetDefaultProvider()using OpenAI with registry-stored config. b. Calls$provider->generateCompletion($content, $user)which sends the prompt to OpenAI's completions API. c. Returns the generated text.- The calling controller logs the generation in
ai_content_generationtable via the model. - The generated text is returned to the admin UI for review and application.
Content Generation (REST API)
The REST API primarily serves as a log/audit layer for content generation records:
- POST
/rest/ai/content-generationwith:json{ "user": "admin@example.com", "field": "description", "entityType": "product", "prompt": "Write a description for...", "generatedText": "Generated content...", "lang": "el" } Controllers\ContentGeneration::store()->WriteService::create().WriteData::fromArray()maps to entity columns.- Inserts into
ai_content_generationwith automatic timestamps.
AI Position Management
- GET
/rest/ai/position?filter[active]=1&with=translations - Returns active recommendation positions with localized titles.
- Storefront recommendation widgets query positions by slug to determine which recommendation types to display and how many items to request.
Domain Layer
ContentGeneration (src/Domains/Ai/ContentGeneration/)
| Component | Class | Description |
|---|---|---|
| Entity | Repository\Entity | id, user, field, entity_type, prompt, generated_text, entry_date, entry_datetime, lang |
| Repository | Repository\Repository | Table ai_content_generation |
| RepositoryConfigurator | Repository\RepositoryConfigurator | No relations |
| Service | Service | Read service |
| WriteService | WriteService | Full CRUD |
| WriteData | WriteData | All entity fields as writable properties |
| Validator | Validator | Stub validator |
Position (src/Domains/Ai/Position/)
| Component | Class | Description |
|---|---|---|
| Entity | Repository\Entity | id, slug, recommendation_type, page, min_items, request_limit, active. Implements FilterTranslation |
| MuiEntity | Repository\MuiEntity | MUI translations for position titles |
| Repository | Repository\Repository | Table ai_position |
| MuiRepository | Repository\MuiRepository | Translation repository |
| Service | Service | Read service with MUI filter/sort |
| WriteService | WriteService | Full CRUD with MUI writes |
| WriteData | WriteData | slug, recommendationType, page, minItems, requestLimit, active |
| MuiWriteData | MuiWriteData | Translation write data |
| FilterByTranslation | Specification\FilterByTranslation | MUI join for title filtering |
| SortByTranslation | Specification\SortByTranslation | MUI join for title sorting |
REST Layer (src/Rest/Ai/)
| Component | Class | Description |
|---|---|---|
| Controller | Controllers\ContentGeneration | Full CRUD with HandlesWriteActions |
| Controller | Controllers\Position | Full CRUD with HandlesWriteActions |
| Resource | Resources\ContentGeneration\Resource | Generation log entry resource |
| Resource | Resources\Position\Resource | Position resource with translations |
| MuiResource | Resources\Position\MuiResource | Position translation resource |
DI Container (src/Domains/Ai/container.php)
Registers all ContentGeneration and Position domain services, repositories, write services, and validators.
Architecture
Legacy AI Module (ecommercen/ai/)
| Component | Path | Purpose |
|---|---|---|
AdvContentGeneration | ecommercen/ai/libraries/AdvContentGeneration.php | OpenAI integration library |
AdvAIConnector | ecommercen/ai/libraries/AdvAIConnector.php | HTTP client for AI service |
CoreAIConnector | ecommercen/ai/libraries/CoreAIConnector.php | Core connector abstraction |
AdvAdvisableAI | ecommercen/ai/libraries/AdvAdvisableAI.php | Advisable AI recommendation engine client |
AdvAIRecommendationPages | ecommercen/ai/libraries/AdvAIRecommendationPages.php | Page type definitions for recommendations |
AdvAIRecommendationTypes | ecommercen/ai/libraries/AdvAIRecommendationTypes.php | Recommendation algorithm types |
AdvAIRecommendationViewModel | ecommercen/ai/libraries/AdvAIRecommendationViewModel.php | View model for recommendation widgets |
AdvAiContentGeneration | ecommercen/ai/models/AdvAiContentGeneration.php | Legacy model for generation log |
AdvAIPagePositions | ecommercen/ai/models/AdvAIPagePositions.php | Legacy model for position management |
aiContentGenerationTrait | ecommercen/ai/traits/aiContentGenerationTrait.php | Shared trait for content generation |
AdvAdvisableAiSettings | ecommercen/ai/controllers/AdvAdvisableAiSettings.php | AI settings admin controller |
Modern Layer
| Component | Path | Purpose |
|---|---|---|
| Domain container | src/Domains/Ai/container.php | DI registration |
| REST container | src/Rest/Ai/container.php | REST controller registration |
| REST routes | application/config/rest_routes.php:1249-1278 | Content generation and position routes |
Data Model
ai_content_generation
| Column | Type | Description |
|---|---|---|
id | int (PK) | Auto-increment primary key |
user | varchar | Username who triggered generation |
field | varchar (nullable) | Target entity field (description, title, etc.) |
entity_type | varchar (nullable) | Entity type (product, blog, category) |
prompt | text (nullable) | AI prompt used for generation |
generated_text | text | AI-generated text output |
entry_date | date (nullable) | Generation date |
entry_datetime | datetime (nullable) | Generation timestamp |
lang | varchar | Language code of generated content |
ai_position
| Column | Type | Description |
|---|---|---|
id | int (PK) | Auto-increment primary key |
slug | varchar | Unique slug identifier for the position |
recommendation_type | varchar | AI algorithm type (similar, complementary, trending, etc.) |
page | varchar | Storefront page (product, cart, home, category) |
min_items | int | Minimum items needed to display the widget |
request_limit | int | Maximum items to request from the AI engine |
active | tinyint | Whether the position is enabled (1=yes, 0=no) |
ai_position_mui
| Column | Type | Description |
|---|---|---|
position_id | int (FK) | Position ID |
title | varchar | Localized widget title (e.g., "You may also like") |
lang | varchar | Language code |
Configuration
Registry Keys (OpenAI Provider)
| Group | Key | Description |
|---|---|---|
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | IS_ENABLED | Feature toggle for OpenAI |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | API_KEY | OpenAI API key |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | COMPLETIONS_API_URL | API endpoint URL |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | TIMEOUT | Request timeout (seconds) |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | MODEL | Model name (e.g., gpt-4) |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | MAX_TOKENS | Maximum tokens per response |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | TEMPERATURE | Creativity parameter (0-2) |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | TOP_P | Nucleus sampling parameter |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | N | Number of completions |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | STREAM | Whether to use streaming |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | LOGPROBS | Log probability setting |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | ECHO | Echo prompt in response |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | STOP | Stop sequences |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | PRESENCE_PENALTY | Presence penalty (0-2) |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | FREQUENCY_PENALTY | Frequency penalty (0-2) |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | BEST_OF | Best-of sampling |
AI_CONTENT_GENERATION_PROVIDER_OPEN_AI | SUFFIX | Completion suffix |
Client Extension Points
- Override AdvContentGeneration: Add custom AI providers by extending the library and adding provider cases to
getProvider(). - Override Position RepositoryConfigurator: Add custom relations to positions.
- Custom prompts: Client repos can customize prompt templates in their admin controllers.
- Override WriteService: Add custom post-generation hooks (e.g., auto-apply generated content to entities).
Business Rules
- Provider abstraction: The
CompletionAIinterface allows plugging in different AI providers, though only OpenAI is currently implemented. - Audit logging: Every content generation is logged with the user, prompt, output, target field, entity type, and language.
- Position activation: Positions have an
activeflag -- disabled positions are ignored by storefront widgets. - Minimum items threshold: The
min_itemsfield prevents showing recommendation widgets when too few items match. - Request limit: The
request_limitcaps how many items the AI engine returns, controlling API costs and response size. - Language-aware: Content generation is language-specific, allowing generation in any configured language.
Related Flows
AD-02 Product Management Admin -- Product edit page uses content generation for descriptions
AD-12 Blog Admin -- Blog editor uses content generation for articles
AD-13 Settings -- AI provider configuration lives in settings
CF-02 Product Detail -- AI positions render recommendation widgets on product pages
CF-34 AI Recommendations -- Storefront AI recommendation widget rendering
SY-23 MUI Translation Pattern — ai_positions_mui companion table
Wiki Guide: Advisable AI Guide -- developer reference for the AI integration system