V3 Story: Routes Auditor

Audits router files statically to verify that imports and Express router registrations are correctly mapped.

🚀 Express Auditor 🔎 Verification Checks 📦 Story Builder

1. What

The Routes Auditor Story (V3) acts as a validator for Express routes files. It maps imported router modules against their registrations (via `router.use()`) to flag unused router imports or routes registered without a corresponding import declaration.

2. How

Execution maps the file text in two tracks:

It cross-references variable names between these lists to populate validation fields: importMissInUse (imported but unused) and useMissInImport (registered but not imported).

3. Example

Below is the analysis setup and the resulting comparison object:

Auditor Execution Code

import patternCollector from 'pattern-collector-anyjs';

const story = patternCollector({
  fileContent,
  parseRegex: /import\s*\{[^}]*router\s+as\s+(\w+)[^}]*\}\s*from\s*['"]\.\/([^/]+)\/.*['"]/,
  searchRegex: /^[ \t]*import\b.*from\s+['"]\.[^'"]*['"];/gm
});

Output JSON Mapping

{
  "importLines": [...],
  "useLines": [...],
  "importMissInUse": [
    { "variable": "routerFromv2", "isFound": false }
  ],
  "useMissInImport": [...]
}

🎮 Live Playground

Input your routing code, target search expression, and variable extraction pattern to test route analysis mapping directly inside your browser.

Analysis Story Result (JSON)
Click "Analyze Router Mapping" to see results.

4. Dependency Diagram

The diagram below displays the execution flow through the custom micro-libraries to generate the validation story:

graph TD user_code["routes-auditor.html (V3 Story)"] --> pc_anyjs["pattern-collector-anyjs"] pc_anyjs --> pc_pull_lines["pattern-collector-anyjs-pull-lines"] pc_anyjs --> pc_build_story["pattern-collector-routesjs-build-story"] pc_pull_lines --> pc_import_extract["pattern-collector-anyjs-import-extract"] pc_pull_lines --> pc_use_extract["pattern-collector-routesjs-use-extract"] pc_import_extract --> pc_import["pattern-collector-anyjs-import"] pc_import_extract --> pc_base_regex["pattern-collector-base-regex"] pc_import --> pc["pattern-collector"] pc_use_extract --> pc_use["pattern-collector-routesjs-use"] pc_use --> pc["pattern-collector"] style user_code fill:#1e293b,stroke:#38bdf8,stroke-width:2px,color:#f8fafc style pc fill:#020617,stroke:#818cf8,stroke-width:1px,color:#cbd5e1 style pc_base_regex fill:#020617,stroke:#818cf8,stroke-width:1px,color:#cbd5e1 style pc_build_story fill:#020617,stroke:#818cf8,stroke-width:1px,color:#cbd5e1 classDef default fill:#0f172a,stroke:#334155,color:#f8fafc;