Pular para o conteúdo principal
Versão: main (dev) 🚧

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 — /auth session endpoints (sign-in, MFA, profile, password, tenant switch, antiforgery, Entra cookie session), users, groups, tenants, permissions, system, client-certificates — is mapped on app.MapBffGroup("/private") (DevPack): unversioned (the SPA ships with the API), authorized only by the session cookie scheme (a Bearer token gets 401 anywhere under it) and listed in the internal OpenAPI document (Development only), never in v1.
  • /v1 keeps 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 loses me, tenants and tenant/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), BFF in Spa/src/lib/api/routes.ts — rewritten by replaces symbols. Program.cs switches the mapping with #if (BffRoutes); AuthEndpoints splits into MapSessionAuth and MapTokenAuth. Code never writes the browser prefix as a literal.

--hosting api|nginx-sidecar (choice, default api)​

  • nginx-sidecar adds Spa/Dockerfile (no API address baked in), nginx.conf.template (per-request DNS through a variable, /_spa-health for the container's own probe, immutable /assets, index.html no-store, SPA fallback), proxy-headers.conf and deploy/containerapp.sample.yaml (API on 127.0.0.1:8081, ForwardedHeaders__Enabled, three explicit probes per container). The API stops bundling the SPA on publish (BuildSpaOnPublish defaults to false). 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 #if in any .cs file is now evaluated by the template engine: an unrelated #if DEBUG would 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 /v1 when the option is on — the --bff-routes probe 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 — /private was never restricted to the cookie there.