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:
22
app/modules/cms/__init__.py
Normal file
22
app/modules/cms/__init__.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# app/modules/cms/__init__.py
|
||||
"""
|
||||
CMS Module - Content Management System.
|
||||
|
||||
This module provides:
|
||||
- Content pages management
|
||||
- Media library
|
||||
- Vendor themes
|
||||
- SEO tools
|
||||
|
||||
Routes:
|
||||
- Admin: /api/v1/admin/content-pages/*
|
||||
- Vendor: /api/v1/vendor/content-pages/*, /api/v1/vendor/media/*
|
||||
|
||||
Menu Items:
|
||||
- Admin: content-pages, vendor-themes
|
||||
- Vendor: content-pages, media
|
||||
"""
|
||||
|
||||
from app.modules.cms.definition import cms_module
|
||||
|
||||
__all__ = ["cms_module"]
|
||||
66
app/modules/cms/definition.py
Normal file
66
app/modules/cms/definition.py
Normal file
@@ -0,0 +1,66 @@
|
||||
# app/modules/cms/definition.py
|
||||
"""
|
||||
CMS module definition.
|
||||
|
||||
Defines the CMS 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.cms.routes.admin import admin_router
|
||||
|
||||
return admin_router
|
||||
|
||||
|
||||
def _get_vendor_router():
|
||||
"""Lazy import of vendor router to avoid circular imports."""
|
||||
from app.modules.cms.routes.vendor import vendor_router
|
||||
|
||||
return vendor_router
|
||||
|
||||
|
||||
# CMS module definition
|
||||
cms_module = ModuleDefinition(
|
||||
code="cms",
|
||||
name="Content Management",
|
||||
description="Content pages, media library, and vendor themes.",
|
||||
features=[
|
||||
"cms_basic", # Basic page editing
|
||||
"cms_custom_pages", # Custom page creation
|
||||
"cms_unlimited_pages", # No page limit
|
||||
"cms_templates", # Page templates
|
||||
"cms_seo", # SEO tools
|
||||
"media_library", # Media file management
|
||||
],
|
||||
menu_items={
|
||||
FrontendType.ADMIN: [
|
||||
"content-pages", # Platform content pages
|
||||
"vendor-themes", # Theme management
|
||||
],
|
||||
FrontendType.VENDOR: [
|
||||
"content-pages", # Vendor content pages
|
||||
"media", # Media library
|
||||
],
|
||||
},
|
||||
is_core=False,
|
||||
)
|
||||
|
||||
|
||||
def get_cms_module_with_routers() -> ModuleDefinition:
|
||||
"""
|
||||
Get CMS module with routers attached.
|
||||
|
||||
This function attaches the routers lazily to avoid circular imports
|
||||
during module initialization.
|
||||
"""
|
||||
cms_module.admin_router = _get_admin_router()
|
||||
cms_module.vendor_router = _get_vendor_router()
|
||||
return cms_module
|
||||
|
||||
|
||||
__all__ = ["cms_module", "get_cms_module_with_routers"]
|
||||
31
app/modules/cms/routes/__init__.py
Normal file
31
app/modules/cms/routes/__init__.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# app/modules/cms/routes/__init__.py
|
||||
"""
|
||||
CMS module route registration.
|
||||
|
||||
This module provides functions to register CMS 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.cms.routes.admin import admin_router
|
||||
from app.modules.cms.routes.vendor import vendor_router, vendor_media_router
|
||||
"""
|
||||
|
||||
# Routers are imported on-demand to avoid circular dependencies
|
||||
# Do NOT add auto-imports here
|
||||
|
||||
__all__ = ["admin_router", "vendor_router", "vendor_media_router"]
|
||||
|
||||
|
||||
def __getattr__(name: str):
|
||||
"""Lazy import routers to avoid circular dependencies."""
|
||||
if name == "admin_router":
|
||||
from app.modules.cms.routes.admin import admin_router
|
||||
return admin_router
|
||||
elif name == "vendor_router":
|
||||
from app.modules.cms.routes.vendor import vendor_router
|
||||
return vendor_router
|
||||
elif name == "vendor_media_router":
|
||||
from app.modules.cms.routes.vendor import vendor_media_router
|
||||
return vendor_media_router
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
25
app/modules/cms/routes/admin.py
Normal file
25
app/modules/cms/routes/admin.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# app/modules/cms/routes/admin.py
|
||||
"""
|
||||
CMS module admin routes.
|
||||
|
||||
This module wraps the existing admin content pages routes and adds
|
||||
module-based access control. Routes are re-exported from the
|
||||
original location with the module access dependency.
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from app.api.deps import require_module_access
|
||||
|
||||
# Import original router (direct import to avoid circular dependency)
|
||||
from app.api.v1.admin.content_pages import router as original_router
|
||||
|
||||
# Create module-aware router
|
||||
admin_router = APIRouter(
|
||||
prefix="/content-pages",
|
||||
dependencies=[Depends(require_module_access("cms"))],
|
||||
)
|
||||
|
||||
# Re-export all routes from the original module with module access control
|
||||
for route in original_router.routes:
|
||||
admin_router.routes.append(route)
|
||||
39
app/modules/cms/routes/vendor.py
Normal file
39
app/modules/cms/routes/vendor.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# app/modules/cms/routes/vendor.py
|
||||
"""
|
||||
CMS module vendor routes.
|
||||
|
||||
This module wraps the existing vendor content pages and media routes
|
||||
and adds module-based access control. Routes are re-exported from the
|
||||
original location with the module access dependency.
|
||||
|
||||
Includes:
|
||||
- /content-pages/* - Content page management
|
||||
- /media/* - Media library
|
||||
"""
|
||||
|
||||
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.content_pages import router as content_original_router
|
||||
from app.api.v1.vendor.media import router as media_original_router
|
||||
|
||||
# Create module-aware router for content pages
|
||||
vendor_router = APIRouter(
|
||||
prefix="/content-pages",
|
||||
dependencies=[Depends(require_module_access("cms"))],
|
||||
)
|
||||
|
||||
# Re-export all routes from the original content pages module
|
||||
for route in content_original_router.routes:
|
||||
vendor_router.routes.append(route)
|
||||
|
||||
# Create separate router for media library
|
||||
vendor_media_router = APIRouter(
|
||||
prefix="/media",
|
||||
dependencies=[Depends(require_module_access("cms"))],
|
||||
)
|
||||
|
||||
for route in media_original_router.routes:
|
||||
vendor_media_router.routes.append(route)
|
||||
Reference in New Issue
Block a user