Files
orion/app/modules/__init__.py
Samir Boulahtit aad18c27ab
Some checks failed
CI / ruff (push) Successful in 11s
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
CI / pytest (push) Has started running
refactor: remove all backward compatibility code across 70 files
Clean up 28 backward compatibility instances identified in the codebase.
The app is not live, so all shims are replaced with the target architecture:

- Remove legacy Inventory.location column (use bin_location exclusively)
- Remove dashboard _extract_metric_value helper (use flat metrics dict)
- Remove legacy stat field duplicates (total_stores, total_imports, etc.)
- Remove 13 re-export shims and class aliases across modules
- Remove module-enabling JSON fallback (use PlatformModule junction table)
- Remove menu_to_legacy_format() conversion (return dataclasses directly)
- Remove title/description from MarketplaceProductBase schema
- Clean billing convenience method docstrings
- Clean test fixtures and backward-compat comments
- Add PlatformModule seeding to init_production.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 13:20:29 +01:00

115 lines
3.4 KiB
Python

# app/modules/__init__.py
"""
Modular Platform Architecture.
This package provides a module system for enabling/disabling feature bundles per platform.
Three-Tier Classification:
1. CORE MODULES (4) - Always enabled, cannot be disabled
- core, tenancy, cms, customers
2. OPTIONAL MODULES (7) - Can be enabled/disabled per platform
- payments, billing, inventory, orders, marketplace, analytics, messaging
3. INTERNAL MODULES (2) - Admin-only tools, not customer-facing
- dev-tools, monitoring
Module Hierarchy:
Global (SaaS Provider)
└── Platform (Business Product - OMS, Loyalty, etc.)
└── Modules (Enabled features - Billing, Marketplace, Inventory, etc.)
├── Routes (API + Page routes)
├── Services (Business logic)
├── Tasks (Celery background jobs)
├── Menu Items (Sidebar entries)
├── Templates (UI components)
└── Migrations (Module-specific)
Modules vs Features:
- Features: Granular capabilities (e.g., analytics_dashboard, letzshop_sync)
Assigned to subscription tiers, gated at API route level.
- Modules: Cohesive feature bundles (e.g., billing, marketplace, inventory)
Enabled/disabled per platform, contains multiple features and menu items.
Usage:
from app.modules import module_service
from app.modules.base import ModuleDefinition
from app.modules.registry import MODULES, CORE_MODULES, OPTIONAL_MODULES
from app.modules.events import module_event_bus, ModuleEvent
# Check if module is enabled for platform
if module_service.is_module_enabled(platform_id, "billing"):
...
# Get menu items for enabled modules
menu_items = module_service.get_module_menu_items(platform_id, FrontendType.ADMIN)
# Get all enabled modules for platform
modules = module_service.get_platform_modules(platform_id)
# Subscribe to module events
@module_event_bus.subscribe(ModuleEvent.ENABLED)
def on_enabled(data):
print(f"Module {data.module_code} enabled")
"""
from app.modules.base import ModuleDefinition, ScheduledTask
from app.modules.events import (
ModuleEvent,
ModuleEventBus,
ModuleEventData,
module_event_bus,
)
from app.modules.registry import (
CORE_MODULES,
INTERNAL_MODULES,
MODULES,
OPTIONAL_MODULES,
get_core_module_codes,
get_internal_module_codes,
get_module_tier,
get_optional_module_codes,
is_core_module,
is_internal_module,
)
from app.modules.service import ModuleService, module_service
from app.modules.task_base import ModuleTask
from app.modules.tasks import (
build_beat_schedule,
discover_module_tasks,
get_module_task_routes,
parse_schedule,
)
__all__ = [
# Core types
"ModuleDefinition",
"ScheduledTask",
# Task support
"ModuleTask",
"discover_module_tasks",
"build_beat_schedule",
"parse_schedule",
"get_module_task_routes",
# Module dictionaries
"MODULES",
"CORE_MODULES",
"OPTIONAL_MODULES",
"INTERNAL_MODULES",
# Helper functions
"get_core_module_codes",
"get_optional_module_codes",
"get_internal_module_codes",
"get_module_tier",
"is_core_module",
"is_internal_module",
# Service
"ModuleService",
"module_service",
# Events
"ModuleEvent",
"ModuleEventData",
"ModuleEventBus",
"module_event_bus",
]