Move 9 init/seed scripts into scripts/seed/ and 7 validation scripts (+ validators/ subfolder) into scripts/validate/ to reduce clutter in the root scripts/ directory. Update all references across Makefile, CI/CD configs, pre-commit hooks, docs (~40 files), and Python imports. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
8.9 KiB
8.9 KiB
Self-Contained Module Routes Migration Plan
Date: 2026-01-30 Goal: Migrate all routes to self-contained modules, remove all legacy route files
Current State
Modules (17 total)
analytics, billing, cart, catalog, checkout, cms, customers, dev_tools,
inventory, loyalty, marketplace, messaging, monitoring, orders, payments
Legacy Route Files to Migrate
Admin API Routes (34 files in app/api/v1/admin/)
| File | Target Module | Status |
|---|---|---|
admin_users.py |
PLATFORM CORE | Keep in legacy |
audit.py |
PLATFORM CORE | Keep in legacy |
auth.py |
PLATFORM CORE | Keep in legacy |
background_tasks.py |
monitoring | Migrate |
code_quality.py |
dev_tools | Migrate |
merchants.py |
PLATFORM CORE | Keep in legacy |
dashboard.py |
PLATFORM CORE | Keep in legacy |
email_templates.py |
messaging | Migrate |
features.py |
billing | Migrate |
images.py |
cms | Migrate |
inventory.py |
inventory | Already migrated (re-export) |
letzshop.py |
marketplace | Already migrated (re-export) |
logs.py |
monitoring | Migrate |
marketplace.py |
marketplace | Already migrated (re-export) |
media.py |
cms | Migrate |
menu_config.py |
PLATFORM CORE | Keep in legacy |
messages.py |
messaging | Migrate |
module_config.py |
PLATFORM CORE | Keep in legacy |
modules.py |
PLATFORM CORE | Keep in legacy |
monitoring.py |
monitoring | Migrate |
notifications.py |
messaging | Migrate |
order_item_exceptions.py |
orders | Already migrated (re-export) |
orders.py |
orders | Already migrated (re-export) |
platform_health.py |
monitoring | Migrate |
platforms.py |
PLATFORM CORE | Keep in legacy |
products.py |
catalog | Migrate |
settings.py |
PLATFORM CORE | Keep in legacy |
subscriptions.py |
billing | Already migrated (re-export) |
tests.py |
dev_tools | Migrate |
users.py |
PLATFORM CORE | Keep in legacy |
store_domains.py |
PLATFORM CORE | Keep in legacy |
store_products.py |
catalog | Migrate |
stores.py |
PLATFORM CORE | Keep in legacy |
store_themes.py |
cms | Migrate |
Store API Routes (24 files in app/api/v1/store/)
| File | Target Module | Status |
|---|---|---|
analytics.py |
analytics | Migrate |
auth.py |
PLATFORM CORE | Keep in legacy |
billing.py |
billing | Already migrated (re-export) |
dashboard.py |
PLATFORM CORE | Keep in legacy |
email_settings.py |
messaging | Migrate |
email_templates.py |
messaging | Migrate |
features.py |
billing | Migrate |
info.py |
PLATFORM CORE | Keep in legacy |
inventory.py |
inventory | Already migrated (re-export) |
invoices.py |
billing | Migrate |
letzshop.py |
marketplace | Already migrated (re-export) |
marketplace.py |
marketplace | Already migrated (re-export) |
media.py |
cms | Migrate |
messages.py |
messaging | Migrate |
notifications.py |
messaging | Migrate |
onboarding.py |
marketplace | Migrate |
order_item_exceptions.py |
orders | Already migrated (re-export) |
orders.py |
orders | Already migrated (re-export) |
payments.py |
payments | Migrate |
products.py |
catalog | Migrate |
profile.py |
PLATFORM CORE | Keep in legacy |
settings.py |
PLATFORM CORE | Keep in legacy |
team.py |
PLATFORM CORE | Keep in legacy |
usage.py |
billing | Migrate |
Page Routes (4 files in app/routes/)
| File | Target Module | Status |
|---|---|---|
admin_pages.py |
Split across modules | Migrate page by page |
store_pages.py |
Split across modules | Migrate page by page |
storefront_pages.py |
Split across modules | Migrate page by page |
platform_pages.py |
PLATFORM CORE | Keep in legacy |
Migration Summary
Files to Migrate (by module)
1. billing (5 routes)
app/api/v1/admin/features.pyapp/api/v1/store/features.pyapp/api/v1/store/invoices.pyapp/api/v1/store/usage.py- Remove re-exports:
subscriptions.py,billing.py
2. catalog (3 routes)
app/api/v1/admin/products.pyapp/api/v1/admin/store_products.pyapp/api/v1/store/products.py
3. cms (4 routes)
app/api/v1/admin/images.pyapp/api/v1/admin/media.pyapp/api/v1/admin/store_themes.pyapp/api/v1/store/media.py
4. messaging (7 routes)
app/api/v1/admin/email_templates.pyapp/api/v1/admin/messages.pyapp/api/v1/admin/notifications.pyapp/api/v1/store/email_settings.pyapp/api/v1/store/email_templates.pyapp/api/v1/store/messages.pyapp/api/v1/store/notifications.py
5. monitoring (4 routes)
app/api/v1/admin/background_tasks.pyapp/api/v1/admin/logs.pyapp/api/v1/admin/monitoring.pyapp/api/v1/admin/platform_health.py
6. dev_tools (2 routes)
app/api/v1/admin/code_quality.pyapp/api/v1/admin/tests.py
7. marketplace (1 route)
app/api/v1/store/onboarding.py- Remove re-exports:
letzshop.py,marketplace.py
8. analytics (1 route)
app/api/v1/store/analytics.py
9. payments (1 route)
app/api/v1/store/payments.py
10. orders (cleanup)
- Remove re-exports:
orders.py,order_item_exceptions.py
11. inventory (cleanup)
- Remove re-exports:
inventory.py
Files to Keep in Platform Core (12 admin + 6 store = 18 files)
Admin:
admin_users.py- Admin user management (super admin only)audit.py- Platform audit logsauth.py- Admin authenticationmerchants.py- Merchant managementdashboard.py- Admin dashboardmenu_config.py- Menu configurationmodule_config.py- Module configurationmodules.py- Module managementplatforms.py- Platform managementsettings.py- Platform settingsusers.py- Platform user managementstore_domains.py- Store domain managementstores.py- Store management
Store:
auth.py- Store authenticationdashboard.py- Store dashboardinfo.py- Store info endpointprofile.py- Store profilesettings.py- Store settingsteam.py- Store team management
Execution Plan
Phase 1: API Routes (Priority Order)
- messaging (7 files) - Largest module, get it done first
- billing (5 files) - Already partially migrated
- monitoring (4 files) - Self-contained
- cms (4 files) - Already partially migrated
- catalog (3 files) - Product management
- dev_tools (2 files) - Testing tools
- marketplace (1 file) - Just onboarding
- analytics (1 file) - Simple
- payments (1 file) - Simple
- Cleanup - Remove all re-export files for orders, inventory
Phase 2: Page Routes
Each module that has admin/store pages needs:
- Create
app/modules/{module}/routes/pages/admin.py - Create
app/modules/{module}/routes/pages/store.py - Move relevant page handlers from legacy files
- Update
admin_pages.py/store_pages.pyto import from modules
Phase 3: Storefront Routes
- cart module - Cart pages
- catalog module - Product listing, detail pages
- checkout module - Checkout flow
- customers module - Customer account pages
Pattern Reference (from customers module)
Module Route Structure
app/modules/{module}/
├── routes/
│ ├── __init__.py # Lazy exports
│ ├── admin.py # Admin API routes with admin_router
│ ├── store.py # Store API routes with store_router
│ ├── api/ # Optional: Split API routes
│ │ ├── admin.py
│ │ ├── store.py
│ │ └── storefront.py
│ └── pages/ # HTML page routes
│ ├── admin.py
│ └── store.py
└── definition.py # Module definition with router getters
Module Definition Pattern
def _get_admin_router():
from app.modules.{module}.routes.admin import admin_router
return admin_router
def _get_store_router():
from app.modules.{module}.routes.store import store_router
return store_router
# In get_{module}_module_with_routers():
{module}_module.admin_router = _get_admin_router()
{module}_module.store_router = _get_store_router()
Router Registration in app/api/v1/{admin,store}/__init__.py
# Import module router
from app.modules.{module}.routes.admin import admin_router as {module}_admin_router
# Include with module access control
router.include_router({module}_admin_router, tags=["admin-{module}"])
# Legacy: router.include_router({module}.router, tags=["admin-{module}"])
Validation
After each module migration:
- Run
python scripts/validate/validate_architecture.py - Test affected endpoints manually
- Verify imports work:
python -c "from app.api.v1.admin import router"
Estimated Effort
- API Routes: ~28 files to migrate across 9 modules
- Page Routes: ~15-20 page handlers to move
- Total: 1-2 sessions depending on complexity