refactor: standardize modular architecture patterns

- Rename module definition variables to follow naming convention:
  - catalog/definition.py: module → catalog_module
  - checkout/definition.py: module → checkout_module
  - cart/definition.py: module → cart_module

- Add router attachment functions for lazy loading:
  - get_catalog_module_with_routers()
  - get_checkout_module_with_routers()
  - get_cart_module_with_routers()

- Move billing exceptions to exceptions.py:
  - Add backwards-compatible aliases (BillingServiceError, etc.)
  - Update billing_service.py to import from exceptions.py

- Standardize VendorEmailSettingsService DI pattern:
  - Change from db in __init__ to db as method parameter
  - Create singleton vendor_email_settings_service instance
  - Update routes and tests to use new pattern

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-03 18:40:03 +01:00
parent b769f5a047
commit a76128e016
11 changed files with 209 additions and 142 deletions

View File

@@ -9,7 +9,20 @@ Orchestrates payment processing and order creation.
from app.modules.base import ModuleDefinition, PermissionDefinition
module = ModuleDefinition(
# =============================================================================
# Router Lazy Imports
# =============================================================================
def _get_storefront_router():
"""Lazy import of storefront router to avoid circular imports."""
from app.modules.checkout.routes.api.storefront import router
return router
# Checkout module definition
checkout_module = ModuleDefinition(
code="checkout",
name="Checkout",
description="Checkout and order creation for storefronts",
@@ -42,3 +55,17 @@ module = ModuleDefinition(
# Checkout is storefront-only - no admin/vendor menus needed
menu_items={},
)
def get_checkout_module_with_routers() -> ModuleDefinition:
"""
Get checkout module with routers attached.
This function attaches the routers lazily to avoid circular imports
during module initialization.
"""
checkout_module.storefront_router = _get_storefront_router()
return checkout_module
__all__ = ["checkout_module", "get_checkout_module_with_routers"]