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:
@@ -10,17 +10,23 @@ This module bridges the gap between the module system and FastAPI,
|
||||
allowing routes to be defined within modules and automatically
|
||||
discovered and registered.
|
||||
|
||||
Usage:
|
||||
# In main.py
|
||||
from app.modules.routes import discover_module_routes
|
||||
Route Discovery:
|
||||
Routes are discovered from these file locations in each module:
|
||||
- routes/api/admin.py -> /api/v1/admin/*
|
||||
- routes/api/vendor.py -> /api/v1/vendor/*
|
||||
- routes/api/storefront.py -> /api/v1/storefront/*
|
||||
- routes/pages/admin.py -> /admin/*
|
||||
- routes/pages/vendor.py -> /vendor/*
|
||||
|
||||
# Auto-discover and register routes
|
||||
for route_info in discover_module_routes():
|
||||
app.include_router(
|
||||
route_info["router"],
|
||||
prefix=route_info["prefix"],
|
||||
tags=route_info["tags"],
|
||||
include_in_schema=route_info.get("include_in_schema", True),
|
||||
Usage:
|
||||
# In app/api/v1/{admin,vendor,storefront}/__init__.py
|
||||
from app.modules.routes import get_admin_api_routes # or vendor/storefront
|
||||
|
||||
for route_info in get_admin_api_routes():
|
||||
router.include_router(
|
||||
route_info.router,
|
||||
prefix=route_info.custom_prefix or "",
|
||||
tags=route_info.tags,
|
||||
)
|
||||
|
||||
Route Configuration:
|
||||
@@ -160,7 +166,7 @@ def _discover_routes_in_dir(
|
||||
"""
|
||||
routes: list[RouteInfo] = []
|
||||
|
||||
# Look for admin.py, vendor.py, shop.py
|
||||
# Look for admin.py, vendor.py, storefront.py, public.py, webhooks.py
|
||||
frontends = {
|
||||
"admin": {
|
||||
"api_prefix": "/api/v1/admin",
|
||||
@@ -172,11 +178,21 @@ def _discover_routes_in_dir(
|
||||
"pages_prefix": "/vendor",
|
||||
"include_in_schema": True if route_type == "api" else False,
|
||||
},
|
||||
"shop": {
|
||||
"api_prefix": "/api/v1/shop",
|
||||
"pages_prefix": "/shop",
|
||||
"storefront": {
|
||||
"api_prefix": "/api/v1/storefront",
|
||||
"pages_prefix": "/storefront",
|
||||
"include_in_schema": True if route_type == "api" else False,
|
||||
},
|
||||
"public": {
|
||||
"api_prefix": "/api/v1/public",
|
||||
"pages_prefix": "/public",
|
||||
"include_in_schema": True,
|
||||
},
|
||||
"webhooks": {
|
||||
"api_prefix": "/api/v1/webhooks",
|
||||
"pages_prefix": "/webhooks",
|
||||
"include_in_schema": True,
|
||||
},
|
||||
}
|
||||
|
||||
for frontend, config in frontends.items():
|
||||
@@ -304,6 +320,90 @@ def get_vendor_api_routes() -> list[RouteInfo]:
|
||||
return sorted(routes, key=lambda r: r.priority)
|
||||
|
||||
|
||||
def get_storefront_api_routes() -> list[RouteInfo]:
|
||||
"""
|
||||
Get storefront API routes from modules, sorted by priority.
|
||||
|
||||
Returns routes sorted by priority (lower first, higher last).
|
||||
This ensures catch-all routes (priority 100+) are registered after
|
||||
specific routes.
|
||||
"""
|
||||
routes = [
|
||||
r for r in discover_module_routes()
|
||||
if r.route_type == "api" and r.frontend == "storefront"
|
||||
]
|
||||
return sorted(routes, key=lambda r: r.priority)
|
||||
|
||||
|
||||
def get_public_api_routes() -> list[RouteInfo]:
|
||||
"""
|
||||
Get public API routes from modules, sorted by priority.
|
||||
|
||||
Public routes are unauthenticated endpoints for marketing pages,
|
||||
pricing info, and other public-facing features.
|
||||
"""
|
||||
routes = [
|
||||
r for r in discover_module_routes()
|
||||
if r.route_type == "api" and r.frontend == "public"
|
||||
]
|
||||
return sorted(routes, key=lambda r: r.priority)
|
||||
|
||||
|
||||
def get_webhooks_api_routes() -> list[RouteInfo]:
|
||||
"""
|
||||
Get webhook API routes from modules, sorted by priority.
|
||||
|
||||
Webhook routes handle callbacks from external services
|
||||
(Stripe, payment providers, etc.).
|
||||
"""
|
||||
routes = [
|
||||
r for r in discover_module_routes()
|
||||
if r.route_type == "api" and r.frontend == "webhooks"
|
||||
]
|
||||
return sorted(routes, key=lambda r: r.priority)
|
||||
|
||||
|
||||
def get_public_page_routes() -> list[RouteInfo]:
|
||||
"""
|
||||
Get public (marketing) page routes from modules, sorted by priority.
|
||||
|
||||
Public pages are unauthenticated marketing pages like:
|
||||
- Homepage (/)
|
||||
- Pricing (/pricing)
|
||||
- Signup (/signup)
|
||||
- Find shop (/find-shop)
|
||||
- CMS catch-all (/{slug})
|
||||
|
||||
Note: CMS routes should have priority=100 to be registered last
|
||||
since they have catch-all patterns.
|
||||
"""
|
||||
routes = [
|
||||
r for r in discover_module_routes()
|
||||
if r.route_type == "pages" and r.frontend == "public"
|
||||
]
|
||||
return sorted(routes, key=lambda r: r.priority)
|
||||
|
||||
|
||||
def get_storefront_page_routes() -> list[RouteInfo]:
|
||||
"""
|
||||
Get storefront (customer shop) page routes from modules, sorted by priority.
|
||||
|
||||
Storefront pages include:
|
||||
- Catalog pages (/, /products, /products/{id}, /categories/{slug})
|
||||
- Cart and checkout (/cart, /checkout)
|
||||
- Account pages (/account/*)
|
||||
- CMS content pages (/{slug})
|
||||
|
||||
Note: CMS routes should have priority=100 to be registered last
|
||||
since they have catch-all patterns.
|
||||
"""
|
||||
routes = [
|
||||
r for r in discover_module_routes()
|
||||
if r.route_type == "pages" and r.frontend == "storefront"
|
||||
]
|
||||
return sorted(routes, key=lambda r: r.priority)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"RouteInfo",
|
||||
"discover_module_routes",
|
||||
@@ -313,4 +413,9 @@ __all__ = [
|
||||
"get_admin_page_routes",
|
||||
"get_admin_api_routes",
|
||||
"get_vendor_api_routes",
|
||||
"get_storefront_api_routes",
|
||||
"get_public_api_routes",
|
||||
"get_webhooks_api_routes",
|
||||
"get_public_page_routes",
|
||||
"get_storefront_page_routes",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user