feat: complete modular platform architecture (Phases 1-5)

Phase 1 - Vendor Router Integration:
- Wire up vendor module routers in app/api/v1/vendor/__init__.py
- Use lazy imports via __getattr__ to avoid circular dependencies

Phase 2 - Extract Remaining Modules:
- Create 6 new module directories: customers, cms, analytics, messaging,
  dev_tools, monitoring
- Each module has definition.py and route wrappers
- Update registry to import from extracted modules

Phase 3 - Database Table Migration:
- Add PlatformModule junction table for auditable module tracking
- Add migration zc2m3n4o5p6q7_add_platform_modules_table.py
- Add modules relationship to Platform model
- Update ModuleService with JSON-to-junction-table migration

Phase 4 - Module-Specific Configuration UI:
- Add /api/v1/admin/module-config/* endpoints
- Add module-config.html template and JS

Phase 5 - Integration Tests:
- Add tests/fixtures/module_fixtures.py
- Add tests/integration/api/v1/admin/test_modules.py
- Add tests/integration/api/v1/modules/test_module_access.py

Architecture fixes:
- Fix JS-003 errors: use ...data() directly in Alpine components
- Fix JS-005 warnings: add init() guards to prevent duplicate init
- Fix API-001 errors: add MenuActionResponse Pydantic model
- Add FE-008 noqa for dynamic number input in template

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-26 18:19:00 +01:00
parent f29f1113cd
commit c419090531
55 changed files with 4059 additions and 206 deletions

View File

@@ -0,0 +1,22 @@
# app/modules/messaging/__init__.py
"""
Messaging Module - Internal messaging and notifications.
This module provides:
- Internal messages between users
- Customer communication
- Notification center
- Email notifications
Routes:
- Admin: /api/v1/admin/messages/*, /api/v1/admin/notifications/*
- Vendor: /api/v1/vendor/messages/*, /api/v1/vendor/notifications/*
Menu Items:
- Admin: messages, notifications
- Vendor: messages, notifications
"""
from app.modules.messaging.definition import messaging_module
__all__ = ["messaging_module"]

View File

@@ -0,0 +1,77 @@
# app/modules/messaging/definition.py
"""
Messaging module definition.
Defines the messaging module including its features, menu items,
and route configurations.
"""
from app.modules.base import ModuleDefinition
from models.database.admin_menu_config import FrontendType
def _get_admin_router():
"""Lazy import of admin router to avoid circular imports."""
from app.modules.messaging.routes.admin import admin_router
return admin_router
def _get_admin_notifications_router():
"""Lazy import of admin notifications router to avoid circular imports."""
from app.modules.messaging.routes.admin import admin_notifications_router
return admin_notifications_router
def _get_vendor_router():
"""Lazy import of vendor router to avoid circular imports."""
from app.modules.messaging.routes.vendor import vendor_router
return vendor_router
def _get_vendor_notifications_router():
"""Lazy import of vendor notifications router to avoid circular imports."""
from app.modules.messaging.routes.vendor import vendor_notifications_router
return vendor_notifications_router
# Messaging module definition
messaging_module = ModuleDefinition(
code="messaging",
name="Messaging & Notifications",
description="Internal messages, customer communication, and notifications.",
features=[
"customer_messaging", # Customer communication
"internal_messages", # Internal team messages
"notification_center", # Notification management
],
menu_items={
FrontendType.ADMIN: [
"messages", # Admin messages
"notifications", # Admin notifications
],
FrontendType.VENDOR: [
"messages", # Vendor messages
"notifications", # Vendor notifications
],
},
is_core=False,
)
def get_messaging_module_with_routers() -> ModuleDefinition:
"""
Get messaging module with routers attached.
This function attaches the routers lazily to avoid circular imports
during module initialization.
"""
messaging_module.admin_router = _get_admin_router()
messaging_module.vendor_router = _get_vendor_router()
return messaging_module
__all__ = ["messaging_module", "get_messaging_module_with_routers"]

View File

@@ -0,0 +1,34 @@
# app/modules/messaging/routes/__init__.py
"""
Messaging module route registration.
This module provides functions to register messaging routes
with module-based access control.
NOTE: Routers are NOT auto-imported to avoid circular dependencies.
Import directly from admin.py or vendor.py as needed:
from app.modules.messaging.routes.admin import admin_router, admin_notifications_router
from app.modules.messaging.routes.vendor import vendor_router, vendor_notifications_router
"""
# Routers are imported on-demand to avoid circular dependencies
# Do NOT add auto-imports here
__all__ = ["admin_router", "admin_notifications_router", "vendor_router", "vendor_notifications_router"]
def __getattr__(name: str):
"""Lazy import routers to avoid circular dependencies."""
if name == "admin_router":
from app.modules.messaging.routes.admin import admin_router
return admin_router
elif name == "admin_notifications_router":
from app.modules.messaging.routes.admin import admin_notifications_router
return admin_notifications_router
elif name == "vendor_router":
from app.modules.messaging.routes.vendor import vendor_router
return vendor_router
elif name == "vendor_notifications_router":
from app.modules.messaging.routes.vendor import vendor_notifications_router
return vendor_notifications_router
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

View File

@@ -0,0 +1,39 @@
# app/modules/messaging/routes/admin.py
"""
Messaging module admin routes.
This module wraps the existing admin messages and notifications routes
and adds module-based access control. Routes are re-exported from the
original location with the module access dependency.
Includes:
- /messages/* - Message management
- /notifications/* - Notification management
"""
from fastapi import APIRouter, Depends
from app.api.deps import require_module_access
# Import original routers (direct import to avoid circular dependency)
from app.api.v1.admin.messages import router as messages_original_router
from app.api.v1.admin.notifications import router as notifications_original_router
# Create module-aware router for messages
admin_router = APIRouter(
prefix="/messages",
dependencies=[Depends(require_module_access("messaging"))],
)
# Re-export all routes from the original messages module
for route in messages_original_router.routes:
admin_router.routes.append(route)
# Create separate router for notifications
admin_notifications_router = APIRouter(
prefix="/notifications",
dependencies=[Depends(require_module_access("messaging"))],
)
for route in notifications_original_router.routes:
admin_notifications_router.routes.append(route)

View File

@@ -0,0 +1,39 @@
# app/modules/messaging/routes/vendor.py
"""
Messaging module vendor routes.
This module wraps the existing vendor messages and notifications routes
and adds module-based access control. Routes are re-exported from the
original location with the module access dependency.
Includes:
- /messages/* - Message management
- /notifications/* - Notification management
"""
from fastapi import APIRouter, Depends
from app.api.deps import require_module_access
# Import original routers (direct import to avoid circular dependency)
from app.api.v1.vendor.messages import router as messages_original_router
from app.api.v1.vendor.notifications import router as notifications_original_router
# Create module-aware router for messages
vendor_router = APIRouter(
prefix="/messages",
dependencies=[Depends(require_module_access("messaging"))],
)
# Re-export all routes from the original messages module
for route in messages_original_router.routes:
vendor_router.routes.append(route)
# Create separate router for notifications
vendor_notifications_router = APIRouter(
prefix="/notifications",
dependencies=[Depends(require_module_access("messaging"))],
)
for route in notifications_original_router.routes:
vendor_notifications_router.routes.append(route)