refactor: complete module-driven architecture migration
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>
This commit is contained in:
@@ -6,8 +6,8 @@ Defines the monitoring module including its features, menu items,
|
||||
route configurations, and self-contained module settings.
|
||||
"""
|
||||
|
||||
from app.modules.base import ModuleDefinition
|
||||
from models.database.admin_menu_config import FrontendType
|
||||
from app.modules.base import MenuItemDefinition, MenuSectionDefinition, ModuleDefinition
|
||||
from app.modules.enums import FrontendType
|
||||
|
||||
|
||||
def _get_admin_router():
|
||||
@@ -44,6 +44,71 @@ monitoring_module = ModuleDefinition(
|
||||
],
|
||||
FrontendType.VENDOR: [], # No vendor menu items
|
||||
},
|
||||
# New module-driven menu definitions
|
||||
menus={
|
||||
FrontendType.ADMIN: [
|
||||
MenuSectionDefinition(
|
||||
id="platformHealth",
|
||||
label_key="monitoring.menu.platform_health",
|
||||
icon="chart-bar",
|
||||
order=75,
|
||||
is_super_admin_only=True,
|
||||
items=[
|
||||
MenuItemDefinition(
|
||||
id="platform-health",
|
||||
label_key="monitoring.menu.capacity_monitor",
|
||||
icon="chart-bar",
|
||||
route="/admin/platform-health",
|
||||
order=10,
|
||||
),
|
||||
MenuItemDefinition(
|
||||
id="testing",
|
||||
label_key="monitoring.menu.testing_hub",
|
||||
icon="beaker",
|
||||
route="/admin/testing",
|
||||
order=20,
|
||||
),
|
||||
MenuItemDefinition(
|
||||
id="code-quality",
|
||||
label_key="monitoring.menu.code_quality",
|
||||
icon="shield-check",
|
||||
route="/admin/code-quality",
|
||||
order=30,
|
||||
),
|
||||
],
|
||||
),
|
||||
MenuSectionDefinition(
|
||||
id="monitoring",
|
||||
label_key="monitoring.menu.platform_monitoring",
|
||||
icon="collection",
|
||||
order=80,
|
||||
is_super_admin_only=True,
|
||||
items=[
|
||||
MenuItemDefinition(
|
||||
id="imports",
|
||||
label_key="monitoring.menu.import_jobs",
|
||||
icon="cube",
|
||||
route="/admin/imports",
|
||||
order=10,
|
||||
),
|
||||
MenuItemDefinition(
|
||||
id="background-tasks",
|
||||
label_key="monitoring.menu.background_tasks",
|
||||
icon="collection",
|
||||
route="/admin/background-tasks",
|
||||
order=20,
|
||||
),
|
||||
MenuItemDefinition(
|
||||
id="logs",
|
||||
label_key="monitoring.menu.application_logs",
|
||||
icon="document-text",
|
||||
route="/admin/logs",
|
||||
order=30,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
},
|
||||
is_core=False,
|
||||
is_internal=True, # Internal module - admin-only, not customer-facing
|
||||
# =========================================================================
|
||||
|
||||
@@ -10,7 +10,7 @@ from app.modules.billing.models import CapacitySnapshot
|
||||
|
||||
# Admin notification and logging models
|
||||
from app.modules.messaging.models import AdminNotification
|
||||
from models.database.admin import PlatformAlert
|
||||
from app.modules.tenancy.models import PlatformAlert
|
||||
|
||||
__all__ = [
|
||||
"CapacitySnapshot",
|
||||
|
||||
@@ -18,7 +18,7 @@ from app.api.deps import get_current_admin_api
|
||||
from app.core.database import get_db
|
||||
from app.modules.monitoring.services.admin_audit_service import admin_audit_service
|
||||
from models.schema.auth import UserContext
|
||||
from models.schema.admin import (
|
||||
from app.modules.tenancy.schemas.admin import (
|
||||
AdminAuditLogFilters,
|
||||
AdminAuditLogListResponse,
|
||||
AdminAuditLogResponse,
|
||||
|
||||
@@ -24,7 +24,7 @@ from app.modules.monitoring.services.admin_audit_service import admin_audit_serv
|
||||
from app.modules.core.services.admin_settings_service import admin_settings_service
|
||||
from app.modules.monitoring.services.log_service import log_service
|
||||
from models.schema.auth import UserContext
|
||||
from models.schema.admin import (
|
||||
from app.modules.tenancy.schemas.admin import (
|
||||
ApplicationLogFilters,
|
||||
ApplicationLogListResponse,
|
||||
FileLogResponse,
|
||||
@@ -280,7 +280,7 @@ def update_log_settings(
|
||||
Changes are applied immediately without restart (for log level).
|
||||
File rotation settings require restart.
|
||||
"""
|
||||
from models.schema.admin import AdminSettingUpdate
|
||||
from app.modules.tenancy.schemas.admin import AdminSettingUpdate
|
||||
|
||||
updated = []
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_db, require_menu_access
|
||||
from app.modules.core.utils.page_context import get_admin_context
|
||||
from app.templates_config import templates
|
||||
from models.database.admin_menu_config import FrontendType
|
||||
from models.database.user import User
|
||||
from app.modules.enums import FrontendType
|
||||
from app.modules.tenancy.models import User
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ from sqlalchemy import and_
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.tenancy.exceptions import AdminOperationException
|
||||
from models.database.admin import AdminAuditLog
|
||||
from models.database.user import User
|
||||
from models.schema.admin import AdminAuditLogFilters, AdminAuditLogResponse
|
||||
from app.modules.tenancy.models import AdminAuditLog
|
||||
from app.modules.tenancy.models import User
|
||||
from app.modules.tenancy.schemas.admin import AdminAuditLogFilters, AdminAuditLogResponse
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ from sqlalchemy.orm import Session
|
||||
from app.core.config import settings
|
||||
from app.exceptions import ResourceNotFoundException
|
||||
from app.modules.tenancy.exceptions import AdminOperationException
|
||||
from models.database.admin import ApplicationLog
|
||||
from models.schema.admin import (
|
||||
from app.modules.tenancy.models import ApplicationLog
|
||||
from app.modules.tenancy.schemas.admin import (
|
||||
ApplicationLogFilters,
|
||||
ApplicationLogListResponse,
|
||||
ApplicationLogResponse,
|
||||
|
||||
@@ -20,7 +20,7 @@ from app.modules.core.services.image_service import image_service
|
||||
from app.modules.inventory.models import Inventory
|
||||
from app.modules.orders.models import Order
|
||||
from app.modules.catalog.models import Product
|
||||
from models.database.vendor import Vendor
|
||||
from app.modules.tenancy.models import Vendor
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -173,7 +173,7 @@ class PlatformHealthService:
|
||||
Returns aggregated limits and current usage for capacity planning.
|
||||
"""
|
||||
from app.modules.billing.models import VendorSubscription
|
||||
from models.database.vendor import VendorUser
|
||||
from app.modules.tenancy.models import VendorUser
|
||||
|
||||
# Get all active subscriptions with their limits
|
||||
subscriptions = (
|
||||
|
||||
Reference in New Issue
Block a user