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>
144 lines
4.9 KiB
Python
144 lines
4.9 KiB
Python
# app/modules/marketplace/definition.py
|
|
"""
|
|
Marketplace module definition.
|
|
|
|
Defines the marketplace module including its features, menu items,
|
|
dependencies, route configurations, and scheduled tasks.
|
|
|
|
Note: This module requires the inventory module to be enabled.
|
|
"""
|
|
|
|
from app.modules.base import MenuItemDefinition, MenuSectionDefinition, ModuleDefinition, ScheduledTask
|
|
from app.modules.enums import FrontendType
|
|
|
|
|
|
def _get_admin_router():
|
|
"""Lazy import of admin router to avoid circular imports."""
|
|
from app.modules.marketplace.routes.api.admin import admin_router
|
|
|
|
return admin_router
|
|
|
|
|
|
def _get_vendor_router():
|
|
"""Lazy import of vendor router to avoid circular imports."""
|
|
from app.modules.marketplace.routes.api.vendor import vendor_router
|
|
|
|
return vendor_router
|
|
|
|
|
|
# Marketplace module definition
|
|
marketplace_module = ModuleDefinition(
|
|
code="marketplace",
|
|
name="Marketplace (Letzshop)",
|
|
description=(
|
|
"Letzshop marketplace integration for product sync, order import, "
|
|
"and catalog synchronization."
|
|
),
|
|
version="1.0.0",
|
|
requires=["inventory"], # Depends on inventory module
|
|
features=[
|
|
"letzshop_sync", # Sync products with Letzshop
|
|
"marketplace_import", # Import products from marketplace
|
|
"product_sync", # Bidirectional product sync
|
|
"order_import", # Import orders from marketplace
|
|
"marketplace_analytics", # Marketplace performance metrics
|
|
],
|
|
menu_items={
|
|
FrontendType.ADMIN: [
|
|
"marketplace-letzshop", # Marketplace monitoring
|
|
],
|
|
FrontendType.VENDOR: [
|
|
"marketplace", # Vendor marketplace settings
|
|
"letzshop", # Letzshop integration
|
|
],
|
|
},
|
|
# New module-driven menu definitions
|
|
menus={
|
|
FrontendType.ADMIN: [
|
|
MenuSectionDefinition(
|
|
id="marketplace",
|
|
label_key="marketplace.menu.marketplace",
|
|
icon="shopping-cart",
|
|
order=60,
|
|
items=[
|
|
MenuItemDefinition(
|
|
id="marketplace-letzshop",
|
|
label_key="marketplace.menu.letzshop",
|
|
icon="shopping-cart",
|
|
route="/admin/marketplace/letzshop",
|
|
order=10,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
FrontendType.VENDOR: [
|
|
MenuSectionDefinition(
|
|
id="products",
|
|
label_key="marketplace.menu.products_inventory",
|
|
icon="download",
|
|
order=10,
|
|
items=[
|
|
MenuItemDefinition(
|
|
id="marketplace",
|
|
label_key="marketplace.menu.marketplace_import",
|
|
icon="download",
|
|
route="/vendor/{vendor_code}/marketplace",
|
|
order=30,
|
|
),
|
|
],
|
|
),
|
|
MenuSectionDefinition(
|
|
id="sales",
|
|
label_key="marketplace.menu.sales_orders",
|
|
icon="external-link",
|
|
order=20,
|
|
items=[
|
|
MenuItemDefinition(
|
|
id="letzshop",
|
|
label_key="marketplace.menu.letzshop_orders",
|
|
icon="external-link",
|
|
route="/vendor/{vendor_code}/letzshop",
|
|
order=20,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
},
|
|
is_core=False,
|
|
# =========================================================================
|
|
# Self-Contained Module Configuration
|
|
# =========================================================================
|
|
is_self_contained=True,
|
|
services_path="app.modules.marketplace.services",
|
|
models_path="app.modules.marketplace.models",
|
|
schemas_path="app.modules.marketplace.schemas",
|
|
exceptions_path="app.modules.marketplace.exceptions",
|
|
tasks_path="app.modules.marketplace.tasks",
|
|
# =========================================================================
|
|
# Scheduled Tasks
|
|
# =========================================================================
|
|
scheduled_tasks=[
|
|
ScheduledTask(
|
|
name="marketplace.sync_vendor_directory",
|
|
task="app.modules.marketplace.tasks.sync_tasks.sync_vendor_directory",
|
|
schedule="0 2 * * *", # Daily at 02:00
|
|
options={"queue": "scheduled"},
|
|
),
|
|
],
|
|
)
|
|
|
|
|
|
def get_marketplace_module_with_routers() -> ModuleDefinition:
|
|
"""
|
|
Get marketplace module with routers attached.
|
|
|
|
This function attaches the routers lazily to avoid circular imports
|
|
during module initialization.
|
|
"""
|
|
marketplace_module.admin_router = _get_admin_router()
|
|
marketplace_module.vendor_router = _get_vendor_router()
|
|
return marketplace_module
|
|
|
|
|
|
__all__ = ["marketplace_module", "get_marketplace_module_with_routers"]
|