Why Modularity?
Using a modular architecture benefits all actors involved:For Core Contributors
- Each package is an independent unit with a well-defined public API
- Easier to reason about the codebase by focusing on one package at a time
- Clear understanding of how changes impact other parts relying on the package
For End Users
- Selective script loading on different WordPress Admin pages
- Contained bundle sizes
- Only load what’s needed (e.g., components without block-editor on settings pages)
For Third-Party Developers
- Reuse packages inside and outside WordPress context
- Use as npm or WordPress script dependencies
- Build custom implementations with editor components
Types of Packages
Almost everything in Gutenberg is built into a package. Packages fall into two categories:Production Packages
These packages ship in WordPress as JavaScript scripts—the actual production code that runs in browsers. Examples:@wordpress/components- Reusable React components for building interfaces@wordpress/api-fetch- WordPress REST API utilities@wordpress/data- State management system
Using Production Packages
Outside WordPress (as npm packages):@wordpress/scripts@wordpress/dependency-extraction-webpack-plugin
Packages with Stylesheets
Some packages require stylesheets: As npm dependency:- Stylesheets available in
build-stylefolder - Load the style file in your application
- Enqueue stylesheets or add to stylesheet dependencies
- Stylesheet handles match script handles
Packages with Data Stores
Some packages define data stores for state management. Store names follow the formatcore/package-name.
Example:
@wordpress/block-editorpackage →core/block-editorstore
Development Packages
Packages used in development to help with daily tasks:- Building JavaScript applications
- Developing WordPress plugins and themes
- Linting, testing, and shipping code
@wordpress/scripts- Build and development tools@wordpress/env- Local WordPress environment@wordpress/e2e-test-utils- End-to-end testing utilities
Editor Package Architecture
The post editor is constructed as a layered abstraction of three separate packages. Understanding the distinction is crucial for contributors.The Three Layers
1. @wordpress/block-editor
Purpose: Generic, WordPress-agnostic block editor
Characteristics:
- Provides components for implementing a block editor
- Operates on primitive value of an array of block objects
- Makes no assumptions about how value is saved
- Has no awareness or requirement of a WordPress site
block-editoris WordPress-agnostic. NEVER addcore-datadependencies or direct REST API calls to it.
2. @wordpress/editor
Purpose: WordPress post-type-aware editing
Characteristics:
- Enhanced version of block editor for WordPress posts
- Utilizes components from
@wordpress/block-editor - Aware of WordPress post concept
- Associates block loading/saving with posts and their content
- Provides post-related components (post title input, etc.)
- Supports editing posts of any post type
- No assumptions about rendering location or layout
3. @wordpress/edit-post / @wordpress/edit-site
Purpose: Full screen implementations
Characteristics:
@wordpress/edit-post- Implementation of “Edit Post” screen@wordpress/edit-site- Implementation of Site Editor- Responsible for layout of components from lower layers
- Full awareness of WordPress admin dashboard presentation
Layering Rules
Architectural Decision:Package layering: Three editor layers —block-editor(generic, WP-agnostic) →editor(WordPress post-type-aware) →edit-post/edit-site(full screens). Lower layers MUST NOT depend on higher ones.
Use Cases for Different Layers
This structure enables various combinations:Using @wordpress/edit-site or @wordpress/edit-widgets
Similar implementations to @wordpress/edit-post for different editing contexts.
Using @wordpress/editor
Perfect for:
- Reusable Block editor (nested block editor for
wp_blockpost type) - Custom post type editors
- Any WordPress post editing context
Using @wordpress/block-editor
Ideal for:
- Non-WordPress block editor implementations
- Different save mechanisms
- Comments editor for posts
- Any block-based interface outside WordPress
Package Distribution
Packages are available both as:- npm packages - For any JavaScript application
- WordPress scripts - With
wp-*handles for WordPress context
Modularity: Packages are available both as npm packages and WordPress scripts (wp-* handles). Production packages must work in both contexts.