A highly modular, testable, and scalable architectural foundation for building production-grade Blender addons.
This project is not a finished tool, but a framework designed to solve the common "spaghetti code" problem in Blender development by enforcing a strict separation of concerns between the Blender API (bpy), business logic, and the user interface.
The codebase follows a layered, unidirectional dependency flow. This prevents the common pitfall of embedding heavy logic inside Blender operators.
Dependency Flow:
UI Components Service Layer Bridge Interface [bpy (Real) OR Mock (Testing)]
- UI Layer (
ui/): Purely responsible for visual representation. It containsPanels(layouts) andOperators(command triggers). Operators should do nothing more than call a method in the Service Layer. - Service Layer (
core/services.py): The "brain" of your extension. This is where your actual business logic lives. It interacts with Blender only through the Bridge. This layer is pure Python and can be unit-tested without Blender. - Bridge Layer (
core/bridge.py): An abstraction layer that uses the Composition Pattern. Instead of one giant class, it provides specialized sub-interfaces (e.g.,bridge.mesh,bridge.materials) to make the API discoverable and modular. - Shared Layer (
shared/): Common data models, math utilities, and logging wrappers used across all layers.
- Modular Bridge Pattern: Highly discoverable API via sub-interfaces (
objects,mesh,materials,scene). - Zero-Blender Testing: Includes a
MockBlenderBridgethat simulates Blender's behavior, allowing you to run your entire service logic in a standard Python environment (e.g., viapytest). - Service-Oriented Design: Encourages clean, reusable logic decoupled from the UI.
- UI Scaffolding: Pre-built templates for Sidebar Panels, Operators, and Addon Preferences.
- Lifecycle Orchestration: A centralized
registration.pythat handles the complex order of registering/unregistering Blender classes. - Persistent Configuration: Built-in support for
bpy.types.AddonPreferences.
As this is a scaffold, please be aware of the following:
- Scope: The current Bridge only implements a subset of
bpy. You must extend theBridgeInterfaceand itsRealimplementations as your tool grows. - Mock Depth: The
MockBlenderBridgeis a lightweight simulation. Complexbpyinteractions (like advanced geometry nodes or specific shader math) will require manual mocking in your tests. - Manual Implementation Required: This framework provides the pipes, but you still need to write the water (your specific tool logic).
The following enhancements are planned to evolve this scaffold into a complete development ecosystem:
- Advanced Error Reporting: A bridge-level mechanism to automatically catch Python exceptions and pipe them into Blender's UI header or a custom popup.
- Visual Async Feedback: Integration between the
Service Layerbackground tasks and theUI Layerto provide visual progress bars or status icons in the N-panel. - Automated Bridge Generation: A utility to help scaffold new Bridge sub-interfaces based on
bpydocumentation.
- Pre-flight Validation Suite: A standardized way to define and run "Scene Health Checks" before performing operations (e.g., "Are all scales applied?", "Are naming conventions met?").
- Asset Browser Sync: Built-in bridge methods to automatically register/manage assets in Blender's native Asset Browser.
- Metadata Persistence: A service to handle custom property persistence during complex export/import workflows.
- Define the API: If you need a new Blender capability, add an interface to
core/bridge.pyand implement it in bothRealBlenderBridgeandMockBlenderBridge. - Write the Logic: Create a new method in
core/services.pythat uses your new bridge method. - Create the UI:
- Add an
Operatorinui/operators.pyto call the service. - Add a
Panelentry inui/panels.pyto trigger the operator.
- Add an
- Register: Ensure your new classes are added to the
OPERATOR_CLASSESorPANEL_CLASSESlists in their respective files.
# Run tests in a standard python environment (no Blender needed)
pytest tests/