Skip to content

feat(graph): add Next.js App Router route resolver - #179

Open
abhinav-phi wants to merge 1 commit into
mex-memory:mainfrom
abhinav-phi:feat/nextjs-app-router-resolver
Open

feat(graph): add Next.js App Router route resolver#179
abhinav-phi wants to merge 1 commit into
mex-memory:mainfrom
abhinav-phi:feat/nextjs-app-router-resolver

Conversation

@abhinav-phi

Copy link
Copy Markdown
Contributor

Resolves #95.

What

A bounded Next.js resolver following the express.ts/flask.ts pattern. It turns App Router route modules into route nodes and connects exported HTTP handler functions:

  • Recognizes app/**/route.ts and route.js, including src/app roots
  • One stable route node per exported handler for GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD — declared as export async function GET() or export const GET = async () => ...
  • Route path derived from the route file's directory: app/api/users/route.ts/api/users
  • Dynamic segment text ([id]) and catch-alls ([...slug]) preserved verbatim; route groups ((marketing)) excluded from paths the way Next itself resolves them
  • Only explicitly exported HTTP-handler names create route nodes; a same-file helper() export is ignored
  • Detection keys on the next dependency in package.json or the presence of route files in the tree (positive and negative cases tested)
  • Same-file handlers resolve only when unambiguous; missing or duplicate handlers stay unresolved

Out of scope, per the issue: Pages Router, route groups' URL composition nuances, parallel/intercepting routes, rewrites, middleware, server components, and any change to the TypeScript extractor or graph core. No identity, reconciliation, schema, or drift-semantics changes.

Tests

  • resolver-nextjs.test.ts (11): detection positive/negative (manifest and file-based), path derivation for both roots plus route groups/dynamic/catch-all segments and rejection of non-App-Router paths, function and arrow-function exports, JS route files, non-route files ignored, resolution and ambiguity, registry registration.
  • resolver-nextjs-integration.test.ts (1): real rebuildGraph over a Next.js fixture — route nodes persist with the stable nextjs-route identity and both handlers resolve through framework edges.

npm run typecheck, npm run build pass; resolver suites green locally (the pre-existing Windows symlink/WAL failures in test/graph-integration.test.ts reproduce identically on clean main and are unrelated).

Translate file-based route modules into route nodes and connect
exported HTTP handler functions without modeling the full Next.js
routing system.

The resolver recognizes app/**/route.ts|js including src/app roots,
emits one route node per exported HTTP handler (GET through HEAD,
declared as functions or arrow-function consts), and derives the URL
path from the route file's directory. Dynamic segment text such as
[id] and catch-alls such as [...slug] are preserved verbatim; route
groups (marketing) are dropped the way Next itself resolves them.

Detection keys on the next dependency in package.json or the presence
of route files in the tree. Same-file handlers resolve only when
unambiguous; missing or duplicate handlers stay unresolved. Pages
Router, route groups' URL composition, rewrites, middleware, and
server components stay out of scope. No identity, reconciliation,
schema, or drift-semantics changes.

Resolves mex-memory#95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Next.js] Add App Router route resolver

1 participant