Architecture Overview
Deep dive into Magento's largest module: EAV implementation, 148 service contracts, 63 database tables, 6 indexers, and the foundation of all product/category functionality.
Deep dive into Magento's largest module: EAV implementation, 148 service contracts, 63 database tables, 6 indexers, and the foundation of all product/category functionality.
Magento_Catalog is the largest and most complex module in Magento 2. It serves as the foundation for all product and category management, implementing the Entity-Attribute-Value (EAV) pattern for flexible attribute storage.
Critical Insight: Understanding the EAV architecture is essential before working with any catalog-related functionality. Misunderstanding it leads to N+1 queries, performance issues, and incorrect data retrieval.
Entity-Attribute-Value (EAV) is Magento's flexible data storage pattern that allows unlimited custom attributes without schema changes. Products and Categories are EAV entities.
The main record (product/category) stored in catalog_product_entity
Definition of a field (name, type, scope) in eav_attribute
Actual data split by type: _varchar, _int, _decimal, _datetime, _text
catalog_product_entity -- Main entity table (entity_id, sku, type_id, attribute_set_id) catalog_product_entity_varchar -- String values (name, url_key, meta_title) catalog_product_entity_int -- Integer values (status, visibility, tax_class_id) catalog_product_entity_decimal -- Decimal values (price, weight, special_price) catalog_product_entity_datetime -- Date values (special_from_date, news_from_date) catalog_product_entity_text -- Long text (description, short_description)
EAV requires multiple JOINs to retrieve a complete entity. This is why Magento has Flat Tables and Indexers to denormalize data for read-heavy operations. Always use the Flat catalog for frontend queries when possible.
Magento_Catalog exposes 148 service contract interfaces: 36 top-level repository/management interfaces and 35 Data interfaces (DTOs). These form the stable API layer.
ProductRepositoryInterface
CRUD operations for products
CategoryRepositoryInterface
CRUD operations for categories
ProductAttributeRepositoryInterface
Manage product attributes
CategoryAttributeRepositoryInterface
Manage category attributes
AttributeSetRepositoryInterface
Manage attribute sets
ProductInterface
Product data transfer object
CategoryInterface
Category data transfer object
ProductAttributeInterface
Attribute metadata DTO
ProductLinkInterface
Related/cross-sell/upsell links
ProductCustomOptionInterface
Custom options DTO
Magento_Catalog defines 63 database tables covering EAV storage, flat tables, indexer data, gallery, links, and more.
catalog_product_entity.entity_id → catalog_product_entity_*.entity_id (EAV values) catalog_product_entity.entity_id → catalog_category_product.product_id (category assignment) catalog_category_entity.entity_id → catalog_category_product.category_id (category assignment) catalog_product_entity.entity_id → catalog_product_link.product_id (related/upsell/crosssell)
Magento_Catalog defines the base product types. Additional types are added by other modules (Bundle, Configurable, Grouped, Downloadable).
Categories use a nested set model with path-based hierarchy. Each store has a root category, and all navigation categories are descendants.
Root Category (ID: 1, path: "1", level: 0)
└── Default Category (ID: 2, path: "1/2", level: 1)
├── Men (ID: 11, path: "1/2/11", level: 2)
│ ├── Tops (ID: 12, path: "1/2/11/12")
│ └── Bottoms (ID: 13, path: "1/2/11/13")
└── Women (ID: 14, path: "1/2/14", level: 2)
└── Dresses (ID: 15, path: "1/2/14/15")
Magento_Catalog provides 6 core indexers that denormalize EAV data for performance and maintain relationship indexes.
Reorganize EAV product structure to flat structure for fast frontend queries.
Performance CriticalReorganize EAV category structure to flat structure.
Performance CriticalIndexed category/products association for navigation.
Shared IndexIndexed product/categories association (reverse lookup).
Shared IndexIndex product prices including tier prices and special prices.
Price CalculationIndex product EAV attributes for layered navigation.
Layered NavMagento_Catalog has strict sequence dependencies that determine load order.
EAV framework for attribute storage
CMS block widgets in categories
Indexer framework for flat tables
Customer group pricing