DongHyeonka ca161878f2 feat(routes): 기능이 홈을 대신하고 context가 자기 레이아웃을 선언한다 (1101/09-03)
문제: 라우터는 모든 context gateway를 `AppShell` 하나 아래에 붙이고 플랫폼
`/`를 index로 둔다. 기능이 `APP_HOME`을 선언하면 `composeUniqueRecord`가
throw한다. 그래서 제품 홈이 기능 화면이거나 화면이 `AppShell`이 아닌 자기
셸을 쓰면 제품이 템플릿 라우터와 조립 카탈로그를 고쳐야 한다. memento는
카탈로그 브리지(`APP_HOME` 허용 목록)와 라우터 브리지(`ownsShell`)를 넣고
동기화마다 병합한다. tech-log는 라우터를 PUBLIC/STUDIO 그룹 라우터로 통째로
바꿔 생성기 설치 경로(context gateway)를 쓰지 못한다.

고른 방법: 리뷰 4.3의 (B). 선언 두 개를 연다.
- 홈 대체: 플랫폼이 기능이 대신할 수 있는 라우트 id를 선언한다
  (`FEATURE_REPLACEABLE_PLATFORM_ROUTE_IDS = ["APP_HOME"]`,
  src/contracts/routes.ts). 그 id를 선언한 기능의 정의가 플랫폼 정의를
  대신한다. 둘이 선언하면 카탈로그를 읽을 때 두 기능 id를 담아 throw한다
  (`withoutTakenOverPlatformRoutes`). 다른 플랫폼 id는 지금처럼 중복 오류다.
  라우터는 대체된 라우트를 소유 context와 함께 그 경로에 붙인다.
- context 레이아웃: `BoundedContextRouteModule.loadLayout`(선택). 생성기는
  `src/contexts/<context>/context-layout.tsx`가 있으면 그 `CONTEXT_LAYOUT`을
  지연 import로 싣는다. 라우터는 그 context를 `AppShell` 형제인 `/` 레이아웃
  라우트 아래, 기능의 등록 경로마다 붙인다. 그래서 모르는 URL은 여전히
  `AppShell`의 NOT_FOUND로 간다. 선언이 없으면 지금처럼 `AppShell` 아래 루트에
  붙는다. 레이아웃 청크 실패는 라우트 청크와 같은 reload-once 복구를 받는다.
- 09-06 불변식을 레이아웃으로 넓힌다. 레이아웃 라우트는 모두 `/`의
  형제라서 루트는 레이아웃과 상관없이 그 아래 URL을 가진다. 그래서 기존
  루트 검사가 모든 레이아웃에 걸친다. 한 레이아웃 아래 루트 여럿(같은
  컴포넌트를 싣는 context들)은 허용한다. 대체된 플랫폼 라우트는 라우터가
  경로에 직접 붙이므로 루트 검사에서 뺀다(09-06 재검토 조건).
- tests/unit/product-features.test.ts의 "플랫폼 라우트는 소유자가 없다"
  검사가 대체 가능한 id는 건너뛴다. memento가 고쳤던 템플릿 테스트다.
- `ContextRouteModule`에 `featureIds`가 생겨서, `TEMPLATE_APP_MODULE`을
  손으로 mock하며 필수 필드 `features`를 빼먹은 두 테스트
  (context-route-gateway, context-boundary-diagnostics)에 `features: []`를
  넣었다.

버린 대안:
- (A) 현 상태: 제품마다 브리지를 넣고 동기화마다 병합한다.
- (C) `AppShell` 통째 교체: 레이아웃 그룹이 둘인 tech-log를 담지 못한다.
- 같은 레이아웃을 쓰는 context를 로더 함수로 묶어 레이아웃 라우트 하나에
  모으기: 만들었다가 지웠다. React 19는 같은 컴포넌트로 풀린 lazy 타입을 같은
  타입으로 맞춰 레이아웃 인스턴스를 그대로 둔다. 묶지 않은 변이로 테스트가
  그대로 통과해서 쓸모없는 코드였다.
- `CONTEXT_LAYOUT_ID` 리터럴로 다른 context의 레이아웃을 가리키기: 같은
  컴포넌트를 내보내는 파일 두 개로 같은 결과가 나와 선언을 하나 덜 둔다.
- 레이아웃 라우트를 `AppShell`보다 앞에 두기(memento 브리지 순서): 경로가
  같으면 기능이 플랫폼 라우트를 조용히 가린다. `AppShell`을 앞에 두어
  지금처럼 플랫폼이 이긴다.

위험·한계:
- 레이아웃이 skip link와 `<main id="main-content">` 하나를 그리는 것은
  계약(타입 주석, starter-experience.md)과 테스트 fixture로만 지킨다. 실행 중
  검사는 없다. 레이아웃 로딩·실패 화면에는 `<main>`이 없다(`AppShell`의
  errorElement와 같다).
- 레이아웃 렌더 결함(청크 실패가 아닌 것)은 라우트 errorElement로 가고
  진단을 남기지 않는다. `AppShell` 렌더 결함과 같다.
- 홈을 대신한 기능을 실행 중에 끄면 `/`는 비활성 기능 화면이 된다. 빌드에서
  빼면(`VITE_PRODUCT_FEATURES`) 플랫폼 홈이 돌아온다.
- tech-log의 PUBLIC 셸 안 NOT_FOUND는 표현하지 않는다. 모르는 URL은
  `AppShell`의 NOT_FOUND다. STUDIO의 `/studio/*` 라우트는 STUDIO 레이아웃
  아래에서 동작한다. tech-log는 기능 하나를 레이아웃 그룹별 기능 둘(context
  둘)로 나눠야 한다.
- 플랫폼 라우트와 기능 라우트의 같은 경로는 여전히 검사하지 않는다(7139c7c
  한계). 루트 `*` context에서 `APP_HOME`이 아닌 id로 `/`를 선언하면 플랫폼
  홈에 가려진다.
- 초기 JS gzip +349 B(204,586 -> 204,935 B). 예산 204,800 B를 135 B
  넘는다(이전 여유 214 B). boot 청크 +228(라우터·앱 모듈),
  installed-feature-contracts 청크 +121. 같은 worktree에서 HEAD 파일로
  `vite build`를 한 번 더 해서 청크별로 비교했다. 예산은 고치지 않았다.

검증:
- RED: tests/component/context-layouts.test.tsx는 파일 적재에서
  "Duplicate route registry key: APP_HOME"으로 실패.
  tests/architecture/context-route-roots.test.ts 15건 중 3건 실패(APP_HOME
  루트 예외 "not under the route root", 대체 함수가 없어 2건).
  tests/scripts/generate-product-feature-index.test.ts 새 1건이 HEAD 생성기로
  "expected ... to contain 'loadLayout: async () => (await import…'"로 실패.
- GREEN: 세 파일 37건 통과(생성기 15, 루트 16, context-layouts 6).
- 변이: 라우터가 `loadLayout`을 무시하면 context-layouts 6건 중 5건 실패.
  topics 레이아웃을 다른 컴포넌트로 바꾸면 "keeps one layout instance" 실패.
- 회귀: tests/{architecture,unit,features,platform,component,contract,
  runtime-schema,integration,scripts,scale}(pnpm을 띄우는 4개 제외)
  300 files, 3,451건 통과. check-registries, check-adapter-inventory,
  verify-documentation-readiness(PASS_SCOPED) 통과.
- tsc app·test·node 통과. 바꾼 파일 eslint 통과. 생성기 --check 통과.
- check:architecture는 pnpm이 필요해 돌리지 않았다.

Refs: docs/reviews/2026-11-01-maturity-review/09-app-core.md 09-03, 4.3
2026-11-03 01:52:18 +09:00

Clean Architecture Frontend Template

A React/Vite reference implementation where architecture boundaries, integration behavior, release coherence, accessibility, performance, and operations are executable contracts rather than conventions.

Start locally

Requirements: the exact Node.js version in .nvmrc (currently 24.14.0) and Corepack. The repository pins pnpm in package.json.

Product source, tests, build/quality scripts, and supported tool configuration are TypeScript/TSX. allowJs is disabled. Node-side .ts scripts run directly on the pinned Node 24 runtime and are checked with NodeNext resolution plus erasable-syntax enforcement. Project-owned executable source contains no JavaScript-family files; negative architecture, security, and type-compatibility fixtures are TypeScript/TSX as well.

corepack pnpm install --frozen-lockfile
corepack pnpm dev

Runtime configuration

Runtime-public settings are validated against one schema before the product tree mounts (runtimeConfigV2ArtifactSchema in src/contracts/release-artifacts.ts). Client secrets are forbidden.

The source of truth is config/runtime/<profile>.json, one file per environment: local, development, staging, production. corepack pnpm build writes dist/config.json from the selected profile (scripts/generate-runtime-config.ts). public/config.json is only the local profile for corepack pnpm dev; the build replaces it, so settings put there never reach a deployment. Keep it equal to config/runtime/local.json plus BUILD_ID: local-build and RELEASE_ID: local-release; tests/unit/deployment-admission.test.ts fails when the two differ.

Build and deploy variables, lowest precedence first:

Variable Sets Default
APP_PROFILE which config/runtime/<profile>.json is used local; an empty value fails the build
RUNTIME_API_BASE_URL API_BASE_URL, overriding the profile; the CI workflow cannot pass it (see below) the profile value
RUNTIME_TELEMETRY_ENDPOINT TELEMETRY_ENDPOINT, overriding the profile; the CI workflow cannot pass it (see below) the profile value
VITE_BUILD_ID BUILD_ID in the runtime config and the release manifest local-build
RELEASE_ID RELEASE_ID in the runtime config and the release manifest local-release
RELEASE_TARGET the environment FE-GATE-027 admits the build to; must equal APP_PROFILE none; admission refuses without it

verify:documentation fails if this table stops naming a variable the build or admission reads (scripts/verify-documentation-readiness.ts).

Only the two RUNTIME_* values can differ from the reviewed profile. Anything else changes by editing the profile file. Staging and production reject demo auth, non-HTTPS endpoints and the names reserved for examples and tests (example.com, example.net, example.org and their subdomains, .example, .invalid, .test). The shipped staging and production profiles use *.example.com, so admission refuses them until a project sets its own endpoints.

In CI the only way to set the endpoints is to commit them to config/runtime/<profile>.json. The CI contract binds just APP_PROFILE and RELEASE_TARGET to the build job (scripts/contracts/ci-gates.ts), so a RUNTIME_* repository variable never reaches the build.

A local production build and its admission check:

APP_PROFILE=production \
RUNTIME_API_BASE_URL=<your-api-origin>/ \
RUNTIME_TELEMETRY_ENDPOINT=<your-telemetry-endpoint> \
VITE_BUILD_ID=<unique build id> RELEASE_ID=<unique release id> \
corepack pnpm build
APP_PROFILE=production RELEASE_TARGET=production corepack pnpm check:release-admission

With CI=true the gate runner (corepack pnpm ci:gate) also requires VITE_COMMIT_SHA, SOURCE_DATE_EPOCH and CI_RUNNER_IMAGE before it runs a gate (scripts/lib/build-environment.ts, scripts/run-ci-gate.ts). The CI variable list is in docs/operations/ci-quality-gates.md.

Included starter experience

The default build mounts a domain-neutral application shell with a header, responsive sidebar, route focus management, session integration status, a persistent system / light / dark theme selector, and a language selector.

The route list is ROUTE_REGISTRY (src/features/installed-feature-contracts.ts): the platform routes of src/contracts/routes.ts plus the routes of every installed feature, the removable reference feature included. The platform overview page (/examples/platform) shows the composed list at runtime, so this README keeps no copy of it and adding a feature does not edit it.

AUTH_MODE=demo is credential-free and accepted only in local/development environments. Deployments use AUTH_MODE=external and provide the opaque auth owner described in docs/architecture/starter-experience.md. The client route policy is user experience only; server authorization remains authoritative.

Support scope

Four tiers. The status words on the right are the ones the catalogs and design documents use; the next table maps them.

Tier What it covers Status words
Default In the default build and covered by the merge gates: the application shell and example routes, the REST HTTP executor, TanStack Query server state, Local/Session Storage registries, cross-tab invalidation, runtime config profiles and the release manifest check, AUTH_MODE=external (demo only in local/development), the typed message catalog, and the removable reference feature. dist/ is served by a static host (docs/architecture/static-delivery.md) COMPOSED
Optional (recipe) Not installed. A project copies one of the recipes in config/recipes/frontend-capability-recipes.json and narrows it (docs/architecture/optional-adapter-recipes.md). realtime, offline-indexeddb, service-worker-pwa and file-transfer also ship a tested reference runtime that the default build leaves out RECIPE_AVAILABLE, NOT_INSTALLED, AVAILABLE_NOT_COMPOSED
Experimental Designed and decided, but the runtime is missing or unfinished; finish it before building on it. GraphQL, gRPC-Web, Connect-Web and Protobuf adapters, Range resumable download, IndexedDB query persistence, the local preview decode-safety probe. src/features/local-draft-feature is an architecture sample, not installed DESIGNED_NOT_IMPLEMENTED
Not supported Deliberately not selected, or browsers cannot guarantee it: SSR, app-managed background upload and download, directory selection, persistent file handles, product query persistence, exactly-once delivery between tabs NOT_SELECTED, PLATFORM_LIMITED

The rows come from docs/architecture/browser-data-capability-completion-ledger.md, docs/architecture/client-cache-and-storage.md and docs/architecture/api-contract-schema-mapper-and-server-state.md.

Status word Where it appears Meaning Tier
COMPOSED capability ledger, design documents wired into the default production path Default
INSTALLED a project's own recipe catalog (step 10 of the recipe procedure) the project added the recipe Default, for that project
RECIPE_AVAILABLE recipe catalog status a recipe exists to copy; nothing is installed Optional
NOT_INSTALLED recipe catalog defaultStatus; a src/features/<id>/NOT_INSTALLED marker file not part of the build Optional (recipe) or Experimental (feature)
AVAILABLE_NOT_COMPOSED capability ledger; recipe referenceRuntime.status code and tests exist; the default build leaves it out Optional
DESIGNED_NOT_IMPLEMENTED capability ledger, design documents design approved, runtime missing Experimental
NOT_SELECTED capability ledger, design documents deliberately not chosen Not supported
PLATFORM_LIMITED capability ledger browsers cannot guarantee it; offered only behind a probe and a fallback, if at all Not supported as a guarantee

Gate results (PASS, PASS_SCOPED, UNVERIFIED, FAIL_UNVERIFIED) are verdicts on evidence, not support tiers.

Browsers: the build targets Chrome and Edge 111, Firefox 128, and Safari and iOS 16.4. That is the higher of Vite 8's default JavaScript target (baseline-widely-available; vite.config.ts sets no build.target) and the CSS targets of Tailwind CSS 4. There is no browserslist. The end-to-end suite runs on the desktop Chromium, Firefox and WebKit builds that Playwright 1.62 pins, plus one Chromium phone-size smoke (playwright.config.ts). Older versions inside the target range and real mobile browsers are not tested.

Architecture

This repository is a Frontend Application Foundation: a starter/composition skeleton plus a reusable capability platform. Platform capabilities stay horizontal while product business features use vertical slices.

src/ has nine top-level folders. The descriptions match the table in docs/architecture/layers.md, which also names every import rule:

  • src/bootstrap — the composition root: runtime configuration, concrete adapter construction and the React mount
  • src/apps — deployable apps: each app-module.ts declares an app and its context budget; template-app.ts is the app this build produces
  • src/contexts — bounded contexts: each context-module.ts declares its app, route root and feature budget
  • src/features — removable vertical slices (src/features/<id>/{domain,application,contracts,adapters,presentation}) and the installed-feature catalogs (src/features/*.ts)
  • src/presentation — generic UI and the inbound adapter: routes, layouts, the design system, pages and providers
  • src/adapters — reusable capability runtimes that implement application ports: HTTP, auth, storage, query cache, telemetry, workers and more
  • src/application — generic use cases, ports, policies and view-models
  • src/contracts — shared vocabulary and registries read by several layers, the workers and the build and release scripts
  • src/platform — product-neutral primitives any folder may use: budgets, execution context, resilience, the telemetry pipeline, error envelopes and release coherence

Dependencies point inward. Every folder may also import contracts and platform:

presentation -> application -> contracts -> platform
adapters -----^
bootstrap composes concrete adapters
apps -> contexts -> features   (an app deploys contexts; a context owns features)
feature use case -> feature port <- feature-owned capability binding

Domain code lives inside each feature; there is no top-level domain folder.

See docs/architecture/frontend-application-foundation.md, docs/architecture/overview.md, docs/architecture/layers.md, and docs/architecture/starter-experience.md. The removable vertical slice is under src/features/reference-feature; its domain, application input, HTTP binding, contracts, route runtime, and presentation own their contributions. The central installed catalogs only aggregate selected contributions. The generic starter routes continue to typecheck, test, and build after that feature is removed.

Platform capability review

The starter shell is implemented, but the repository review also records the remaining work required before feature teams can use every declared contract through one end-to-end application path:

These documents distinguish repository defaults from opt-in adapters and project-owned integrations. They are target designs and review findings; a capability is not treated as implemented until its branch acceptance criteria and executable gates pass.

Documentation

docs/README.md sorts the documents into current contracts, target designs and work history.

Files you can delete after copying

These record how the template was built. Nothing in the build or the gates reads them, except the one file noted below (tests/unit/deletable-history-documents.test.ts checks this).

Path Contents
docs/superpowers/ past plans and specs
docs/reviews/ reviews and the review guide. Keep docs/reviews/adapters/INVENTORY.md: check:adapter-inventory (FE-GATE-010) reads it
SPEC.md, tasks/ requirements and task list of the 2026-09-25 review fix round
CLAUDE.md review instructions for the template repository itself; replace it with your own
PRODUCT.md product context of the template itself (users, purpose, principles) for design tools; replace it with your product's

The reference feature is not in this list: deleting its directory alone leaves tests, policy entries and CI scripts behind that fail the gates. scripts/test-sample-removal.ts removes it from a copy of the repository and lists everything that has to go with it (its header comment and SAMPLE_EXTRAS); do the same in your project and run the gates.

Verification

Common local checks:

corepack pnpm lint
corepack pnpm check:types
corepack pnpm check:types:app
corepack pnpm check:types:node
corepack pnpm check:types:test
corepack pnpm check:architecture
corepack pnpm test:all
corepack pnpm test:contract
corepack pnpm test:e2e
corepack pnpm test:a11y
corepack pnpm build
corepack pnpm check:bundle
corepack pnpm test:performance
corepack pnpm verify:compatibility
corepack pnpm verify:release
corepack pnpm check:registries
corepack pnpm drill:runbooks
corepack pnpm check:ci

drill:runbooks stops at the first drill that is not PASS. Without provider evidence every drill ends UNVERIFIED (exit 3), because a drill never reports a check it could not run locally as PASS; see "Runbook jobs" in docs/operations/ci-quality-gates.md.

test:all is the ordinary product-development loop and intentionally excludes host-level CI-runner assurance. Run corepack pnpm test:system only on the compatible Linux assurance host described in docs/testing/taxonomy.md.

check:types는 source, Node scripts/config와 tests를 분리된 TypeScript project로 모두 검사한다. type/architecture/security/registry의 invalid fixture는 config/ci/gates.json에서 “실패해야 통과”하는 negative gate로 실행된다. 도구 호환성 결정은 VD-01에 기록돼 있다.

Application feature input은 module augmentation으로 닫힌 ID와 정확한 input shape를 제공하며, 공통 Result<Value, Failure = AppFailure>는 error registry의 failure kind만 application/presentation 경계를 통과시킨다. Architecture gate는 TypeScript/TSX의 static, dynamic, type import를 별도 정적 그래프로 분석하고 runtime/source 영역의 JavaScript 재유입도 거절한다. 해석되지 않은 import, parse failure, 금지 계층 edge와 순환 의존은 모두 fail-closed이며 전용 TypeScript/TSX negative fixture로도 검증된다.

Install the pinned Playwright browser engines before the first cross-browser run:

corepack pnpm exec playwright install --with-deps chromium firefox webkit

Two gates intentionally need external evidence:

  • review:a11y-manual (release gate FE-GATE-028) needs a signed human keyboard/focus/screen-reader review of every registered route, one record per route at artifacts/tests/a11y-manual/<ROUTE_ID>.md. The routes are ROUTE_REGISTRY; verify:documentation fails, naming the route ID, when a registered route has no record. The merge gate FE-GATE-009 runs only review:a11y-manual -- --format-only, which checks that every route record keeps the template's fields, reviewed or still pending.
  • collect:web-vitals-evidence stays FAIL_UNVERIFIED until a reviewed minimum eligible-sample threshold and 28 days of production data exist.

Live hosting verification (FE-GATE-019, production stage) requires HOSTING_BASE_URL and the promoted release deployed by the workflow's deployment job. That job is an empty slot until the project fills it (docs/operations/ci-quality-gates.md); until then the result is UNVERIFIED, not PASS. A host serving another release fails.

CI and evidence

The gate registry is config/ci/gates.json; the Gitea workflow is .gitea/workflows/quality-gates.yml. It follows:

MERGE_READY -> RELEASE_READY -> PROD_PROMOTION_READY -> FIELD_SLO_READY

DOCUMENTATION_READY is independent. No gate is downgraded to a warning.

The workflow runs on pull requests, pushes to main and develop, and v* tags. The Git host of this repository may not have Actions enabled, so a pull request can show no gate status at all; no status is not a pass. Until the host runs the workflow and marks the merge gates as required checks, run the 13 merge gates locally before merging (FE-GATE-008 and 009 need Playwright browsers):

for gate in 001 002 003 004 005 006 007 008 009 010 011 013 020; do
  corepack pnpm ci:gate -- "FE-GATE-$gate" || break
done

Machine-readable evidence is written below artifacts/; generated evidence is ignored by Git while .gitkeep files preserve the taxonomy.

Operational details are in docs/operations/, with incident procedures in docs/runbooks/.

Updating a copied project

Template versions are Git tags vX.Y.Z. CHANGELOG.md lists the changes between tags, marks security fixes [보안] and contract changes [계약] (backend, deployment, CI or feature code must change too), and names the affected paths.

Record where you started. Right after copying, commit a one-line .template-origin file at the root of your project with the template tag (or commit) you copied and the date, for example v0.2.0 2026-09-26.

Take a template fix with Git. cherry-pick works even when your repository does not share the template's history, because it merges against the picked commit's parent:

git remote add template <template repository URL>
git fetch template --tags
git log --oneline <your origin>..template/main   # what changed since you copied
git cherry-pick -x <commit>                      # one fix; -x records its origin

When the files have moved or diverged too far for a clean pick, read the change as a diff and apply it by hand:

git diff <commit>^ <commit> -- <paths from CHANGELOG>

Afterwards run the local merge gates from "CI and evidence", apply the backend or deployment change a [계약] row names, and update .template-origin once you have caught up to a tag. git revert undoes a pick.

Defects: if a problem reproduces on an unmodified checkout of your .template-origin commit, it is a template defect. Report it on the template repository with that commit and the reproduction; the template maintainer classifies it and ships the fix with a CHANGELOG entry. A problem that needs your changes to reproduce belongs to your project, and applying a template fix to your copy is your project's job.

S
Description
No description provided
Readme
20 MiB
Languages
TypeScript 98.2%
Python 1%
CSS 0.5%
Shell 0.3%