Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- **SvelteKit and Nuxt server endpoints are on the map:** a SvelteKit `+server.ts` and a Nuxt file under `server/api/` or `server/routes/` answer a URL by where they sit in the folder, but the map showed none of them, so the website's requests to them weren't connected. They now show up: one endpoint per exported method in SvelteKit, the method from a `.get.` / `.post.` suffix on the file name in Nuxt (or `ANY` without one), route groups `(…)` and parallel slots `@…` skipped, `[param]` as `:param` and `[...rest]` as `*`. A Nuxt file without `defineEventHandler` is left alone. Fixed by @ryoaonetsuki in #138.

## 0.11.0 (2026-11-16)

- **Serverless Framework endpoints are on the map:** a backend whose endpoints are declared in `serverless.yml` rather than in code showed none, so the website's requests to it weren't connected and Health skipped its sign-in check. Endpoints now come from each function's `http` and `httpApi` events (`path` and `method`, `any` and `*`, and the short `http: GET /orders` form) in `serverless.yml`, `serverless-*.yml` and `serverless_*.yml`, including function lists split across files included with `${file(./functions.yml)}`. Each endpoint sits in the file its `handler:` names (`src/orders.create` is `create` in `src/orders.ts`), followed through a file that re-exports it, or into another file's function when the handler only passes the request on to it (`(event) => withEvent(event, options, orders.create)`). Health counts an `authorizer`, `private: true` (an API key) or a sign-in check handed to the wrapper as protecting an endpoint, and still reads the handler for a check of its own. CloudFormation tags (`!Ref`, `!GetAtt`, `!Sub`), `${opt:…}` and `${self:…}` variables and anchors are read without trouble, and the scan summary lists schedules, queues, streams and other background functions for a worker node. Sample configs in test folders add no endpoints. Reported and fixed by @ShehanEk in #131 and #132.
Expand Down
1 change: 1 addition & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ The tests use Node's built-in test runner, so there's nothing to install (`npm t
| `swift.test.mjs` | Swift: module imports and the top-level types, functions and values a file uses, through `Package.swift` targets (custom `path:`, nested and commented-out targets) or an Xcode app with no package, a name in the file's own module winning over an imported one, what must stay unlinked (nested and private declarations, a module nothing is used from, test helpers), and files built to slow the reading down |
| `subpath-imports.test.mjs` | imports through package.json `"imports"` (`#lib/x`): the nearest package.json, the most specific key, arrays and conditions, falling back to tsconfig `paths`, near misses left unlinked, and odd or endlessly nested shapes that must not stop the scan |
| `fastify.test.mjs` | Fastify: plugins registered with a prefix, nested registers, and the website's requests reaching the right plugin (sample in `fixtures/`) |
| `server-routes.test.mjs` | SvelteKit `+server.ts` and Nuxt `server/api|routes` endpoints, derived from the file path: one endpoint per exported method, the method from a file-name suffix in Nuxt, route groups and parallel slots skipped, `[param]` / `[...rest]` / `[[optional]]`, a Nuxt file without `defineEventHandler` left alone, and the website's requests reaching both |
| `fastify-route-options.test.mjs` | Fastify routes declared as objects (`app.route({ method, url, handler })`): method lists, keys inside `schema` left alone, a method or url that isn't written out skipped, routers with any name the file made, a non-router's `route()` left alone, and the website's requests reaching them |
| `nestjs.test.mjs` | NestJS: endpoints from `@Controller` and `@Get`/`@Post`… decorators with their full path and method name, several controllers and other classes in one file, decorators outside a NestJS file left alone, the website's requests reaching the right controller, and Health reading `@UseGuards`, `@Public()` and an app-wide guard (`APP_GUARD`, `useGlobalGuards`) for Nest routes only, with look-alikes that must not count (rate limits, a guard on the next class) (sample in `fixtures/`) |
| `route-tables.test.mjs` | endpoints listed as data: `{ method, path, handle }` objects with a plain path or a regular expression (captures as parameters, groups of words expanded, odd patterns dropped rather than widened), `Bun.serve({ routes })`, a website's list of its own requests left alone (`action`, `resolve` or `fetch` count only in a file that serves), Fastify route objects counted once, and Health still reading the Express routes beside a table (sample in `fixtures/`) |
Expand Down
2 changes: 1 addition & 1 deletion docs/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Supported languages: TypeScript and JavaScript (including Vue, Svelte and Astro

The most useful lines on the map connect a screen's web requests to the server code that answers them, often across repos. Floorplan:

- **Finds endpoints** in Express, Fastify (plugin prefixes included), Koa, Hono, NestJS (controller decorators), Next.js (route files and API routes), Firebase Cloud Functions, Flask, FastAPI, Django, Go (net/http, Gin, Echo, chi, Fiber), Actix, Axum, Spring and ASP.NET Core (attribute-routed controllers, conventional routes from `MapControllerRoute`, minimal APIs and SignalR hubs), and in route tables: keyed by method and path (`"GET /api/orders": listOrders`) in JavaScript and Python, listed as `{ method, path, handle }` objects (the path may be a regular expression) in JavaScript, and `Bun.serve({ routes })`.
- **Finds endpoints** in Express, Fastify (plugin prefixes included), Koa, Hono, NestJS (controller decorators), Next.js (route files and API routes), SvelteKit (`+server.ts`) and Nuxt (`server/api` and `server/routes`), Firebase Cloud Functions, Flask, FastAPI, Django, Go (net/http, Gin, Echo, chi, Fiber), Actix, Axum, Spring and ASP.NET Core (attribute-routed controllers, conventional routes from `MapControllerRoute`, minimal APIs and SignalR hubs), and in route tables: keyed by method and path (`"GET /api/orders": listOrders`) in JavaScript and Python, listed as `{ method, path, handle }` objects (the path may be a regular expression) in JavaScript, and `Bun.serve({ routes })`.
- **Resolves prefixes**: Flask blueprints registered with a `url_prefix`, and Express and Hono routers mounted with `app.use('/api/users', usersRouter)` or `app.route('/api', api)`, whatever the router is called, including routers mounted inside other routers (in the same file or another), routers passed on by an index file (`export { default as authRoutes } from './auth.routes.js'`) or made by a function (`app.use('/billing', createBillingRoutes())`), and mounts with middleware in front; ASP.NET Core `[Route]` prefixes on controllers (a subclass's prefix for actions it inherits) and `MapGroup` prefixes on minimal APIs, including groups an endpoint-mapping extension method is called on from another file.
- **Finds requests** made with `fetch`, axios, ky, `requests`, a SignalR `withUrl(…)` and similar, including:
- addresses built in a variable first: `const url = …; api.get(url)`;
Expand Down
31 changes: 31 additions & 0 deletions skills/floorplan/scripts/lib/extract.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,37 @@ function extractJs(src, filePath) {
const methods = all(/export\s+(?:async\s+)?(?:function|const)\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/g, code).map((m) => m[1]);
for (const method of methods.length ? methods : ['ANY']) routes.push({ method, path: p, var: null, line: 1, framework: 'next' });
}
// SvelteKit server endpoints and Nuxt server endpoints, derived from the file path. A SvelteKit
// `+server.ts` answers the URL of its folder, one endpoint per exported method; a Nuxt file
// under `server/api/` or `server/routes/` answers the matching URL, its method from a `.get.` /
// `.post.` suffix on the file name (or ANY without one), `index` meaning the folder itself.
// Route groups `(…)` and parallel slots `@…` are not part of the URL; `[param]` becomes
// `:param`, `[...rest]` becomes `*`, and `[[optional]]` becomes `:param`.
const fileSeg = (s) => {
if (/^\(.*\)$/.test(s) || s.startsWith('@')) return '';
const rest = /^\[\.\.\.(.+)\]$/.exec(s); if (rest) return '*';
const opt = /^\[\[(.+)\]\]$/.exec(s); if (opt) return ':' + opt[1];
const par = /^\[(.+)\]$/.exec(s); if (par) return ':' + par[1];
return s;
};
const svelte = /(?:^|\/)routes\/((?:[^/]+\/)*)\+server\.(?:t|j)sx?$/.exec(filePath);
if (svelte) {
const p = '/' + (svelte[1] || '').split('/').filter(Boolean).map(fileSeg).filter(Boolean).join('/');
for (const m of all(/export\s+(?:async\s+)?(?:function|const|let|var)\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/g, code)) {
routes.push({ method: m[1], path: p, var: null, line: at(m.index), framework: 'sveltekit' });
}
}
const nuxt = /(?:^|\/)server\/(api|routes)\/((?:[^/]+\/)*)([^/]+)\.(?:ts|js|mjs)$/.exec(filePath);
if (nuxt && /define\w*EventHandler\s*\(/.test(code)) {
const base = nuxt[1] === 'api' ? '/api' : '';
const dirs = (nuxt[2] || '').split('/').filter(Boolean).map(fileSeg);
const mm = /^(.+)\.(get|post|put|patch|delete|head|options)$/i.exec(nuxt[3]);
const last = mm ? mm[1] : nuxt[3];
const segs = [...dirs, ...(last === 'index' ? [] : [fileSeg(last)])].filter(Boolean);
const p = (base + '/' + segs.join('/')).replace(/\/+$/, '') || '/';
const handler = /define\w*EventHandler\s*\(/.exec(code);
routes.push({ method: mm ? mm[2].toUpperCase() : 'ANY', path: p, var: null, line: at(handler.index), framework: 'nuxt' });
}
// Endpoints listed as data: `[{ method: 'GET', path: /^\/api\/items$/, handle: listItems }]` and Bun.serve({ routes })
// (route-tables.mjs). A route object Fastify's reading above already took isn't counted again.
const dataAt = routes.length;
Expand Down
117 changes: 117 additions & 0 deletions tests/server-routes.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// SvelteKit `+server.ts` and Nuxt `server/api|routes` endpoints, derived from the file path.
// SvelteKit answers the URL of its folder, one endpoint per exported method; Nuxt answers the
// matching URL, its method from a `.get.` / `.post.` suffix on the file name. Route groups `(…)` and
// parallel slots `@…` are not part of the URL; `[param]` becomes `:param`, `[...rest]` becomes `*`.
import { test, before, after } from 'node:test';
import assert from 'node:assert/strict';
import { lib, makeProject, run, readGraph, routeKeys, cleanup } from './helpers.mjs';

const { extract } = await lib('extract.mjs');

const kit = (path, body) => extract(body.join('\n'), 'typescript', path);
const routesOf = (r) => r.routes.map((x) => `${x.method} ${x.path}`).sort();

test('SvelteKit: one endpoint per exported method, at the folder URL', () => {
const r = kit('src/routes/api/items/+server.ts', [
`export async function GET() { return new Response('[]'); }`,
`export async function POST() { return new Response('{}'); }`,
`export async function DELETE() { return new Response(''); }`,
]);
assert.deepEqual(routesOf(r), ['DELETE /api/items', 'GET /api/items', 'POST /api/items']);
assert.equal(r.routes[0].framework, 'sveltekit');
});

test('SvelteKit: a group is skipped, a rest segment becomes *, an optional one a parameter', () => {
const r = kit('src/routes/(admin)/settings/+server.ts', [
`export async function GET() { return new Response('[]'); }`,
]);
assert.deepEqual(routesOf(r), ['GET /settings']);
const files = kit('src/routes/api/files/[...path]/+server.ts', [
`export async function GET() { return new Response('[]'); }`,
]);
assert.deepEqual(routesOf(files), ['GET /api/files/*']);
const opt = kit('src/routes/blog/[[slug]]/+server.ts', [
`export const GET = () => new Response('[]');`,
]);
assert.deepEqual(routesOf(opt), ['GET /blog/:slug']);
});

test('SvelteKit: a +server with no exported method, or at the root, declares nothing extra', () => {
const none = kit('src/routes/api/items/+server.ts', [`const helper = () => 1;`]);
assert.deepEqual(routesOf(none), []);
const root = kit('src/routes/+server.ts', [
`export async function GET() { return new Response('[]'); }`,
]);
assert.deepEqual(routesOf(root), ['GET /']);
});

test('Nuxt: the method comes from the file name, index means the folder, [id] a parameter', () => {
const items = kit('server/api/items.ts', [
`export default defineEventHandler((event) => { return []; });`,
]);
assert.deepEqual(routesOf(items), ['ANY /api/items']);
assert.equal(items.routes[0].framework, 'nuxt');
const one = kit('server/api/items/[id].ts', [
`export default defineEventHandler((event) => { return {}; });`,
]);
assert.deepEqual(routesOf(one), ['ANY /api/items/:id']);
const created = kit('server/api/users.post.ts', [
`export default defineEventHandler((event) => { return {}; });`,
]);
assert.deepEqual(routesOf(created), ['POST /api/users']);
const index = kit('server/api/index.ts', [
`export default defineCachedEventHandler((event) => { return []; });`,
]);
assert.deepEqual(routesOf(index), ['ANY /api']);
});

test('Nuxt: server/routes answers the plain URL, and a file without defineEventHandler is left alone', () => {
const health = kit('server/routes/health.ts', [
`export default defineEventHandler((event) => { return { ok: true }; });`,
]);
assert.deepEqual(routesOf(health), ['ANY /health']);
const plain = kit('server/api/notes.ts', [`export const notes = [];`]);
assert.deepEqual(routesOf(plain), []);
});

let root, graph;
before(() => {
root = makeProject({
'kit/package.json': JSON.stringify({ name: 'kit', type: 'module', dependencies: { '@sveltejs/kit': '^2.0.0' } }),
'kit/src/routes/api/items/+server.ts': [
`export async function GET() { return new Response('[]'); }`,
`export async function POST() { return new Response('{}'); }`,
].join('\n'),
'nuxt/package.json': JSON.stringify({ name: 'nuxt', type: 'module', dependencies: { nuxt: '^3.0.0' } }),
'nuxt/server/api/orders.ts': [
`export default defineEventHandler((event) => { return []; });`,
].join('\n'),
'web/package.json': JSON.stringify({ name: 'web', type: 'module' }),
'web/src/api.js': [
`export const listItems = () => fetch('/api/items').then((r) => r.json());`,
`export const listOrders = () => fetch('/api/orders').then((r) => r.json());`,
].join('\n'),
}, {
arch: {
project: { name: 'Shop', summary: 'A shop with SvelteKit and Nuxt backends.' },
nodes: [
{ id: 'kit', label: 'SvelteKit', kind: 'service', summary: 'The SvelteKit server.', paths: ['kit/**'] },
{ id: 'nuxt', label: 'Nuxt', kind: 'service', summary: 'The Nuxt server.', paths: ['nuxt/**'] },
{ id: 'web', label: 'Website', kind: 'ui', summary: 'The website.', paths: ['web/**'] },
],
},
});
run('scan.mjs', root);
run('build.mjs', root, '--no-claude-md');
graph = readGraph(root);
});
after(() => cleanup(root));

test('end to end: both kinds land on the map, and the website reaches them', () => {
assert.deepEqual(routeKeys(graph), ['ANY /api/orders', 'GET /api/items', 'POST /api/items']);
const http = graph.links.filter((l) => l.k === 'http').map((l) => `${l.a.slice(2)} -> ${l.b.slice(2)} ${l.labels.join(', ')}`).sort();
assert.deepEqual(http, [
'web/src/api.js -> kit/src/routes/api/items/+server.ts GET /api/items',
'web/src/api.js -> nuxt/server/api/orders.ts ANY /api/orders',
]);
});