feat: implement three-tier module classification and framework layer

Module Classification:
- Core (4): core, tenancy, cms, customers - always enabled
- Optional (7): payments, billing, inventory, orders, marketplace, analytics, messaging
- Internal (2): dev-tools, monitoring - admin-only

Key Changes:
- Rename platform-admin module to tenancy
- Promote CMS and Customers to core modules
- Create new payments module (gateway abstractions)
- Add billing→payments and orders→payments dependencies
- Mark dev-tools and monitoring as internal modules

New Infrastructure:
- app/modules/events.py: Module event bus (ENABLED, DISABLED, STARTUP, SHUTDOWN)
- app/modules/migrations.py: Module-specific migration discovery
- app/core/observability.py: Health checks, Prometheus metrics, Sentry integration

Enhanced ModuleDefinition:
- version, is_internal, permissions
- config_schema, default_config
- migrations_path
- Lifecycle hooks: on_enable, on_disable, on_startup, health_check

New Registry Functions:
- get_optional_module_codes(), get_internal_module_codes()
- is_core_module(), is_internal_module()
- get_modules_by_tier(), get_module_tier()

Migrations:
- zc*: Rename platform-admin to tenancy
- zd*: Ensure CMS and Customers enabled for all platforms

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-27 22:02:39 +01:00
parent 9a828999fe
commit 1a52611438
26 changed files with 3084 additions and 67 deletions

View File

@@ -4,6 +4,16 @@ Modular Platform Architecture.
This package provides a module system for enabling/disabling feature bundles per platform.
Three-Tier Classification:
1. CORE MODULES (4) - Always enabled, cannot be disabled
- core, tenancy, cms, customers
2. OPTIONAL MODULES (7) - Can be enabled/disabled per platform
- payments, billing, inventory, orders, marketplace, analytics, messaging
3. INTERNAL MODULES (2) - Admin-only tools, not customer-facing
- dev-tools, monitoring
Module Hierarchy:
Global (SaaS Provider)
└── Platform (Business Product - OMS, Loyalty, etc.)
@@ -11,7 +21,8 @@ Module Hierarchy:
├── Routes (API + Page routes)
├── Services (Business logic)
├── Menu Items (Sidebar entries)
── Templates (UI components)
── Templates (UI components)
└── Migrations (Module-specific)
Modules vs Features:
- Features: Granular capabilities (e.g., analytics_dashboard, letzshop_sync)
@@ -22,7 +33,8 @@ Modules vs Features:
Usage:
from app.modules import module_service
from app.modules.base import ModuleDefinition
from app.modules.registry import MODULES
from app.modules.registry import MODULES, CORE_MODULES, OPTIONAL_MODULES
from app.modules.events import module_event_bus, ModuleEvent
# Check if module is enabled for platform
if module_service.is_module_enabled(platform_id, "billing"):
@@ -33,15 +45,55 @@ Usage:
# Get all enabled modules for platform
modules = module_service.get_platform_modules(platform_id)
# Subscribe to module events
@module_event_bus.subscribe(ModuleEvent.ENABLED)
def on_enabled(data):
print(f"Module {data.module_code} enabled")
"""
from app.modules.base import ModuleDefinition
from app.modules.registry import MODULES
from app.modules.registry import (
MODULES,
CORE_MODULES,
OPTIONAL_MODULES,
INTERNAL_MODULES,
get_core_module_codes,
get_optional_module_codes,
get_internal_module_codes,
get_module_tier,
is_core_module,
is_internal_module,
)
from app.modules.service import ModuleService, module_service
from app.modules.events import (
ModuleEvent,
ModuleEventData,
ModuleEventBus,
module_event_bus,
)
__all__ = [
# Core types
"ModuleDefinition",
# Module dictionaries
"MODULES",
"CORE_MODULES",
"OPTIONAL_MODULES",
"INTERNAL_MODULES",
# Helper functions
"get_core_module_codes",
"get_optional_module_codes",
"get_internal_module_codes",
"get_module_tier",
"is_core_module",
"is_internal_module",
# Service
"ModuleService",
"module_service",
# Events
"ModuleEvent",
"ModuleEventData",
"ModuleEventBus",
"module_event_bus",
]