Files
orion/app/modules/customers/definition.py
Samir Boulahtit d7a0ff8818 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>
2026-02-01 21:02:56 +01:00

111 lines
3.6 KiB
Python

# app/modules/customers/definition.py
"""
Customers module definition.
Defines the customers 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_admin_router():
"""Lazy import of admin router to avoid circular imports."""
from app.modules.customers.routes.admin import admin_router
return admin_router
def _get_vendor_router():
"""Lazy import of vendor router to avoid circular imports."""
from app.modules.customers.routes.vendor import vendor_router
return vendor_router
# Customers module definition
customers_module = ModuleDefinition(
code="customers",
name="Customer Management",
description="Customer database, profiles, addresses, and segmentation.",
version="1.0.0",
features=[
"customer_view", # View customer profiles
"customer_export", # Export customer data
"customer_profiles", # Detailed customer profiles
"customer_segmentation", # Customer tagging and segments
"customer_addresses", # Address management
"customer_authentication", # Customer login/registration
],
menu_items={
FrontendType.ADMIN: [
"customers", # Platform-wide customer view
],
FrontendType.VENDOR: [
"customers", # Vendor customer list
],
},
# New module-driven menu definitions
menus={
FrontendType.ADMIN: [
MenuSectionDefinition(
id="vendorOps",
label_key="customers.menu.vendor_operations",
icon="user-group",
order=40,
items=[
MenuItemDefinition(
id="customers",
label_key="customers.menu.customers",
icon="user-group",
route="/admin/customers",
order=20,
),
],
),
],
FrontendType.VENDOR: [
MenuSectionDefinition(
id="customers",
label_key="customers.menu.customers_section",
icon="user-group",
order=30,
items=[
MenuItemDefinition(
id="customers",
label_key="customers.menu.all_customers",
icon="user-group",
route="/vendor/{vendor_code}/customers",
order=10,
),
],
),
],
},
is_core=True, # Customers is a core module - customer data is fundamental
# =========================================================================
# Self-Contained Module Configuration
# =========================================================================
is_self_contained=True,
services_path="app.modules.customers.services",
models_path="app.modules.customers.models",
schemas_path="app.modules.customers.schemas",
exceptions_path="app.modules.customers.exceptions",
)
def get_customers_module_with_routers() -> ModuleDefinition:
"""
Get customers module with routers attached.
This function attaches the routers lazily to avoid circular imports
during module initialization.
"""
customers_module.admin_router = _get_admin_router()
customers_module.vendor_router = _get_vendor_router()
return customers_module
__all__ = ["customers_module", "get_customers_module_with_routers"]