Add fragment composition infrastructure for micro-frontend UI

New HTTP client (fragments.py) fetches HTML fragments from other apps
over the Docker network, with Redis caching and graceful degradation.
Jinja global `fragment()` available in all templates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-24 08:26:08 +00:00
parent e7d180912b
commit b882770828
2 changed files with 169 additions and 0 deletions

View File

@@ -107,5 +107,14 @@ def setup_jinja(app: Quart) -> None:
from shared.services.widget_registry import widgets as _widget_registry
app.jinja_env.globals["widgets"] = _widget_registry
# fragment composition helper — fetch HTML from another app's fragment API
from shared.infrastructure.fragments import fetch_fragment_cached
async def _fragment(app_name: str, fragment_type: str, ttl: int = 30, **params) -> str:
p = params if params else None
return await fetch_fragment_cached(app_name, fragment_type, params=p, ttl=ttl)
app.jinja_env.globals["fragment"] = _fragment
# register jinja filters
register_filters(app)