Project Context
A client needed to connect their Magento catalog with AliExpress to expand sales channels. Magento serves as their B2C/B2B platform, while AliExpress acts as a marketplace where they operate as a Merchant/Seller. The goal was to synchronize products from each Magento store to AliExpress, enabling merchants to manage their catalog in Magento and automatically export it to AliExpress.
Technical Challenge
On paper it seemed simple, but real-world challenges emerged. AliExpress provides a complex API, so they created an SDK as middleware to abstract API communication. However, this SDK presented critical problems:
- • No clear use case definitions: The SDK lacked clear business boundaries and use cases as entry points, forcing developers to struggle with low-level API interactions
- • No proper packaging: The SDK was a public file manually downloaded and included in source code—no autoloader, no Composer package, no PSR standards. This required manual integration work in our Magento module
Architectural Solution
We decided to build our own SDK and use it as an external library in the Magento module. The architecture consisted of three layers:
- • Custom SDK library: Abstracts all AliExpress API communication using the Mediator pattern. Each use case is represented by an object that represents the intention (Use Case) and receives a DTO (data for POST/GET to AliExpress API). This allows calling use cases as if they were REST APIs—remember, everything is an API
- • Magento module (Use Case layer): Defines use cases to democratize AliExpress API usage at the application level. This module uses indirection (through the SDK) to interact with AliExpress API. It has minimal Magento dependencies and could have been a plain PHP library—it only defines use cases with the SDK, making it an API to the machinery
- • Magento module (Infrastructure layer): Interacts with the backoffice, closer to infrastructure. Defines Magento configurations for merchant credentials, backoffice pages for viewing and exporting products to AliExpress, importing orders from AliExpress to Magento, and a Cron job for periodic product and order synchronization
Results
This architecture reduces friction with the framework by creating independent responsibility layers that don't depend on the framework. The business logic is completely separated from Magento infrastructure, and use cases are clearly defined, making the system maintainable and testable.
Technologies
- • PHP & Magento 2
- • Domain-Driven Design
- • Mediator Pattern
- • Hexagonal Architecture
- • Use Case Pattern
- • PSR Standards
Key Achievements
- • Clear use case definitions as API entry points
- • Framework-independent business logic (could be any PHP library)
- • Proper SDK packaging following PSR standards
- • Separation of concerns: Use Case layer vs Infrastructure layer