Overview
apps/cms is the dedicated home for Tuturuuu CMS. It should feel like a
consumer-grade site editing product for nontechnical editors, even though it
continues to use the existing external-project implementation contracts behind
the scenes.
- It owns the CMS UI, routing, workspace picker, and root-level
/{wsId}/projectslinking console. - It remains a satellite frontend with mixed API ownership: CMS-local handlers
own root administration and commerce integration, while the larger
external-project content API remains in
apps/web. - Unmatched CMS
/api/*traffic falls back toapps/web; an exact local route is served byapps/cmsbefore that fallback is considered.
Product Vocabulary
Normal CMS product UI should use editor-friendly terms: site, site template, connection, content, section, URL path, custom details, media, publishing, preview, and team access. Avoid exposing implementation terms such as external project, canonical, adapter, binding, slug, schema, metadata, profile data, payload, or JSON in the primary UI. When staff genuinely need exact implementation values, place them behind a collapsed “Developer details” or internal root-console advanced panel. Code, database names, API paths, tests, and operational docs can keep the existingexternal-project* names so route and data contracts remain stable.
Routing
/{wsId}: overview/{wsId}/games: game-focused content library, visible only when CMS Games is enabled/{wsId}/landing: landing-page builder for hero/profile/page-section edits/{wsId}/library: content operations library for non-landing, non-game content/{wsId}/library/entries/{entryId}: compatibility redirect that opens the library fullscreen editor dialog/{wsId}/library/collections/{collectionId}: collection detail/{wsId}/members: workspace member and role management/{wsId}/preview: delivered-content preview/{wsId}/settings: legacy compatibility redirect to/{wsId}/members/internal/projects: internal site-template registry and workspace linking console/play/{wsId}/webgl/{assetId}: public WebGL package player. This route does not require a CMS login, but the proxied WebGL asset API still only serves the package when the owning CMS entry is published. WebGL player iframes must stay sandboxed withoutallow-same-origin.
wsId resolves to the internal/root workspace, /{wsId} and other workspace-local routes should bounce to /internal/projects instead of trying to render the bound-workspace CMS surfaces.
The previous /{wsId}/content, /{wsId}/collections/..., and /{wsId}/admin CMS routes are removed. New entry points should link directly to the CMS-native route map above.
Access Model
- Only workspaces with CMS access enabled appear in the CMS workspace picker.
- A workspace must still satisfy the existing external-project permissions to open CMS workspace routes.
- CMS Games is disabled by default for every workspace. Enable it from the CMS settings dialog, which writes
ENABLE_CMS_GAMES=trueto workspace configs and reveals the/{wsId}/gamessidebar route. - Only platform admins can open
/internal/projects. - Workspace member and role management lives on
/{wsId}/members. Member and role reads requiremanage_external_projects; editor access alone cannot load people, invites, roles, or default permissions. Write paths still respect member and role management permissions.
Studio enablement and canonical projects
Product decision: enabling External Project Studio for a workspace and creating or changingcanonical_external_projects rows are root platform-admin
actions.
- Scope: the root linking console, the root admin external-project routes,
and
POST /api/v1/workspaces/{wsId}/external-projects/setup. - Default: a workspace does not have the studio until a root
external-project admin (
manage_external_projectsormanage_workspace_rolesin the root workspace) binds it. Every binding a root admin creates through setup writes the sameworkspace_external_project_binding_auditsrow as the linking console. - Workspace managers: creators, admins, and holders of workspace-level
manage_external_projectsmanage content, collections, and sync inside a studio that is already enabled. They cannot run setup, enable the studio for their own workspace, or change shared canonical project metadata; setup returns403for them, including through CMS sessions and app tokens. - Linked apps: a linked app authenticating with its app credentials may call setup only for the studio it is already bound to. Setup then refreshes that workspace’s field definitions and template only; it never creates a binding or creates or alters a canonical project.
- Regression coverage:
apps/web/src/lib/external-projects/studio-setup.test.tsandapps/web/src/app/api/v1/workspaces/[wsId]/external-projects/setup/route.test.ts.
Mobile CMS visibility
Product decision: the mobile app shows CMS only in workspaces whose studio is enabled, so an unavailable studio is never a resting error screen.- Scope: the mobile Apps launcher, rail and sidebar, Apps hub search, and
/cmsdeep links. - Default: hidden until access resolves. The app probes
GET /api/v1/workspaces/{wsId}/external-projects/summary. A200shows CMS. A404(“External project studio unavailable for this workspace”) or a plain403hides it. MFA and verification challenges,401, and transient failures keep the previous answer. Each workspace entry shows the stored answer, then revalidates with the server. - Deep links:
/cmsstays open while access is loading and falls back to Apps once access resolves as unavailable. If the page itself receives the404, it shows a neutral “CMS isn’t enabled” state with an Open Apps action and asks the gate to re-check. - Intentional exception: the summary route requires
managemode, and so does every mobile CMS action (summary, collections and entry edits). Members with onlyedit_external_projectsorpublish_external_projectstherefore see CMS on web but not on mobile, until mobile supports editor-only workflows. - Regression coverage:
apps/mobile/test/features/cms/cubit/cms_access_test.dartandapps/mobile/test/features/cms/view/cms_workspace_test.dart.
API Ownership
apps/cmsowns host-local auth/session and build-info routes. It also owns the root administration handlers for external-project audits, bindings, and project templates under/api/v1/admin/*, plus commerce overview, insights, products, and storefront under/api/v1/commerce/*.- The workspace external-project families for content models, collections,
entries, blocks, assets, publishing and delivery, sync, and CMS-aware team
access remain in
apps/web. Requests with no CMS-local handler reach them through the fallback/api/:path*rewrite. - Keep clients on typed
@tuturuuu/internal-apihelpers. Browser calls should stay same-origin so local routes win and fallback routes are forwarded; request-scoped server calls must preserve forwarded authentication. - CMS-local protected handlers resolve the CMS app-session actor and then apply
getCmsWorkspaceAccessor the root-admin gate. Forwarded Web handlers still require the coordinated Web-issued session and enforce their own workspace permissions; the proxy guard is not a replacement for route authorization. - The rewrite target must resolve to the central web app, not the CMS app origin. Prefer
INTERNAL_WEB_API_ORIGIN,NEXT_PUBLIC_WEB_APP_URL, orWEB_APP_URLfor the central origin. If a deployment-levelNEXT_PUBLIC_APP_URLpoints atcms.tuturuuu.comor the current CMS Vercel preview URL, the CMS config ignores it and falls back tohttps://tuturuuu.comto avoid self-rewriting/api/*requests. - Add new behavior to the host that owns its route family. Extend the CMS-local
admin or commerce handler for those families; extend the Web-owned
external-project handler for content, media, publishing, sync, or team
behavior, and expose shared access through
packages/internal-api. - The root linking console reads the workspace-indexed binding summary from the
CMS-local
GET /api/v1/admin/external-project-bindingshandler. - On the central Web API, a verified CLI session can bind or unbind a workspace
through
PATCH /api/v1/admin/external-project-bindings/{workspaceId}. SendcanonicalId: nullto unbind. Both browser and CLI paths recheck root permission in Postgres and record the verified actor in the binding audit. Coverage:external-project-bindings/[workspaceId]/route.test.tsandexternal-project-binding-cli-actor.sql. - The root linking console may load its initial server-render payload directly with the request-scoped CMS Supabase admin path after
getCmsWorkspaceAccessproves root admin access. Avoid server-to-server Internal API fetches during that initial render, because production auth/origin forwarding failures turn/internal/projectsinto a hard RSC error page. Keep workspace-secret lookups batched; one.in('ws_id', allWorkspaceIds)query can exceed PostgREST/proxy URL limits and return400 Bad Requestin production. - Backend naming stays on
external-project*contracts even though the product surface is branded as Tuturuuu CMS. - Add or update the CMS product-copy hygiene test whenever new visible CMS strings are introduced. The test should protect the consumer vocabulary while allowing collapsed developer-detail and internal-only exceptions.
Content Model
- Collections remain the content-type container. Field definitions live in
workspace_external_project_field_definitions, while entry values continue to be stored in the existingprofile_dataandmetadataJSON payloads so delivery and sync payloads stay backward-compatible. - Field definitions support the manifest field contract:
string,markdown,number,boolean,date,datetime,json, andstring-array. Scope controls whether the value is saved underprofile_dataormetadata. - The CMS Library has a
Content modelsection with reusable templates for Profile, Blog Posts, Gallery, Shop Products, Writing Worlds, and Social Links. Applying a template creates the collection if needed, stores the collection schema, and creates any missing field definitions without deleting CMS-only fields. - Landing and Library must stay visibly distinct. Landing is a page-builder surface for landing-only sections, preview-first actions, and page readiness. Library is a content operations surface for search, status, bulk publishing, collection health, and non-landing/non-game content. Keep
landing,library, andgamescapability scopes mutually distinct in tests. - The Library command center is the consolidated authoring entry point for content, content models, workflow queues, and settings. Keep new CMS operations reachable from that surface before adding another isolated toolbar or settings panel.
- Entry detail forms render schema-aware controls for the active collection field definitions. Authors should edit those typed controls instead of hand-editing raw
profile_dataormetadataJSON for modeled fields. - Body and asset affordances should be driven by the collection schema when available. Naming heuristics for legacy Yoola collections remain as compatibility fallback only.
- External-project setup and sync import manifest
profileFieldsandmetadataFieldsinto DB field definitions. Sync snapshots are built from DB-managed field definitions, and field removals should only be applied during an explicit destructive sync.
Yashie Bridge
- Yashie is the proof case for the generic content model. Its manifest seeds profile, blog post, gallery, shop product, writing world, and social-link collections and field definitions.
- This phase does not change
../yashieruntime pages. Yashie can be seeded and managed from CMS, but the public Yashie app continues to read its local static data until a later integration pass consumes CMS delivery payloads. - Shop product entries are catalog-only in this phase. No checkout, payment, inventory, or commerce fulfillment behavior is implied by the template.
Client Architecture
- Keep route pages server-side only for auth and access gates, then hand off interactive CMS surfaces to client modules backed by TanStack Query.
- Keep
cms-studio-client.tsxfocused on query state, mutations, and routing. Library rendering should stay split across dedicated gallery, workflow, and settings modules rather than growing back into one large TSX file. - Keep CMS team access clients on
@tuturuuu/internal-apihelpers that target external-project-awareapps/webroutes. Do not call the standard workspace members or roles settings endpoints directly fromapps/cms. - Entry detail now opens as a fullscreen dialog from the library route so the CMS keeps the library cache warm instead of forcing a separate navigation for each entry.
- The Games route reuses the library client with a game-like collection scope and only exposes WebGL ZIP upload controls when
ENABLE_CMS_GAMESis explicitly enabled. - When a user creates the first Games entry, CMS should automatically create the workspace
Gamescollection and then open the new game entry instead of requiring a manual collection setup step. - Published game entries expose a public
/play/{wsId}/webgl/{assetId}link from the WebGL package card. Keep this route login-free in the CMS proxy, and keep publication checks in the centralapps/webWebGL asset route so drafts and archived entries do not leak assets. The player iframe and the served WebGL document must both use sandboxing that allows scripts but does not allow same-origin access. - CMS media uploads show per-file progress for cover images, gallery media, and WebGL ZIP packages. Cover and gallery media must use the external-project asset app-server upload route so Tuturuuu measures the actual bytes before writing storage objects, then store the returned Drive path on the CMS asset row. WebGL ZIP package uploads still upload directly to the signed storage URL returned by the self-hosted web API, then call the WebGL package finalize route so the ZIP can be extracted and mapped to a playable artifact. The WebGL asset-serving route must infer browser content types from the requested WebGL filename for known outputs such as
index.html,.js,.jpg,.wasm,.data, and compressed.gz/.brfiles, because extracted storage metadata can be too generic or incorrectly recorded astext/plain. Served WebGL files must include a CSPsandboxheader that omitsallow-same-origin; served HTML is also adjusted for the CMS player so Unity canvases fill the iframe viewport instead of keeping the default fixed-size template layout, hide the stock Unity footer chrome, resize the canvas backing buffer to the iframe viewport, inject a route-local<base>and artifact-map URL resolver soBuild/*andTemplateData/*load through the same WebGL package API route even when the Unity template creates scripts dynamically, and show in-frame resource download progress when the runtime fetches package assets. - CMS asset delivery must respect the workspace Drive provider. Supabase assets may use signed image transforms, while R2-backed assets should resolve through the workspace storage provider signed-read path and ignore Supabase-only transform parameters.
- CMS asset rows may only store workspace storage paths under
external-projects/; asset delivery and cleanup must not operate on paths from other workspace modules such as Drive or finance. GET /api/v1/workspaces/{wsId}/external-projects/assets/{assetId}redirects to an asset’ssource_urlonly when it is anhttpsURL on the exact platform storage origin (SUPABASE_SERVER_URLor the public Supabase URL; no userinfo, no other port), its path starts with/storage/v1/object/or/storage/v1/render/image/, its path has no encoded/or\(%2F,%5C), and its query has no signed-URLtokenparameter in any letter case. Any othersource_url(another host or path,http,javascript:,data:, protocol-relative oruser@hostforms, signed URLs) is never a redirect target, also for authorized reads of unpublished assets: the route serves the asset’s stored object instead, and returns404only when there is none. Sites that link third-party media readsource_urlfrom the delivery payload, or import the file into workspace storage. Coverage:apps/web/src/lib/external-projects/asset-redirect-policy.test.tsand the route’sroute-source-redirect.test.ts.- CMS does not register the shared offline service worker or emit the shared web app manifest. Its unmatched, Web-owned protected API families fall back to
apps/web, so PWA routes owned byapps/webmust not be advertised fromcms.tuturuuu.com. - Library taxonomy edits should stay lightweight: category/tag assignment, creation, and removal can happen directly from the library dialog, while deeper editorial changes still live in the entry sidebar taxonomy card.
Local Development
- Use
bun dev:cmsto run the CMS app with the shared packages andapps/web. - Use
bun devx:cmsorbun devrs:cmswhen you also need a reset local Supabase environment.
CI/CD
- Production runs on the CMS Cloudflare Worker; Vercel receives no production deploys.
Native Start candidate
The app’s retained App Router pages and layouts are compiled through the shared Start bridge RSC adapter. Generate the native candidate withnode scripts/start-bridge-codemod/cli.mjs cms --apply; rerun the generator
instead of editing marked generated files. bun run --cwd apps/cms type-check:cloudflare checks the native entry and bun run --cwd apps/cms build:cloudflare runs the real Vite+ build on an admitted build host.
The route registry compiles in the RSC environment so server-only imports
retain their boundary. Server actions use the shared bridge action transport
and existing CSRF checks. The router carries the request CSP nonce.
The candidate admits only the canonical CMS root and its explicit staging
hosts from start-bridge.config.ts. Apex /cms and unknown hosts return 404
before application dispatch or network access. Apex stays held until the
shared-session decision and auth guard are admitted; the same artifact can
support a mount after that separate review. This policy is covered by
apps/cms/src/runtime/root-host-policy.test.ts and the emitted Worker gate.
Hosted staging uses <app>.tutur3u.com; workers.dev hosts are not admitted.
Every response is noindex, nofollow and nosnippet. Non-assets force private,
no-store and vary by Cookie, Authorization and Accept-Language; static cache
exemptions require GET/HEAD, status 200 and non-HTML without cookies.
The response wrapper preserves upstream CSP restrictions and denies framing.
Only the exact workspace external-project asset /webgl path and descendants
retain their upstream sandbox CSP unchanged and omit X-Frame-Options. A
handler-level CSP would replace that sandbox, so this app uses the response
wrapper instead. response-policy.test.ts covers both the sandbox exception
and its neighbouring paths, cache overrides, indexing and response preservation.
Production remains on its existing publisher until an explicit cutover-preparation PR. That PR
requires an app-specific enforced CSP policy, exact-source sealed artifact,
runtime and authenticated browser acceptance, and an immediate rollback.
At /cms, middleware relies on Web’s shared Supabase session and does not
refresh, exchange or clear satellite sessions. Legacy session-writing API
endpoints return 409 on that mount; the host-root flow keeps its existing
behavior. Page loaders and API handlers still validate the actor and CMS
permissions. Machine-key APIs retain their ambient-cookie removal and route
authentication. Mounted-session and redirect regressions are covered by
apps/cms/src/proxy.test.ts.
Machine credential binding
Machine synchronization credentials must match the enabled workspace binding. Built-in projects match their registered adapter id; custom projects match the canonical project id. The sharedcustom adapter name grants no project access.
This follows the same identity rule as app-token handoff. Coverage:
apps/web/src/lib/external-projects/app-credentials.test.ts.
Content reads and administrative activity
Workspace external-project read mode accepts the CMS editor permission. Full Studio responses and summaries requiremanage_external_projects because they
include import records and publish audit events. The shared internal API client
requests view=content for Studio content: this read-mode variant returns empty
importJobs and publishEvents arrays, preserving page-builder content access.
Member and role reads require manage access through the team access helper.
Content assets, bound-project storage, collections, entries and field/relation
schemas remain readable by editors. These routes return the workspace’s bound
project content; root binding inventories, secrets and binding audits retain
their separate administrator gates.
The route, method, required permission and returned-data inventory is maintained
in apps/web/src/lib/external-projects/read-route-table.test.ts. Its negative
cases execute administrative GET handlers as an editor and require 403; the
content variant verifies that audit records are absent. This policy applies to
the shared Web API consumed by CMS, including its native migration path.
Public asset publication
An uploaded asset is private until publication records its storage revision. Public delivery and direct asset reads, including WebGL package files, require a published parent and a matching asset revision. Publish records media referenced by the entry’s media slots or by a linked block. An asset changed after publication needs a new publish. Existing published entries can use a matching historical publish snapshot. An entry without publication evidence needs a new publish to expose its media, except an entry last published before publication proofs began (migration20261120141201), including a published import that never recorded a publication time. Such an entry keeps delivering its attached media that has a stored object (or WebGL inventory) and has not changed since its publication, or since proofs began when the entry has no publication time. Editing the entry or replacing its media after that point needs a new publish. Coverage: published-assets-pre-proof.test.ts and the asset route’s route-publication.test.ts.
Published .m4a assets are served inline as audio/mp4. Byte-range requests
receive partial content for playback and seeking. Missing or generic binary
storage metadata resolves to audio/mp4 for the .m4a extension.
Coverage: public-asset-response.test.ts.
The workspace manage-decision endpoint accepts an external app bearer with the exact manage scope. It checks the linked app, current workspace membership, and current workspace-level manage permission on each request. Publish-only grants are denied. Responses are private, and timeouts deny access.