ADR-018 — Scaffold options as template symbols (--bff-routes, --hosting)
Date: 2026-10-03
Status: Accepted
Extends: ADR-006 (BFF cookie session), ADR-007 (SPA served same-origin).
Library side: DevPack 10.20.0 — Identity/Authentication/Bff (MapBffGroup, BffAntiforgeryMiddleware) and the ITLab.Template.DevPack.OpenApi sub-package.
Origin: ABBC Hub backport, wave W6 (G2, D1, C6).
Context
Two choices of the ABBC hub are sound but not universal: the browser-owned routes on a separate /private surface
that no token reaches, and the SPA served by an nginx sidecar instead of the API. Hard-wiring either into the canon
would impose it on every project; copying it from a document would let it drift. Until now template.json had no
symbols at all, and examples/ holds business features to copy, not infrastructure that rewires Program.cs.
Decision
An option that changes Program.cs, the routes or the deployment is a dotnet new symbol. A business feature to
copy stays in examples/. Defaults reproduce the output as it was.
--bff-routes (bool, default false)
- The browser-owned surface —
/authsession endpoints (sign-in, MFA, profile, password, tenant switch, antiforgery, Entra cookie session),users,groups,tenants,permissions,system,client-certificates— is mapped onapp.MapBffGroup("/private")(DevPack): unversioned (the SPA ships with the API), authorized only by the session cookie scheme (a Bearer token gets401anywhere under it) and listed in theinternalOpenAPI document (Development only), never inv1. /v1keeps what a token client needs:orders(and every business feature),auth/token,auth/token/refresh,auth/token/mfa,auth/clients/token,auth/entra/token,auth/config. A Bearer client therefore losesme,tenantsandtenant/switch— accepted: under this option the browser is the only client of the console surface.- Mechanics. The prefix lives in three constants —
ApiRoutes.Bff(Api),Routes.Bff(integration tests),BFFinSpa/src/lib/api/routes.ts— rewritten byreplacessymbols.Program.csswitches the mapping with#if (BffRoutes);AuthEndpointssplits intoMapSessionAuthandMapTokenAuth. Code never writes the browser prefix as a literal.
--hosting api|nginx-sidecar (choice, default api)
nginx-sidecaraddsSpa/Dockerfile(no API address baked in),nginx.conf.template(per-request DNS through a variable,/_spa-healthfor the container's own probe, immutable/assets,index.htmlno-store, SPA fallback),proxy-headers.confanddeploy/containerapp.sample.yaml(API on127.0.0.1:8081,ForwardedHeaders__Enabled, three explicit probes per container). The API stops bundling the SPA on publish (BuildSpaOnPublishdefaults tofalse). Nothing about the hub's names or resources comes along.
Validation
The repository compiles only the defaults, so each combination is scaffolded and tested in template-publish.yml
(a four-entry matrix: defaults, --bff-routes, --hosting nginx-sidecar, both). Tests that only make sense under a
symbol live in files wrapped in #if (BffRoutesTests).
Consequences
- A preprocessor
#ifin any.csfile is now evaluated by the template engine: an unrelated#if DEBUGwould be stripped from the output. Use runtime checks (IHostEnvironment) instead. - The browser prefix is a convention to keep: a new browser route uses the constant, or it stays behind on
/v1when the option is on — the--bff-routesprobe is what catches it. - The OpenAPI contract published by CI (
--dump-openapi v1) is the public one in both modes.
Alternatives considered
- Two templates (
itlab-fullstack,itlab-fullstack-bff): duplicates every file for one routing difference. - A runtime switch (
Bff:Enabled): the SPA would need the prefix at build time anyway, and the dormant branch would ship in every project. - Docs-only recipe: the hub showed how such recipes drift —
/privatewas never restricted to the cookie there.