next-route-graph 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/CONTRIBUTING.md +74 -0
  3. package/README.md +113 -189
  4. package/SECURITY.md +19 -0
  5. package/dist/cli.js +107 -80
  6. package/dist/core/analyzer.d.ts +5 -1
  7. package/dist/core/analyzer.d.ts.map +1 -1
  8. package/dist/core/analyzer.js +21 -14
  9. package/dist/core/inspect.d.ts +6 -0
  10. package/dist/core/inspect.d.ts.map +1 -0
  11. package/dist/core/inspect.js +21 -0
  12. package/dist/core/linter.d.ts.map +1 -1
  13. package/dist/core/linter.js +43 -23
  14. package/dist/core/parser.d.ts.map +1 -1
  15. package/dist/core/parser.js +31 -16
  16. package/dist/errors/index.d.ts +4 -0
  17. package/dist/errors/index.d.ts.map +1 -1
  18. package/dist/errors/index.js +8 -1
  19. package/dist/index.d.ts +4 -2
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +4 -2
  22. package/dist/preview.d.ts +4 -0
  23. package/dist/preview.d.ts.map +1 -0
  24. package/dist/preview.js +25 -0
  25. package/dist/render/dot.d.ts.map +1 -1
  26. package/dist/render/dot.js +25 -47
  27. package/dist/render/graph.d.ts +13 -0
  28. package/dist/render/graph.d.ts.map +1 -0
  29. package/dist/render/graph.js +53 -0
  30. package/dist/render/html.d.ts +8 -0
  31. package/dist/render/html.d.ts.map +1 -0
  32. package/dist/render/html.js +718 -0
  33. package/dist/render/index.d.ts +4 -2
  34. package/dist/render/index.d.ts.map +1 -1
  35. package/dist/render/index.js +10 -3
  36. package/dist/render/mermaid.d.ts.map +1 -1
  37. package/dist/render/mermaid.js +19 -43
  38. package/dist/render/svg.d.ts +8 -0
  39. package/dist/render/svg.d.ts.map +1 -0
  40. package/dist/render/svg.js +76 -0
  41. package/dist/types/index.d.ts +5 -1
  42. package/dist/types/index.d.ts.map +1 -1
  43. package/docs/ARCHITECTURE.md +71 -0
  44. package/docs/NEW_FEATURES.md +16 -0
  45. package/docs/adr/0001-offline-reports-and-shared-route-graph.md +29 -0
  46. package/docs/route-report.png +0 -0
  47. package/package.json +12 -4
package/CHANGELOG.md ADDED
@@ -0,0 +1,95 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ---
9
+
10
+ ## [1.2.0] - 2026-11-10
11
+
12
+ ### Added
13
+ - Offline SVG route maps with intermediate URL segments and source information; available through `--svg`, `--format svg`, and the SDK.
14
+ - A focused HTML explorer with route selection, layout chains, search, endpoint filters, health diagnostics, and downloadable exports.
15
+ - `--output <file>` for every format, including creation of parent directories.
16
+ - `inspectProject()` and immutable `filterRoutes()` SDK helpers, plus a shared `buildRouteGraph()` model for visual exporters.
17
+ - Offline browser regression tests and Windows/Linux CI checks.
18
+
19
+ ### Fixed
20
+ - Interception markers now resolve target URL segments while ignoring route groups and parallel slots.
21
+ - Valid parallel and intercepted views no longer trigger duplicate URL diagnostics. API-only projects do not require UI layouts.
22
+ - Dynamic parameter conflicts are detected even when descendant endpoints differ; static paths remain case-sensitive.
23
+ - File read failures abort with `ERR_FILE_READ` instead of silently producing incomplete metadata.
24
+ - Named HTTP exports use the exported alias and ignore type-only entries.
25
+ - HTML uses escaped markup and text nodes for source data, a restrictive content policy, and spreadsheet-safe CSV cells.
26
+ - Preview binds to `127.0.0.1`, validates ports, handles occupied ports, and serves only the report.
27
+ - Format conflicts and unknown formats fail explicitly. Reports remain available when strict validation fails; status messages use stderr.
28
+ - Mermaid and DOT now share the URL hierarchy, including segments without endpoints; DOT line breaks render correctly.
29
+ - Tests rebuild production artifacts first, preventing stale CLI and SDK tests.
30
+
31
+ ### Changed
32
+ - Indexed layout lookup replaces repeated scans of every discovered file per endpoint.
33
+ - Search updates every endpoint summary count while keeping convention totals and diagnostics project-wide.
34
+ - CLI version is read from package metadata; npm packages include the linked guides, changelog, and report screenshot.
35
+
36
+ ## [1.1.0] - 2026-11-07
37
+
38
+ ### Added
39
+ - **Route Linter & Collision Detection Engine**: Built-in validation rules detecting dynamic segment collisions (`/users/[id]` vs `/users/[slug]`), duplicate URL path conflicts across route groups (`no-duplicate-paths`), conflicting `page.tsx` and `route.ts` handlers, missing root layouts, and unhandled parallel route slots (`@slot`).
40
+ - **Strategy Pattern Renderers**:
41
+ - `MermaidRenderer` (`--mermaid` or `--format mermaid`): Generates Mermaid flowchart diagrams with entity-encoded node shapes.
42
+ - `DotRenderer` (`--dot` or `--format dot`): Generates Graphviz DOT graphs with properly escaped string literals.
43
+ - `MarkdownRenderer` (`--markdown` or `--format markdown`): Generates GitHub-flavored Markdown tables.
44
+ - `HtmlRenderer` (`--html`, `--serve`, or `--format html`): Generates a standalone, zero-dependency interactive visual HTML report with route hierarchy cards, searchable data table, CSV export, integrated tabbed format explorer (Mermaid, DOT, Markdown, ANSI Terminal, JSON, Flat), and built-in local preview server.
45
+ - **Deep HTTP Method & Metadata Inspection**: Automatically detects exported HTTP handlers (`GET`, `POST`, `PUT`, `DELETE`, etc.) in `route.ts`, React Server Actions (`"use server"`), and route segment configurations (`runtime`, `dynamic`).
46
+ - **Programmatic TypeScript SDK**: Exported root module `dist/index.js` with TypeScript type declarations (`dist/index.d.ts`) and `"exports"` map, enabling library usage via `import { analyzeRoutes } from 'next-route-graph'`.
47
+ - **Domain Error Hierarchy**: Structured error classes (`ProjectNotFoundError`, `AmbiguousRouterError`, `NoAppRouterError`, `RouteLintError`) with machine-readable codes and actionable hints.
48
+ - **New CLI Commands & Flags**:
49
+ - `next-route-graph check`: Run route linting checks with exit codes.
50
+ - `--strict`: Fails with non-zero exit code if route issues or collisions are detected.
51
+ - `--format <tree|flat|json|mermaid|dot|markdown|html>`: Flexible format selector.
52
+ - `--html [file]`: Export self-contained interactive HTML report (defaults to `route-graph.html`).
53
+ - `--serve [port]`: Spin up zero-dependency local HTTP preview server (defaults to port 3000) and open in default browser.
54
+ - **Comprehensive Automated Test Suite**: Expanded test coverage from 9 to 50 unit and integration tests, including end-to-end Next.js project fixtures, CLI subprocess tests, scanner edge cases, linter edge cases, external SDK consumer verification, and HTML report validation.
55
+ - **Documentation & Governance Suite**: Added `docs/ARCHITECTURE.md`, `docs/adr/0001-hybrid-parsing-and-strategy-renderers.md`, `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md`, and `SECURITY.md`.
56
+
57
+ ### Fixed
58
+ - **Private Folders**: Ignored Next.js private folders (`_folder`, e.g. `_components`, `_lib`) and hidden directories during route discovery so internal components are not treated as public routes.
59
+ - **Multiple Root Layouts**: Added support for Multiple Root Layouts partitioned within top-level route groups (e.g. `app/(marketing)/layout.tsx` and `app/(shop)/layout.tsx`), eliminating false-positive `require-root-layout` errors.
60
+ - **Intercepting Routes**: Fixed regex in `parseRoutePath` and `extractRouteMetadata` to match multi-level intercepting tokens `(..)(..)` before single-level `(..)`.
61
+ - **Directive Truncation**: Replaced 500-character slice heuristic with a prologue parser (`getPrologueDirectives`), fixing missed `"use client"` / `"use server"` directives in files with long license headers.
62
+ - **Comment-Stripped Extraction**: Stripped comments before extracting HTTP methods, Server Actions, and route configs to prevent commented-out code (e.g. `// export function GET()`) from being reported.
63
+ - **Renderer Escaping**:
64
+ - Escaped backslashes before double quotes in Graphviz DOT output.
65
+ - Entity-encoded square brackets (`#91;`, `#93;`) in Mermaid labels to prevent broken node shape syntax.
66
+ - Escaped pipe characters (`\|`) in Markdown table cells.
67
+
68
+ ### Performance
69
+ - **Reduced Disk I/O**: Reduced filesystem reads by 66% in `analyzer.ts` by reading each file once into memory and caching parsed metadata.
70
+ - **Deterministic Route Ordering**: Implemented composite multi-level sorting (`path`, then `file`) guaranteeing consistent output across operating systems.
71
+
72
+ ### Changed
73
+ - Refactored `analyzer.ts` into a decoupled pipeline supporting layout hierarchy tracking and slot resolution.
74
+ - Enriched `AnalysisResult` and `SummaryStats` with API route, parallel route, and interceptor counts.
75
+ - Enabled direct path execution in `detectAppRouter` when targeting `app/` or `src/app/` directly.
76
+ - Decoded Next.js `%5F` prefix syntax to underscores in URL routes (e.g. `%5Fprivate` ➔ `/_private`).
77
+ - Aligned route tree columns dynamically based on the longest route path in the project.
78
+ - Fixed nested markdown code blocks in `README.md`.
79
+
80
+ ---
81
+
82
+ ## [1.0.2] - 2026-09-13
83
+
84
+ ### Changed
85
+ - Improved rendering performance and CLI tree layout formatting.
86
+
87
+ ---
88
+
89
+ ## [1.0.0] - 2026-09-05
90
+
91
+ ### Added
92
+ - Initial release of `next-route-graph`.
93
+ - Support for static, dynamic, catch-all, and optional catch-all route detection.
94
+ - App Router directory auto-discovery (`app` and `src/app`).
95
+ - Basic tree, flat, and JSON output formats.
@@ -0,0 +1,74 @@
1
+ # Contributing to next-route-graph
2
+
3
+ Thank you for your interest in contributing! We welcome bug reports, documentation improvements, new renderers, and feature contributions.
4
+
5
+ ---
6
+
7
+ ## Development Setup
8
+
9
+ 1. **Prerequisites**:
10
+ * Node.js >= 18.0.0
11
+ * npm >= 9.0.0
12
+ * Node.js >= 20 for the optional browser tests
13
+
14
+ 2. **Clone and Install**:
15
+ ```bash
16
+ git clone https://github.com/Nima-sltn/next-route-graph.git
17
+ cd next-route-graph
18
+ npm install
19
+ ```
20
+
21
+ 3. **Running the Development CLI**:
22
+ ```bash
23
+ npm run dev -- [path-to-nextjs-app]
24
+ ```
25
+
26
+ ---
27
+
28
+ ## Quality Checks & Testing
29
+
30
+ Before submitting a Pull Request, ensure all tests, type checks, and builds pass:
31
+
32
+ ```bash
33
+ # Run unit tests
34
+ npm test
35
+
36
+ # Run TypeScript type check
37
+ npm run typecheck
38
+
39
+ # Build the project
40
+ npm run build
41
+
42
+ # Exercise the offline HTML report in Chromium
43
+ npx playwright install chromium
44
+ npm run test:browser
45
+
46
+ # Run the complete pre-publish verification suite
47
+ npm run prepublishOnly
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Project Structure
53
+
54
+ * `src/cli.ts` - Command line interface definition and options.
55
+ * `src/index.ts` - Programmatic public SDK entry point.
56
+ * `src/core/detector.ts` - App Router root directory detection.
57
+ * `src/core/scanner.ts` - File discovery and directory traversal.
58
+ * `src/core/parser.ts` - Directive detection, HTTP method parsing, and URL resolution.
59
+ * `src/core/linter.ts` - Route collision and framework best practice validation.
60
+ * `src/core/analyzer.ts` - Core analysis orchestrator and indexed layout lookup.
61
+ * `src/core/inspect.ts` - Shared CLI/SDK scan entry point and immutable filtering.
62
+ * `src/render/` - Text, SVG, and offline HTML renderers with a shared URL graph.
63
+ * `src/preview.ts` - Loopback-only static report serving.
64
+ * `src/errors/` - Domain error classes and actionable hints.
65
+ * `tests/` - Node.js built-in unit/integration tests and Playwright browser checks.
66
+
67
+ ---
68
+
69
+ ## Pull Request Guidelines
70
+
71
+ 1. Create a descriptive branch name (e.g. `feature/openapi-export` or `fix/parallel-routes`).
72
+ 2. Add unit tests for any new functionality in `tests/`.
73
+ 3. Follow existing code conventions and maintain explicit TypeScript types.
74
+ 4. Update `README.md` and `CHANGELOG.md` when introducing user-facing changes.
package/README.md CHANGED
@@ -1,245 +1,169 @@
1
1
  # next-route-graph
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/next-route-graph.svg?color=blue&style=flat-square)](https://www.npmjs.com/package/next-route-graph)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?style=flat-square)](https://opensource.org/licenses/MIT)
5
- [![Node](https://img.shields.io/badge/node-%3E%3D18-brightgreen.svg?style=flat-square)](https://nodejs.org)
6
- [![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org)
7
- [![Tests](https://img.shields.io/badge/tests-47%20passed-success?style=flat-square)](https://github.com/Nima-sltn/next-route-graph)
3
+ [![npm version](https://img.shields.io/npm/v/next-route-graph.svg)](https://www.npmjs.com/package/next-route-graph)
4
+ [![CI](https://github.com/Nima-sltn/next-route-graph/actions/workflows/ci.yml/badge.svg)](https://github.com/Nima-sltn/next-route-graph/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
8
6
 
9
- > Inspect, lint, and visualize the structure of your Next.js App Router project from the terminal or programmatic TypeScript SDK.
7
+ Inspect, lint, and visualize a Next.js App Router project without starting Next.js or executing its code. Use the terminal for quick inspection, an offline HTML report for exploration, and SVG for a diagram you can share anywhere.
10
8
 
11
- `next-route-graph` is a lightweight, zero-config CLI and SDK that scans your `app/` or `src/app/` directory and turns your routing architecture into a clear visual overview.
12
-
13
- Useful for auditing large codebases, preventing route collisions in CI/CD, onboarding developers, generating README diagrams, or supplying structured context to AI coding assistants.
14
-
15
- ---
16
-
17
- ## ✨ Features
18
-
19
- - **Route Discovery**: Identifies static, dynamic (`[slug]`), catch-all (`[...slug]`), and optional catch-all (`[[...slug]]`) routes.
20
- - **App Router Special Conventions**: Full detection of `page`, `layout`, `loading`, `error`, `not-found`, `template`, `default`, and `route` files.
21
- - **Deep HTTP Method Detection**: Inspects `route.ts` API handlers to extract supported methods (`GET`, `POST`, `PUT`, `DELETE`, etc.).
22
- - **Route Linter & Collision Detection**: Catches dynamic parameter collisions (e.g. `/users/[id]` vs `/users/[slug]`), missing root layouts, page/route conflicts, and parallel route slot fallbacks.
23
- - **Multiple Output Formats**: Styled terminal tree, flat list, JSON, **Mermaid flowchart**, **Graphviz DOT**, and **Markdown table**.
24
- - **Programmatic TypeScript SDK**: Use directly in Node.js scripts, build pipelines, or devtools with full type definitions.
25
- - **Fast & Zero-Config**: Runs in milliseconds without starting a Next.js server, bundler, or runtime.
9
+ ```sh
10
+ npx next-route-graph ./my-app
11
+ npx next-route-graph ./my-app --html reports/routes.html
12
+ npx next-route-graph ./my-app --svg --output reports/routes.svg
13
+ ```
26
14
 
27
- ---
15
+ Version **1.2.0** adds rendered SVG exports, an offline HTML explorer, and shared CLI/SDK scanning. See the [changelog](CHANGELOG.md) for details.
28
16
 
29
- ## 🚀 Installation & Quick Start
17
+ ![Offline route map with parallel endpoint details](docs/route-report.png)
30
18
 
31
- Run instantly with `npx`:
19
+ ## What it tells you
32
20
 
33
- ```bash
34
- npx next-route-graph
35
- ```
21
+ - Public URL paths, dynamic segments, route groups, parallel slots, and intercepted targets.
22
+ - Page and API handler source files, declared HTTP methods, client directives, Server Actions, and literal segment configuration.
23
+ - Layout chains from the outermost layout to each endpoint.
24
+ - Route collisions, missing page layouts, page/handler conflicts, slot fallback warnings, and misplaced global error files.
36
25
 
37
- Or install globally:
26
+ Private folders and build/dependency directories are excluded. Routes are sorted for consistent output. All exports work without a Next.js server.
38
27
 
39
- ```bash
40
- npm install -g next-route-graph
41
- ```
28
+ ## Install
42
29
 
43
- Or add as a development dependency:
30
+ Requires Node.js 18 or newer. Run with `npx`, or install in your project:
44
31
 
45
- ```bash
32
+ ```sh
46
33
  npm install -D next-route-graph
47
34
  ```
48
35
 
49
- ---
50
-
51
- ## 🖥️ CLI Usage
36
+ ## Explore visually
52
37
 
53
- ### Basic Tree Overview
38
+ ```sh
39
+ # Standalone report; opens directly from disk and works offline
40
+ npx next-route-graph ./my-app --html reports/routes.html
54
41
 
55
- Run from the root of your Next.js project:
42
+ # Local static snapshot; visit the printed URL (default port 3000)
43
+ npx next-route-graph ./my-app --serve
56
44
 
57
- ```bash
58
- npx next-route-graph
45
+ # Choose a port, or 0 to choose an available port
46
+ npx next-route-graph ./my-app --serve 4300
59
47
  ```
60
48
 
61
- Analyze a specific project directory:
62
-
63
- ```bash
64
- npx next-route-graph ./path/to/my-next-app
65
- ```
66
-
67
- Example terminal output:
68
-
69
- ```text
70
- next-route-graph
71
-
72
- Project my-next-app
73
- Router App Router
74
- Root src/app
75
-
76
- Routes
77
- ────────────────────────────────────────
78
- ├── / page.tsx
79
- ├── /about page.tsx [client]
80
- ├── /blog page.tsx
81
- ├── /blog/[slug] page.tsx [dynamic]
82
- ├── /dashboard page.tsx [@analytics]
83
- └── /api/users route.ts [GET, POST]
84
-
85
- Summary
86
- ────────────────────────────────────────
87
- Routes 6
88
- Dynamic 1
89
- Client 1
90
- Server 5
91
- Layouts 2
92
- Loading 1
93
- Errors 1
94
- API Routes 1
95
- Parallel 1
96
-
97
- ✓ Analysis completed in 8ms
98
- ```
99
-
100
- ---
101
-
102
- ## 🛡️ Route Health & Linting (`check`)
103
-
104
- Run route validation checks to detect conflicts, broken parallel slots, or missing layouts before deploying:
49
+ The report has four sections:
105
50
 
106
- ```bash
107
- # Check routes and display issues
108
- npx next-route-graph check
51
+ | Section | Purpose |
52
+ | --- | --- |
53
+ | Route map | Rendered SVG hierarchy, including segments without endpoints. Select a node with a mouse or keyboard to inspect every source and its layout chain. |
54
+ | Routes | Search paths, source files, methods, or layouts; filter pages, handlers, rendering declarations, dynamic routes, slots, or interceptions. Download matching rows as CSV. |
55
+ | Health | Project-wide diagnostics with rule names, locations, and actionable hints. |
56
+ | Exports | Download SVG, Mermaid, DOT, Markdown, JSON, flat paths, or a plain terminal tree. One selector keeps the interface compact. |
109
57
 
110
- # Strict mode: exits with code 1 if errors or collisions are discovered (ideal for CI)
111
- npx next-route-graph check --strict
112
- ```
113
-
114
- ---
58
+ Multiple sources at one URL remain inspectable. Map filtering dims unrelated branches and retains ancestors for context. Report downloads contain all endpoints included in the report; CSV uses the current browser filter.
115
59
 
116
- ## 📊 Output Formats (Strategy Pattern)
60
+ SVG is a real vector image. Mermaid and Graphviz DOT are source formats for their respective renderers; they do not need to render in your terminal. The HTML map renders directly without a CDN or a graph library. The preview server binds only to `127.0.0.1` and serves the in-memory report. Rerun the command to refresh its snapshot.
117
61
 
118
- Select any format with `--format <type>` or dedicated flags:
62
+ ## Export and automate
119
63
 
120
- ### 1. Mermaid Flowchart (`--mermaid`)
121
- Generate a Mermaid flowchart diagram to paste directly into GitHub READMEs, PRs, or Notion:
64
+ Choose one format flag, or use `--format`. `--output` works for every format and creates missing parent directories. File-write notices go to stderr; stdout remains suitable for pipes.
122
65
 
123
- ```bash
124
- npx next-route-graph --mermaid
125
- ```
66
+ | Format | Flag | Use |
67
+ | --- | --- | --- |
68
+ | Terminal tree | Default / `--format tree` | Quick overview and lint summary |
69
+ | Flat paths | `--flat` | Shell pipelines |
70
+ | JSON | `--json` | SDK consumers, build tools, or AI context |
71
+ | SVG | `--svg` | Rendered image for reports and design tools |
72
+ | HTML | `--html [file]` / `--format html` | Offline interactive report |
73
+ | Mermaid | `--mermaid` | Fenced diagram for Markdown documentation |
74
+ | Graphviz DOT | `--dot` | Graphviz processing |
75
+ | Markdown | `--markdown` | Documentation table |
126
76
 
127
- ```mermaid
128
- flowchart TD
129
- %% Next.js Route Graph
130
- root["/"]
131
- route_1["/about (client)"]
132
- route_2["/api/users (GET/POST)"]
133
- root --> route_1
134
- root --> route_2
135
- ```
77
+ ```sh
78
+ npx next-route-graph ./my-app --json --output reports/routes.json
79
+ npx next-route-graph ./my-app --mermaid --output reports/routes.md
80
+ npx next-route-graph ./my-app --dot --output reports/routes.dot
81
+ dot -Tsvg reports/routes.dot -o reports/graphviz.svg
136
82
 
137
- ### 2. Graphviz DOT (`--dot`)
138
- Output standard Graphviz DOT notation for visual pipelines and rendering tools:
83
+ # Stream HTML instead of writing a report file
84
+ npx next-route-graph ./my-app --format html > routes.html
139
85
 
140
- ```bash
141
- npx next-route-graph --dot > routes.dot
86
+ # Case-insensitive filtering by path, file, or HTTP method
87
+ npx next-route-graph ./my-app --search POST --json
142
88
  ```
143
89
 
144
- ### 3. Markdown Table (`--markdown`)
145
- Generate a clean Markdown summary table:
90
+ `--search` changes endpoint counts in the report; layout/loading/error-file totals and diagnostics still describe the whole project. A filtered export cannot hide a CI failure. Use `--output -` to explicitly write to stdout. `--html` defaults to `route-graph.html`.
146
91
 
147
- ```bash
148
- npx next-route-graph --markdown
149
- ```
92
+ ## Validate in CI
150
93
 
151
- ### 4. JSON (`--json`)
152
- Output machine-readable JSON for CI integration, custom tooling, or AI agents:
94
+ ```sh
95
+ npx next-route-graph check ./my-app
96
+ npx next-route-graph check ./my-app --strict --json
153
97
 
154
- ```bash
155
- npx next-route-graph --json
98
+ # Save a reviewable artifact even if validation fails
99
+ npx next-route-graph ./my-app --strict --format html --output reports/routes.html
156
100
  ```
157
101
 
158
- ### 5. Flat Paths (`--flat`)
159
- Output only newline-separated URL paths:
102
+ | Command | Exit 1 when |
103
+ | --- | --- |
104
+ | Default scan | Scanning or output fails |
105
+ | `check` / `--check` | Scanning fails or lint errors exist |
106
+ | `--strict` | Scanning fails or lint errors or warnings exist |
160
107
 
161
- ```bash
162
- npx next-route-graph --flat
163
- ```
108
+ JSON scan errors are written as `{ "error": "…", "code": "…" }` to stderr. Successful report data is written to stdout or the requested file. Invalid options also fail. A strict file export is written before lint determines the exit code.
164
109
 
165
- ### 6. Route Filtering (`--search`)
166
- Filter routes matching a specific substring:
110
+ Example GitHub Actions step after installing your project's dependencies:
167
111
 
168
- ```bash
169
- npx next-route-graph --search blog
112
+ ```yaml
113
+ - name: Check routing and generate a report
114
+ run: npx next-route-graph . --strict --format html --output reports/routes.html
115
+ - name: Save report
116
+ if: always()
117
+ uses: actions/upload-artifact@v4
118
+ with:
119
+ name: route-report
120
+ path: reports/routes.html
170
121
  ```
171
122
 
172
- ---
173
-
174
- ## 📦 Programmatic TypeScript SDK
123
+ ## TypeScript SDK
175
124
 
176
- `next-route-graph` exports a complete, fully-typed programmatic API:
125
+ ```ts
126
+ import { inspectProject, filterRoutes, getRenderer } from "next-route-graph";
127
+ import { writeFile } from "node:fs/promises";
177
128
 
178
- ```typescript
179
- import {
180
- detectAppRouter,
181
- scanAppDir,
182
- analyzeRoutes,
183
- lintRoutes,
184
- getRenderer,
185
- } from "next-route-graph";
129
+ const result = await inspectProject("./my-app");
130
+ await writeFile("routes.html", getRenderer("html").render(result));
131
+ await writeFile("routes.svg", getRenderer("svg").render(result));
186
132
 
187
- // 1. Detect App Router root
188
- const { appDir, displayRoot } = detectAppRouter("./my-next-app");
189
-
190
- // 2. Discover files
191
- const files = await scanAppDir(appDir);
133
+ const api = filterRoutes(result, "api/"); // returns a new result
134
+ console.log(api.summary.apiRoutes);
135
+ if (result.lint?.hasErrors) process.exitCode = 1;
136
+ ```
192
137
 
193
- // 3. Analyze routes, HTTP methods, and layouts
194
- const result = await analyzeRoutes(files, "./my-next-app", displayRoot);
138
+ The lower-level `detectAppRouter()`, `scanAppDir()`, `analyzeRoutes()`, and `lintRoutes()` APIs remain available. `buildRouteGraph(result.routes)` exposes URL nodes with stable IDs within an export, parent IDs, depth, and all endpoint sources attached to each node. `getRenderer()` rejects unknown formats. See [architecture](docs/ARCHITECTURE.md) for module boundaries.
195
139
 
196
- console.log(`Found ${result.summary.routes} routes`);
140
+ ## Scope and limitations
197
141
 
198
- // 4. Render output via Strategy Pattern
199
- const mermaidOutput = getRenderer("mermaid").render(result);
200
- console.log(mermaidOutput);
142
+ This is static **App Router** source inspection, not a replacement for `next build`. Pages Router, metadata-generated endpoints, custom `pageExtensions`, rewrites, redirects, middleware/proxy behavior, and imports are not evaluated. Source extraction uses comment-aware text parsing, not an AST or TypeScript evaluation; computed exports, complex string contents, and re-export chains can be incomplete. Detected HTTP methods are declared methods, not Next.js-generated methods.
201
143
 
202
- // 5. Run route lint checks programmatically
203
- const lint = lintRoutes(result.routes, files);
204
- if (lint.hasErrors) {
205
- console.error("Route validation failed:", lint.issues);
206
- }
207
- ```
144
+ “Server” means the file has no top-level `use client` directive. It does not prove static generation, caching, SSR behavior, or imported component boundaries. Runtime and dynamic configuration show local literal declarations, not inherited effective values. The URL graph describes structure; its edges do not imply imports, navigation links, or layout inheritance. Layout inheritance appears separately in the details panel.
208
145
 
209
- ---
146
+ Diagnostics intentionally cover a small set of routing conventions. Parallel fallback warnings flag potentially unmatched navigation; the tool does not simulate navigation. Share exported reports with the same care as source filenames and internal endpoint names: they contain those names and detected metadata, but never source file contents.
210
147
 
211
- ## 🤖 CI/CD Integration (GitHub Actions)
148
+ Framework references: [intercepting routes](https://nextjs.org/docs/app/api-reference/file-conventions/intercepting-routes), [parallel routes](https://nextjs.org/docs/app/api-reference/file-conventions/parallel-routes), and [layouts](https://nextjs.org/docs/app/api-reference/file-conventions/layout).
212
149
 
213
- Add a route validation check to your GitHub Actions pull request workflow:
150
+ ## Development
214
151
 
215
- ```yaml
216
- name: Route Verification
217
- on: [pull_request]
218
-
219
- jobs:
220
- check-routes:
221
- runs-on: ubuntu-latest
222
- steps:
223
- - uses: actions/checkout@v4
224
- - uses: actions/setup-node@v4
225
- with:
226
- node-version: 20
227
- - run: npm ci
228
- - name: Lint Next.js Routes
229
- run: npx next-route-graph check --strict
152
+ ```sh
153
+ npm ci
154
+ npm run typecheck
155
+ npm test # builds first; unit, CLI, SDK, and HTTP integration tests
156
+ npx playwright install chromium
157
+ npm run test:browser # builds first; real offline browser workflow
230
158
  ```
231
159
 
232
- ---
233
-
234
- ## 🏛️ Architecture & Documentation
235
-
236
- - [Architecture Guide](docs/ARCHITECTURE.md) - Pipeline design, data structures, and component diagram.
237
- - [Architectural Decision Records (ADRs)](docs/adr/0001-hybrid-parsing-and-strategy-renderers.md) - Technical decisions and trade-offs.
238
- - [Contributing Guide](CONTRIBUTING.md) - How to run tests and contribute.
239
- - [Changelog](CHANGELOG.md) - Release history and version notes.
240
-
241
- ---
160
+ Browser development tests require Node.js 20 or newer. To use installed Chrome in PowerShell: `$env:PLAYWRIGHT_CHROMIUM_CHANNEL='chrome'`. Set `NRG_REPORT_ARTIFACT_DIR=reports` to save the example HTML and desktop/mobile screenshots during browser tests.
242
161
 
243
- ## 📄 License
162
+ - [Contributing](CONTRIBUTING.md)
163
+ - [Architecture and trade-offs](docs/ARCHITECTURE.md)
164
+ - [Architecture decision](docs/adr/0001-offline-reports-and-shared-route-graph.md)
165
+ - [Improvement evidence](docs/NEW_FEATURES.md)
166
+ - [Changelog](CHANGELOG.md)
167
+ - [Security](SECURITY.md)
244
168
 
245
- [MIT](LICENSE) © 2026 [Nima Soltanian](https://github.com/Nima-sltn)
169
+ [MIT](LICENSE) © 2026 Nima Soltanian
package/SECURITY.md ADDED
@@ -0,0 +1,19 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | ------------------ |
7
+ | 1.2.x | :white_check_mark: |
8
+ | 1.1.x | :white_check_mark: |
9
+ | 1.0.x | :x: |
10
+
11
+ ## Reporting a Vulnerability
12
+
13
+ If you discover a security vulnerability in `next-route-graph`, please report it responsibly:
14
+
15
+ 1. **Do not open a public GitHub issue.**
16
+ 2. Send an email to the repository maintainer or open a private security advisory through GitHub.
17
+ 3. Include detailed steps to reproduce the issue along with a minimal reproduction project if possible.
18
+
19
+ You will receive an acknowledgment within 48 hours, followed by updates on the timeline for a patch.