The Three-Layer Architecture
Layer 1: Block Editor
Package:@wordpress/block-editor
Responsibilities
- Generic block editing functionality
- Block tree manipulation
- Block insertion, selection, and movement
- Block toolbar and inspector controls
- Block canvas rendering
- InnerBlocks API for nested blocks
Key Characteristics
WordPress-Agnostic: This package has zero knowledge of WordPress. It operates purely on an array of block objects. Value-Based: Operates on a primitive value—an array of block objects. Makes no assumptions about:- How the value is persisted
- Where it comes from
- What happens after editing
@wordpress/core-data- WordPress REST API
- WordPress-specific concepts
Architectural Constraint
block-editoris a WordPress-agnostic package. NEVER addcore-datadependencies or direct REST API calls to it.
Use Cases
- Building block editors outside WordPress
- Custom save mechanisms
- Non-post-based block interfaces
- Comments editors
- Standalone block-based applications
Example
Layer 2: Editor
Package:@wordpress/editor
Responsibilities
- WordPress post editing functionality
- Post entity awareness
- Post title, excerpt, featured image
- Post settings (categories, tags, etc.)
- Content saving to WordPress
- Post type specific features
Key Characteristics
Post-Type Aware: Understands the concept of a WordPress post and its properties. Utilizes Block Editor: Builds on@wordpress/block-editor components, adding WordPress-specific context.
Flexible Context:
Does not assume:
- Where rendering happens (admin screen, custom page, etc.)
- Layout arrangement
- Specific screen implementation
Data Management
Uses Core Data: Relies on@wordpress/core-data for:
- Loading post entities
- Saving post changes
- Managing edit state
Use Cases
- Reusable block editor (editing
wp_blockpost type) - Custom post type editors
- Embedded post editors
- Any WordPress post editing context
Example
Layer 3: Edit Post / Edit Site
Packages:@wordpress/edit-post, @wordpress/edit-site
Responsibilities
- Full screen implementation
- Layout and UI arrangement
- Sidebars (settings, block inspector)
- Header area (save button, tools)
- WordPress admin integration
- Screen-specific features
Key Characteristics
Screen Implementation: Complete implementation of specific WordPress admin screens:edit-post- Post editing screenedit-site- Site Editor screen
- Component arrangement
- Sidebar positioning
- Header toolbar
- Canvas display
- Panel management
- WordPress admin dashboard
- Admin UI patterns
- Screen-specific requirements
Parallel Implementations
Multiple packages can exist at this layer:@wordpress/edit-post- Post editor screen@wordpress/edit-site- Site editor screen@wordpress/edit-widgets- Widgets editor screen- Custom implementations for plugins
Use Cases
- Standard WordPress post editor
- Site editor for full site editing
- Widgets editor
- Custom admin screens for plugins
Dependency Rules
Strict Layer Enforcement
Rule: Lower layers MUST NOT depend on higher ones.Why This Matters
Reusability: Lower layers can be used independently without pulling in unnecessary dependencies. Maintainability: Clear boundaries make it easier to understand and modify code. Flexibility: Different higher-layer implementations can use the same lower layers.Data Flow Through Layers
Layer 1 (Block Editor)
Layer 2 (Editor)
Layer 3 (Edit Post/Site)
Common Patterns
Creating a Custom Editor
For WordPress Posts: Use Layer 2 (@wordpress/editor) + Layer 1 (@wordpress/block-editor)
For Non-WordPress Use:
Use Layer 1 (@wordpress/block-editor) only
For Full Admin Screen:
Use all three layers or create a custom Layer 3 implementation
Extending the Editor
Adding Block Features: Work at Layer 1 (block-editor) Adding Post Features: Work at Layer 2 (editor) Adding Screen Features: Work at Layer 3 (edit-post/edit-site)Best Practices
Choosing the Right Layer
- Need WordPress post awareness? Use Layer 2+
- Need admin screen integration? Use Layer 3
- Building generic block interface? Use Layer 1 only
Avoiding Layer Violations
Don’t:- Add WordPress-specific code to
block-editor - Import from higher layers in lower layers
- Assume WordPress context in Layer 1
- Keep Layer 1 generic and reusable
- Use Layer 2 for WordPress post integration
- Implement screen-specific UI in Layer 3