Skip to content

[Next.js] Add App Router route resolver #95

Description

@theDakshJaitly

Target branch: code-graph-preview

Dependency

The TypeScript and JavaScript extractors are already available on code-graph-preview. No language-extractor issue blocks this resolver.

Goal

Add a bounded Next.js resolver for App Router route handlers. The first version should translate file-based route modules into route nodes and connect exported HTTP handler functions without attempting to model the full Next.js routing system.

Scope

  • Detect Next.js through next in dependencies or dev dependencies.
  • Recognize app/**/route.ts and app/**/route.js, including projects using src/app/.
  • Recognize exported GET, POST, PUT, PATCH, DELETE, OPTIONS, and HEAD handler functions.
  • Derive a route path from the directory containing the route file.
  • Preserve dynamic segment text such as [id] in the first version.
  • Emit one route node per exported HTTP handler and a reference to that handler function.
  • Resolve each route to the corresponding same-file function when unambiguous.

Required changes

  • Add src/graph/resolution/frameworks/nextjs.ts implementing FrameworkResolver.
  • Register and export it from src/graph/resolution/frameworks/index.ts.
  • Add minimal App Router fixtures for TypeScript and JavaScript.
  • Add focused detection, path derivation, extraction, resolution, and ambiguity tests.

Acceptance criteria

  • Positive and negative Next.js detection are tested.
  • Both app/ and src/app/ roots are covered.
  • Tests cover multiple HTTP methods, a nested static path, and a dynamic segment.
  • Route nodes use stable ids and the source file's language id.
  • Only explicitly exported HTTP handler names create route nodes.
  • Missing or ambiguous handler functions remain unresolved.
  • The resolver is additive and does not change the frozen interface.
  • npm run typecheck, npm test, and npm run build pass.

Out of scope

  • Pages Router API routes.
  • Route groups, parallel routes, intercepting routes, rewrites, redirects, or middleware.
  • React Server Components, server actions, page components, or layouts.
  • Runtime Next.js configuration evaluation.
  • Changes to the TypeScript/JavaScript extractors or graph core.

Contributor references

Contributor workflow

git switch code-graph-preview
git pull
git switch -c feat/nextjs-app-router-resolver

Open the pull request with base branch code-graph-preview.

Metadata

Metadata

Assignees

No one assigned

    Labels

    code-graphWork related to the AST and Tree-sitter code graphdeveloper-previewPart of an unreleased developer previewhelp wantedExtra attention is needed

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions