refactor: migrate templates and static files to self-contained modules

Templates Migration:
- Migrate admin templates to modules (tenancy, billing, monitoring, marketplace, etc.)
- Migrate vendor templates to modules (tenancy, billing, orders, messaging, etc.)
- Migrate storefront templates to modules (catalog, customers, orders, cart, checkout, cms)
- Migrate public templates to modules (billing, marketplace, cms)
- Keep shared templates in app/templates/ (base.html, errors/, partials/, macros/)
- Migrate letzshop partials to marketplace module

Static Files Migration:
- Migrate admin JS to modules: tenancy (23 files), core (5 files), monitoring (1 file)
- Migrate vendor JS to modules: tenancy (4 files), core (2 files)
- Migrate shared JS: vendor-selector.js to core, media-picker.js to cms
- Migrate storefront JS: storefront-layout.js to core
- Keep framework JS in static/ (api-client, utils, money, icons, log-config, lib/)
- Update all template references to use module_static paths

Naming Consistency:
- Rename static/platform/ to static/public/
- Rename app/templates/platform/ to app/templates/public/
- Update all extends and static references

Documentation:
- Update module-system.md with shared templates documentation
- Update frontend-structure.md with new module JS organization

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-01 14:34:16 +01:00
parent 843703258f
commit 4e28d91a78
542 changed files with 11603 additions and 9037 deletions

148
main.py
View File

@@ -61,14 +61,13 @@ from app.core.lifespan import lifespan
from app.exceptions import ServiceUnavailableException
from app.exceptions.handler import setup_exception_handlers
# Import page routers (legacy routes - will be migrated to modules)
from app.routes import admin_pages, platform_pages, storefront_pages, vendor_pages
# Import CMS module admin pages
from app.modules.cms.routes.pages.admin import router as cms_admin_pages
# Module route auto-discovery
from app.modules.routes import discover_module_routes, get_vendor_page_routes
# Module route auto-discovery - all page routes now come from modules
from app.modules.routes import (
get_admin_page_routes,
get_public_page_routes,
get_storefront_page_routes,
get_vendor_page_routes,
)
from app.utils.i18n import get_jinja2_globals
from middleware.context import ContextMiddleware
from middleware.language import LanguageMiddleware
@@ -304,87 +303,94 @@ def health_check(db: Session = Depends(get_db)):
# ============================================================================
# HTML PAGE ROUTES (Jinja2 Templates)
# HTML PAGE ROUTES (Jinja2 Templates) - AUTO-DISCOVERED FROM MODULES
# ============================================================================
# Include HTML page routes (these return rendered templates, not JSON)
# All page routes are now auto-discovered from self-contained modules.
# Routes are discovered from app/modules/*/routes/pages/{admin,vendor,public,storefront}.py
logger.info("=" * 80)
logger.info("ROUTE REGISTRATION")
logger.info("ROUTE REGISTRATION (AUTO-DISCOVERY)")
logger.info("=" * 80)
# Platform marketing pages (homepage, pricing, signup)
logger.info("Registering platform page routes: /*, /pricing, /find-shop, /signup")
app.include_router(
platform_pages.router, prefix="", tags=["platform-pages"], include_in_schema=False
)
# Admin pages
logger.info("Registering admin page routes: /admin/*")
app.include_router(
admin_pages.router, prefix="/admin", tags=["admin-pages"], include_in_schema=False
)
# CMS module admin pages (self-contained module)
# NOTE: These routes are specific (/content-pages/*) so they won't conflict
logger.info("Registering CMS admin page routes: /admin/content-pages/*")
app.include_router(
cms_admin_pages, prefix="/admin", tags=["cms-admin-pages"], include_in_schema=False
)
# Vendor management pages (dashboard, products, orders, etc.)
# NOTE: Legacy routes - modules with their own routes will override these
logger.info("Registering vendor page routes: /vendor/{code}/*")
app.include_router(
vendor_pages.router,
prefix="/vendor",
tags=["vendor-pages"],
include_in_schema=False,
)
# =============================================================================
# AUTO-DISCOVERED MODULE ROUTES
# PUBLIC PAGES (Marketing pages - homepage, pricing, signup, etc.)
# =============================================================================
# Self-contained modules register their routes automatically.
# Routes are discovered from app/modules/*/routes/pages/ and routes/api/
# NOTE: CMS has catch-all route, so it's registered last via priority sorting
# Public pages are served at root level (/) for platform marketing
logger.info("Auto-discovering public (marketing) page routes...")
public_page_routes = get_public_page_routes()
logger.info(f" Found {len(public_page_routes)} public page route modules")
logger.info("Auto-discovering module page routes...")
vendor_page_routes = get_vendor_page_routes()
# Sort routes: CMS last (has catch-all), others alphabetically
def route_priority(route):
if route.module_code == "cms":
return (1, route.module_code) # CMS last
return (0, route.module_code)
vendor_page_routes.sort(key=route_priority)
for route_info in vendor_page_routes:
logger.info(f" Registering {route_info.module_code} vendor pages: {route_info.prefix}")
for route_info in public_page_routes:
logger.info(f" Registering {route_info.module_code} public pages (priority={route_info.priority})")
app.include_router(
route_info.router,
prefix=route_info.prefix,
prefix="", # Public pages at root
tags=route_info.tags,
include_in_schema=route_info.include_in_schema,
)
# =============================================================================
# ADMIN PAGES
# =============================================================================
logger.info("Auto-discovering admin page routes...")
admin_page_routes = get_admin_page_routes()
logger.info(f" Found {len(admin_page_routes)} admin page route modules")
for route_info in admin_page_routes:
logger.info(f" Registering {route_info.module_code} admin pages")
app.include_router(
route_info.router,
prefix="/admin",
tags=route_info.tags,
include_in_schema=route_info.include_in_schema,
)
# =============================================================================
# VENDOR PAGES
# =============================================================================
logger.info("Auto-discovering vendor page routes...")
vendor_page_routes = get_vendor_page_routes()
logger.info(f" Found {len(vendor_page_routes)} vendor page route modules")
for route_info in vendor_page_routes:
logger.info(f" Registering {route_info.module_code} vendor pages (priority={route_info.priority})")
app.include_router(
route_info.router,
prefix="/vendor",
tags=route_info.tags,
include_in_schema=route_info.include_in_schema,
)
# =============================================================================
# STOREFRONT PAGES (Customer Shop)
# =============================================================================
# Customer shop pages - Register at TWO prefixes:
# 1. /storefront/* (for subdomain/custom domain modes)
# 2. /vendors/{code}/storefront/* (for path-based development mode)
logger.info("Registering storefront page routes:")
logger.info(" - /storefront/* (subdomain/custom domain mode)")
logger.info(" - /vendors/{code}/storefront/* (path-based development mode)")
logger.info("Auto-discovering storefront page routes...")
storefront_page_routes = get_storefront_page_routes()
logger.info(f" Found {len(storefront_page_routes)} storefront page route modules")
app.include_router(
storefront_pages.router, prefix="/storefront", tags=["storefront-pages"], include_in_schema=False
)
# Register at /storefront/* (direct access)
logger.info(" Registering storefront routes at /storefront/*")
for route_info in storefront_page_routes:
logger.info(f" - {route_info.module_code} (priority={route_info.priority})")
app.include_router(
route_info.router,
prefix="/storefront",
tags=["storefront-pages"],
include_in_schema=False,
)
app.include_router(
storefront_pages.router,
prefix="/vendors/{vendor_code}/storefront",
tags=["storefront-pages"],
include_in_schema=False,
)
# Register at /vendors/{code}/storefront/* (path-based development mode)
logger.info(" Registering storefront routes at /vendors/{code}/storefront/*")
for route_info in storefront_page_routes:
app.include_router(
route_info.router,
prefix="/vendors/{vendor_code}/storefront",
tags=["storefront-pages"],
include_in_schema=False,
)
# Add handler for /vendors/{vendor_code}/ root path
@@ -402,7 +408,7 @@ async def vendor_root_path(
if not vendor:
raise HTTPException(status_code=404, detail=f"Vendor '{vendor_code}' not found")
from app.routes.storefront_pages import get_storefront_context
from app.modules.core.utils.page_context import get_storefront_context
from app.modules.cms.services import content_page_service
# Get platform_id (use platform from context or default to 1 for OMS)