Overview
The Shopware Admin SDK uses an iframe-based architecture to enable secure communication between apps and the Shopware Administration. This architecture allows third-party applications to extend the admin interface while maintaining security and isolation.Iframe Communication Model
Apps run inside iframes embedded within the Shopware Administration. Communication between the app iframe and the parent admin window occurs through the browser’spostMessage API, providing a secure cross-origin messaging system.
Message Structure
All messages follow a consistent structure with three key properties:Message Passing System
Sending Messages
Thesend function handles all outgoing messages from apps to the admin:
- Generates a unique callback ID for matching responses (channel.ts:114)
- Serializes the message data, converting Entity, EntityCollection, and Criteria objects to JSON (channel.ts:127)
- Sends the message via
postMessageto the parent window (channel.ts:249) - Returns a Promise that resolves when a matching response is received (channel.ts:177-260)
- Includes a 7-second timeout to prevent hanging requests (channel.ts:174, 252-259)
Handling Messages
Thehandle function registers handlers for incoming messages:
- Listens for messages with matching
_type(channel.ts:286) - Deserializes message data (channel.ts:306)
- Executes the handler method (channel.ts:321-347)
- Serializes the response (channel.ts:357-385)
- Sends the response back to the source window (channel.ts:389-398)
Window Registration
Apps automatically register with the admin on initialization:Security Model
Origin Validation
All messages validate the origin to prevent unauthorized access:Privilege Validation
The SDK validates privileges before processing entity data:Serialization Security
The SDK uses a serialization layer to:- Transform Entity and EntityCollection objects to safe JSON (channel.ts:15-18)
- Validate data against app privileges
- Prevent direct access to internal Shopware data structures
Location-Based Loading
Apps specify their location via URL parameters:Communication Flow Diagram
Best Practices
1. Always Handle Errors
2. Clean Up Handlers
3. Use Appropriate Timeouts
The default timeout is 7 seconds (channel.ts:174). For long-running operations, consider alternative patterns.4. Validate Message Origins
Always verify the origin in handlers when working with sensitive data:Performance Considerations
- Messages are serialized/deserialized on each transmission
- Large Entity or EntityCollection objects may impact performance
- Use selectors to limit data transfer when subscribing to datasets
- The subscriber registry allows efficient targeted messaging (channel.ts:87-92)
Next Steps
- Learn about Context API for accessing Shopware context
- Explore Location Module for iframe positioning
- Understand Data Handling for working with entities