feat: complete analytics module self-containment

Migrate analytics module to fully self-contained structure:

- routes/api/vendor.py - API endpoints
- routes/pages/vendor.py - Page routes with full implementation
- services/stats_service.py - Business logic (moved from app/services)
- services/usage_service.py - Usage tracking (moved from app/services)
- schemas/stats.py - Pydantic schemas (moved from models/schema)
- models/__init__.py - Model exports
- templates/analytics/vendor/ - Templates (moved from app/templates)
- static/vendor/js/ - JavaScript (moved from static/vendor)
- locales/ - Translations (en, de, fr, lu)
- exceptions.py - Module exceptions

Removed legacy files:
- app/modules/analytics/routes/vendor.py (replaced by routes/pages/)
- static/admin/js/analytics.js (unused)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-28 22:21:21 +01:00
parent 2466dfd7ed
commit bd2c99a775
22 changed files with 1870 additions and 50 deletions

View File

@@ -3,18 +3,25 @@
Analytics module definition.
Defines the analytics module including its features, menu items,
and route configurations.
route configurations, and self-contained module settings.
"""
from app.modules.base import ModuleDefinition
from models.database.admin_menu_config import FrontendType
def _get_vendor_router():
"""Lazy import of vendor router to avoid circular imports."""
from app.modules.analytics.routes.vendor import vendor_router
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 vendor_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
@@ -22,11 +29,13 @@ 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: [
@@ -37,6 +46,18 @@ analytics_module = ModuleDefinition(
],
},
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",
)
@@ -46,8 +67,13 @@ def get_analytics_module_with_routers() -> ModuleDefinition:
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_router = _get_vendor_router()
analytics_module.vendor_api_router = _get_vendor_api_router()
analytics_module.vendor_page_router = _get_vendor_page_router()
return analytics_module