@route-intelligence/core
v2.2.0
Published
Core routing intelligence engine for React applications
Readme
@route-intelligence/core
Graph engine, analysis pipeline, algorithms, and exporters. Framework-agnostic: it never depends on React or Next.js.
You usually get this package transitively via @route-intelligence/cli. Install it directly only when you want to run analysis from your own Node code.
Install
npm install @route-intelligence/coreYou also need at least one framework plugin (for example @route-intelligence/next) and pass it in plugins.
Analyze from code
import { createAnalyzer, exportJson, exportMermaid } from '@route-intelligence/core';
import { NextPlugin } from '@route-intelligence/next';
const analyzer = createAnalyzer({
root: process.cwd(),
plugins: [NextPlugin()],
include: ['app/**', 'pages/**', 'src/**', 'middleware.ts'],
exclude: ['**/node_modules/**', '**/.next/**'],
});
const result = await analyzer.analyze();
console.log(result.metadata.totalRoutes);
console.log(result.diagnostics);
const json = exportJson(result.graph, process.cwd());
const mermaid = exportMermaid(result.graph);Pipeline
createAnalyzer runs a staged pipeline:
- File system scan
- Route discovery (plugins)
- Parse / AST
- Semantic analysis
- Navigation analysis
- Static analysis (dead routes, cycles, broken links)
- Graph build + metrics
Plugins register through PluginRegistry. Active plugins are those whose detect() returns true for the project.
Watch
const watcher = analyzer.watch();
watcher.on('update', (patch) => {
console.log(patch.addedNodes.length, patch.removedNodeIds.length);
});
watcher.on('error', (err) => console.error(err));
await watcher.stop();Uses chokidar plus an incremental cache (default directory .route-intelligence).
Graph API
RouteGraph stores nodes (routes, layouts, middleware, API routes, …) and typed edges (navigation, redirect, layout-parent, prefetch, …).
Algorithms:
findCyclesfindDeadRoutesfindShortestPathdetectInfiniteRedirectsgetMostConnectedcomputeMetrics/metricsToMetadata
Exporters
| Function | Output |
|----------|--------|
| exportJson | Serialized graph JSON |
| exportMermaid | Mermaid flowchart (ELK, left-to-right) |
| exportPlantUML | PlantUML |
| exportDot | Graphviz DOT |
| exportHtml | Standalone HTML report |
| exportMarkdown | Markdown route list |
Config helper
import { defineConfig } from '@route-intelligence/core';
export default defineConfig({
root: '.',
plugins: [],
});Types for AnalyzerConfig, AnalysisResult, Diagnostic, and FrameworkPlugin are re-exported from @route-intelligence/shared.
License
MIT
