Core Modules
Unchained Engine is built around a modular architecture. Each core module handles a specific domain of e-commerce functionality.
Module Overview
| Module | Package | Description |
|---|---|---|
| Products | core-products | Product catalog management |
| Orders | core-orders | Order lifecycle and cart |
| Users | core-users | User accounts and authentication |
| Assortments | core-assortments | Category hierarchies |
| Filters | core-filters | Search and faceted filtering |
| Payment | core-payment | Payment providers |
| Delivery | core-delivery | Delivery providers |
| Warehousing | core-warehousing | Inventory management |
| Enrollments | core-enrollments | Subscriptions |
| Quotations | core-quotations | Quote requests |
| Bookmarks | core-bookmarks | User favorites |
| Files | core-files | Media management |
| Worker | core-worker | Background jobs |
| Events | core-events | Event history |
| Countries | core-countries | Country configuration |
| Currencies | core-currencies | Currency configuration |
| Languages | core-languages | Language configuration |
Configuration
Configure module options when starting the platform:
import { startPlatform } from '@unchainedshop/platform';
await startPlatform({
options: {
// Module-specific options
orders: {
ensureUserHasCart: true,
},
products: {
slugify: (title) => title.toLowerCase().replace(/\s+/g, '-'),
},
users: {
mergeUserCartsOnLogin: true,
},
},
});
Accessing Modules
Modules are available through the modules context:
// In GraphQL resolvers
const resolvers = {
Query: {
product: async (_, { productId }, { modules }) => {
return modules.products.findProduct({ productId });
},
},
};
// In custom code after platform start
const { modules } = await startPlatform({ ... });
const products = await modules.products.findProducts({
status: 'ACTIVE',
limit: 10,
});
Common Module Methods
Most modules follow a consistent pattern:
Query Methods
// Find single entity
modules.products.findProduct({ productId });
// Find multiple entities
modules.products.findProducts({ status: 'ACTIVE', limit: 10 });
// Count entities
modules.products.count({ status: 'ACTIVE' });
// Check existence
modules.products.productExists({ productId });
Mutation Methods
// Create
const productId = await modules.products.create({ type: 'SIMPLE' });
// Update
await modules.products.update(productId, { status: 'ACTIVE' });
// Delete (usually soft delete)
await modules.products.delete(productId);
Events
Modules emit events for important operations. Subscribe to events for custom logic:
import { emit, registerEvents } from '@unchainedshop/events';
// Register custom event handlers
registerEvents(['CUSTOM_EVENT']);
// Subscribe to events
events.on('PRODUCT_CREATE', async ({ payload }) => {
console.log('Product created:', payload.productId);
});
Common event patterns:
{MODULE}_CREATE- Entity created{MODULE}_UPDATE- Entity updated{MODULE}_REMOVE- Entity deleted
Related
- Architecture - System architecture overview
- Director/Adapter Pattern - Plugin system
- Extending GraphQL - Custom API extensions