feat: implement DashboardWidgetProvider pattern for modular dashboard widgets

Add protocol-based widget system following the MetricsProvider pattern:

- Create DashboardWidgetProviderProtocol in contracts/widgets.py
- Add WidgetAggregatorService in core to discover and aggregate widgets
- Implement MarketplaceWidgetProvider for recent_imports widget
- Implement TenancyWidgetProvider for recent_vendors widget
- Update admin dashboard to use widget_aggregator
- Add widget_provider field to ModuleDefinition

Architecture documentation:
- Add widget-provider-pattern.md with implementation guide
- Add cross-module-import-rules.md enforcing core/optional separation
- Update module-system.md with widget_provider and import rules

This enables modules to provide rich dashboard widgets without core modules
importing from optional modules, maintaining true module independence.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-04 19:01:23 +01:00
parent a8fae0fbc7
commit 3e38db79aa
13 changed files with 1906 additions and 25 deletions

View File

@@ -22,6 +22,13 @@ def _get_metrics_provider():
return tenancy_metrics_provider
def _get_widget_provider():
"""Lazy import of widget provider to avoid circular imports."""
from app.modules.tenancy.services.tenancy_widgets import tenancy_widget_provider
return tenancy_widget_provider
tenancy_module = ModuleDefinition(
code="tenancy",
name="Tenancy Management",
@@ -161,6 +168,8 @@ tenancy_module = ModuleDefinition(
exceptions_path="app.modules.tenancy.exceptions",
# Metrics provider for dashboard statistics
metrics_provider=_get_metrics_provider,
# Widget provider for dashboard widgets
widget_provider=_get_widget_provider,
)
__all__ = ["tenancy_module"]