Documentation

Docs / Reference

ADR 0077 - Next.js App Router routes, server actions and Supabase table access

Status: Accepted (delegated review, 2026-11-19)

Context

Milestone M5 (item 2) of the project plan adds Next.js App Router route handlers and server actions and the Supabase JS client. The T024 investigation (2026-11-18; the T024 task records (internal)) pinned four corpora (chatbot-ui, ai-chatbot, saas-starter, supabase-stripe) and re-read umami and dokploy with main (extractors-45):

The task draft (internal; its tables are in docs/contract/claims/nextjs-supabase.md) holds the claim contracts (rows NX, SA, SB, each with one default branch D). The developer decided open points O1-O7 on 2026-11-18 (recorded in the task file under "Decisions (developer, 2026-11-18)"); this ADR reflects those decisions.

Options considered and decisions

1. Next.js route paths

Routes are ordinary HTTP route nodes (ADR 0013) with framework: nextjs; the client matcher (ADR 0018) gains them as candidates. Next.js routes are same-origin, so a call with a literal origin never links to one (a precision rule found on dokploy, whose api.porkbun.com calls would otherwise link to /api/[...trpc]). basePath composes as a prefix; an env-dependent basePath leaves the base unresolved. Rewrites and middleware are not applied and the edge says so (assumption NX-V1).

Decided (O2 (a)): Pages Router pages/api/** files are routes too, one ANY route per file (framework: nextjs_pages), only together with the same-origin rule. Decided (O7, revised): linking follows file-system routing with NX-V1 shown on every linked call; next.config literal rewrites (and basePath) are read in the route unit: a call whose path matches a literal rewrite source gets no Next.js candidate of that project (the request may be rewritten elsewhere), and non-literal configuration stays unknown (nextjs_rewrites_unread, base unresolved).

2. Server actions

3. Supabase

4. Oracles

TypeScript 6.0.3 for export names, directives and use resolution; the next path helpers for templates; Supabase migrations replayed into the throwaway PostgreSQL 17 cluster over a platform prelude (scripts/oracle/nextjs_supabase/) for tables; @supabase/postgrest-js's query builder, which builds method and URL without a request, for chain operations. Not cheap, so mapped: basePath evaluation, rewrites, the client module graph, PostgREST embedded-resource resolution.

Implementation notes (T024a, extractors-47)

Implementation notes (T024a2, extractors-48)

T024b implementation notes (2026-11-18, extractors-49)

T024c1 implementation notes (2026-11-18, extractors-51)

T024c1b implementation notes (2026-11-18, extractors-52)

T024c1b R1 notes (2026-11-18, extractors-53)

T024c1c notes (2026-11-18, extractors-55)

T024c2 implementation notes (2026-11-18, extractors-54)

T024c3 implementation notes (2026-11-18, extractors-55)

T024 review fixes (2026-11-18, extractors-56)

Fixes for the T024 task record (internal) (A1, B1-B4, C1-C7), each as a class rule with its contract row, docs and fixture kept 1:1.

NX-F2 notes (2026-11-18, extractors-56)

Coverage recovery after the T024 review fixes, rows SB-M9 and SB-M10 (task table, docs/extract/schema.md "Supabase sets"; code in internal/extract/schema/supabase.go, tests supabase_nxf2_test.go). T024c1c (LANGUAGE sql bodies, SB-M8) was merged first; its fixture migration became 20240106000000_sql_functions.sql, because the review's 20240105000000_archive.sql already held its version (the Supabase CLI keys migrations by version).

NX-G notes (2026-11-18, gate preparation)

Follow-ups B5 and C8 of the T024 review's confirmation pass.

NX-S notes (stacked gate on T023, T022 and T026; extractors-49)

Consequences

Known gaps

Interception routes, middleware and proxy files, non-literal rewrites, redirects and headers, rewrite chains and rewrites a call may match only unprovably (withheld, not re-routed), pages and public/ files at a rewritten call's path (assumption NX-V3), Pages Router pages, i18n prefixes, app wrappers returned from hooks (umami useApi), Playwright request calls, actions passed through props, .rpc, storage, auth and realtime calls, embedded resources without a single foreign key proof, Supabase access with neither a migration set nor generated types in the package, generated-types relationships as foreign keys and their TypeScript types as Postgres types (T024c3), the boundary of direct action calls outside the client module graph, server imports the module resolver cannot resolve (a shared module could then read client), one server graph for the whole repository (a dynamic import in one application makes every application's client labels unknown), and escaped Supabase builders whose verb use is elsewhere (builder_unread), a Next.js application divided by a member's link scopes as a project link target (TOP-1 of 2026-11-18) and server actions on the architecture map (T026 draws neither exposes_action nor calls_action).

Open points

None open: O1-O7 were decided by the developer on 2026-11-18 (task file, "Decisions (developer, 2026-11-18)"). Steps: T024a routes, pages/api, rewrites and basePath, client links; T024b server actions; T024c1 Supabase migration sets with RLS; T024c2 Supabase table access with embeds; T024c3 generated types.

Acceptance notes (2026-11-19)

Report a problem with this pageSource: docs/adr/0077-nextjs-and-supabase.md