This commit completes the migration to a fully module-driven architecture: ## Models Migration - Moved all domain models from models/database/ to their respective modules: - tenancy: User, Admin, Vendor, Company, Platform, VendorDomain, etc. - cms: MediaFile, VendorTheme - messaging: Email, VendorEmailSettings, VendorEmailTemplate - core: AdminMenuConfig - models/database/ now only contains Base and TimestampMixin (infrastructure) ## Schemas Migration - Moved all domain schemas from models/schema/ to their respective modules: - tenancy: company, vendor, admin, team, vendor_domain - cms: media, image, vendor_theme - messaging: email - models/schema/ now only contains base.py and auth.py (infrastructure) ## Routes Migration - Moved admin routes from app/api/v1/admin/ to modules: - menu_config.py -> core module - modules.py -> tenancy module - module_config.py -> tenancy module - app/api/v1/admin/ now only aggregates auto-discovered module routes ## Menu System - Implemented module-driven menu system with MenuDiscoveryService - Extended FrontendType enum: PLATFORM, ADMIN, VENDOR, STOREFRONT - Added MenuItemDefinition and MenuSectionDefinition dataclasses - Each module now defines its own menu items in definition.py - MenuService integrates with MenuDiscoveryService for template rendering ## Documentation - Updated docs/architecture/models-structure.md - Updated docs/architecture/menu-management.md - Updated architecture validation rules for new exceptions ## Architecture Validation - Updated MOD-019 rule to allow base.py in models/schema/ - Created core module exceptions.py and schemas/ directory - All validation errors resolved (only warnings remain) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
102 lines
3.3 KiB
Python
102 lines
3.3 KiB
Python
# app/modules/analytics/definition.py
|
|
"""
|
|
Analytics module definition.
|
|
|
|
Defines the analytics module including its features, menu items,
|
|
route configurations, and self-contained module settings.
|
|
"""
|
|
|
|
from app.modules.base import MenuItemDefinition, MenuSectionDefinition, ModuleDefinition
|
|
from app.modules.enums import FrontendType
|
|
|
|
|
|
def _get_vendor_api_router():
|
|
"""Lazy import of vendor API router to avoid circular imports."""
|
|
from app.modules.analytics.routes.api.vendor import router
|
|
|
|
return router
|
|
|
|
|
|
def _get_vendor_page_router():
|
|
"""Lazy import of vendor page router to avoid circular imports."""
|
|
from app.modules.analytics.routes.pages.vendor import router
|
|
|
|
return router
|
|
|
|
|
|
# Analytics module definition
|
|
analytics_module = ModuleDefinition(
|
|
code="analytics",
|
|
name="Analytics & Reporting",
|
|
description="Dashboard analytics, custom reports, and data exports.",
|
|
version="1.0.0",
|
|
features=[
|
|
"basic_reports", # Basic reporting
|
|
"analytics_dashboard", # Analytics dashboard
|
|
"custom_reports", # Custom report builder
|
|
"export_reports", # Export to CSV/Excel
|
|
"usage_metrics", # Usage and performance metrics
|
|
],
|
|
menu_items={
|
|
FrontendType.ADMIN: [
|
|
# Analytics appears in dashboard for admin
|
|
],
|
|
FrontendType.VENDOR: [
|
|
"analytics", # Vendor analytics page
|
|
],
|
|
},
|
|
# New module-driven menu definitions
|
|
menus={
|
|
FrontendType.VENDOR: [
|
|
MenuSectionDefinition(
|
|
id="main",
|
|
label_key=None,
|
|
icon=None,
|
|
order=0,
|
|
is_collapsible=False,
|
|
items=[
|
|
MenuItemDefinition(
|
|
id="analytics",
|
|
label_key="analytics.menu.analytics",
|
|
icon="chart-bar",
|
|
route="/vendor/{vendor_code}/analytics",
|
|
order=20,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
},
|
|
is_core=False,
|
|
# =========================================================================
|
|
# Self-Contained Module Configuration
|
|
# =========================================================================
|
|
is_self_contained=True,
|
|
services_path="app.modules.analytics.services",
|
|
models_path="app.modules.analytics.models",
|
|
schemas_path="app.modules.analytics.schemas",
|
|
exceptions_path="app.modules.analytics.exceptions",
|
|
# Module templates (namespaced as analytics/admin/*.html and analytics/vendor/*.html)
|
|
templates_path="templates",
|
|
# Module-specific translations (accessible via analytics.* keys)
|
|
locales_path="locales",
|
|
)
|
|
|
|
|
|
def get_analytics_module_with_routers() -> ModuleDefinition:
|
|
"""
|
|
Get analytics module with routers attached.
|
|
|
|
This function attaches the routers lazily to avoid circular imports
|
|
during module initialization.
|
|
|
|
Routers:
|
|
- vendor_api_router: API endpoints for vendor analytics
|
|
- vendor_page_router: Page routes for vendor analytics dashboard
|
|
"""
|
|
analytics_module.vendor_api_router = _get_vendor_api_router()
|
|
analytics_module.vendor_page_router = _get_vendor_page_router()
|
|
return analytics_module
|
|
|
|
|
|
__all__ = ["analytics_module", "get_analytics_module_with_routers"]
|