Package Layering
Gutenberg follows a strict three-layer architecture for editor packages:Layer Hierarchy
-
@wordpress/block-editor(Bottom Layer)- Generic, WordPress-agnostic block editor
- No WordPress-specific dependencies
- Can be used in any application
-
@wordpress/editor(Middle Layer)- WordPress post-type-aware functionality
- Depends on
@wordpress/block-editor - Handles WordPress entities (posts, pages)
-
@wordpress/edit-post/@wordpress/edit-site(Top Layer)- Complete editor screens
- Depends on
@wordpress/editorand@wordpress/block-editor - Full WordPress integration
Critical Rule
Lower layers MUST NOT depend on higher layers. This ensures:- Code reusability
- Clear separation of concerns
- WordPress-agnostic editor core
Block Data Model
Understand how blocks are represented and manipulated:In-Memory Structure
During editing, blocks exist as in-memory tree structures:Serialized Format
Blocks are saved as HTML with comment delimiters:Key Principle
Always work with the block tree via APIs, not the serialized HTML.Data Layer Architecture
Gutenberg uses@wordpress/data for state management, following a Redux-like pattern.
State Management Principles
Use data stores for all state:Critical Rules
Edit entities throughcore-data actions:
Styles System
Gutenberg’s styling follows a three-layer merge system:Style Layer Hierarchy
-
WordPress Defaults (Base)
- Core WordPress styles
- Block default styles
-
theme.json(Theme Layer)- Theme-defined styles and settings
- Global style variations
-
User Preferences (Top Layer)
- User customizations
- Site-specific overrides
Implementation Guidelines
Use Block Supports API:Modularity and Distribution
Gutenberg packages work in multiple contexts:Dual Distribution
Production packages are available as:-
npm packages:
@wordpress/components- Used by third-party developers
- Bundled into plugins and themes
-
WordPress scripts:
wp-components- Loaded via
wp_enqueue_script() - Available as global
wp.components
- Loaded via
Critical Requirement
Production packages must work in both contexts.WordPress-Agnostic Core
The@wordpress/block-editor package is designed to be WordPress-agnostic:
What This Means
No WordPress-specific dependencies:Development Tools Separation
The@wordpress/scripts package has special constraints:
Special Case: @wordpress/scripts
Purpose: Generic build tool for:
- Gutenberg plugin development
- WordPress Core contributions
- Third-party plugin development
@wordpress/scripts
Key Takeaways
When contributing to Gutenberg:- Respect package layering - Lower layers don’t depend on higher layers
- Use block APIs - Don’t manipulate serialized HTML directly
- Use data stores - Follow Redux patterns via
@wordpress/data - Use CSS custom properties - Don’t hardcode style values
- Keep
block-editoragnostic - Nocore-dataor WordPress-specific code - Make packages portable - Work in both npm and WordPress contexts
- Keep build tools generic -
@wordpress/scriptsserves multiple use cases
Further Reading
For detailed architecture documentation:Next Steps
- Review Common Pitfalls to avoid architectural mistakes
- Check Coding Guidelines for implementation patterns
- See Folder Structure to understand package organization