Skip to content

Code Scanning

recon scan walks a repository and finds HTTP and RPC routes, the request and response types (DTOs) they use, and the exact file:line of each handler. Use it to see which endpoints your code exposes, to link .http requests to their handlers, and as the input for drift detection.

Run it from the workspace root, or pass a directory:

Terminal window
recon scan
✓ Scanned 4 file(s): 7 route(s), 3 DTO(s) (axum, fastapi, nextjs, openapi)
POST /v2/enrollments [fastapi] py/main.py:10
GET /v1/students [axum] server/src/routes.rs:16
DELETE /v1/students/{id} [axum] server/src/routes.rs:17
GET /v1/students/{id} [axum] server/src/routes.rs:17
GET /admin/stats [axum] server/src/routes.rs:18
GET /v1/courses [openapi] specs/openapi.yaml:6
GET /api/courses/{id} [nextjs] web/app/api/courses/[id]/route.ts:7

This workspace has an axum router in server/src/routes.rs, a FastAPI handler in py/main.py, a Next.js route handler in web/app/api/courses/[id]/route.ts, and an OpenAPI file in specs/openapi.yaml. The axum file contains:

pub fn router() -> Router {
Router::new()
.route("/v1/students", get(list_students))
.route("/v1/students/{id}", get(get_student).delete(delete_student))
.nest("/admin", Router::new().route("/stats", get(stats)))
}

Add --sync to write the handler location into your .http files and to create requests for routes you have not covered yet:

Terminal window
recon scan --sync
✓ Scanned 4 file(s): 7 route(s), 3 DTO(s) (axum, fastapi, nextjs, openapi)
...
Sync: 1 existing updated, 6 new route(s) written

The List Students request matched GET /v1/students, so it gained a # @handler line:

### List Students (PII Airlock + Twin-Run Drift Demo)
### List Students
# @name List Students
# @folder Campus SIS
# @handler server/src/routes.rs:16
# @assert status == 200
# @assert jsonpath $.students[0].program == MDiv
GET {{base_url}}/v1/students

The other six routes went into collections/discovered.http:

### create_enrollment
# @name create_enrollment
# @folder Code (fastapi)
# @handler py/main.py:10
# @assert status in 200..299
POST {{base_url}}/v2/enrollments
Content-Type: application/json
{
"course": "",
"student_id": ""
}
### delete_student
# @name delete_student
# @folder Code (axum)
# @handler server/src/routes.rs:17
# @assert status in 200..299
DELETE {{base_url}}/v1/students/{id}
...

A second recon scan --sync changes nothing:

{"added_new": 0, "modified_files": [], "updated_existing": 0}

Recon walks the directory recursively.

  • It honours .gitignore files in the repository. It does not read your global Git ignore file.
  • Hidden files and directories are included.
  • These directories are always skipped: .git, node_modules, target, dist, build, _build, .recon, vendor, .next, .venv, __pycache__.
  • Files larger than 1,048,576 bytes (1 MiB) are skipped.
  • Files that are not valid UTF-8 are skipped.
  • Files are picked by extension. The match is case-insensitive.
Extensions Scanner
ts, tsx, js, jsx, mts, cts, mjs, cjs TypeScript and JavaScript
py Python
rs Rust
go Go
ex, exs Elixir and Phoenix
rb Ruby and Rails
mo Mo and Arvo
yaml, yml, json, graphql, gql, proto Spec files

files_scanned counts every file with a supported extension that Recon could read, even if it held no routes. Every .json and .yaml file in the tree counts, including capsules and contracts.

After scanning, Recon removes duplicate routes with the same method, path, file and line. Routes are sorted by file, line, path and method. DTOs are sorted by file, line and name.

Every route path is converted to one form so that paths from different frameworks can be compared. The original string is kept in raw_path.

  1. A # fragment and a ? query are removed.
  2. A scheme://host:port prefix is removed.
  3. A leading template variable such as {{base_url}} is removed.
  4. Empty segments are dropped. The result starts with /.
  5. Each segment is converted:
Written as Becomes
[id], [...slug], [[...slug]] {id}, {slug}
<id>, <int:id> {id}
:id, :id(\d+) {id} (text from ( on is dropped)
{id}, {id:int}, {*rest} {id}, {rest}

Two paths match when they have the same number of segments and each pair of segments is equal, or one of them is a {param} or a {{template}} segment. {{base_url}}/v1/students matches /v1/students. /bills/{id}/pay does not match /bills/42.

Files ending in .tsx or .jsx are parsed with the TSX grammar. All other script files use the TypeScript grammar, including .js.

Next.js App Router. A file whose name starts with route. (for example route.ts) and that sits below a directory named app is a route handler. The path is the directories between app and the file. Route groups such as (marketing) are dropped. Each exported function or const named after an HTTP verb (GET, POST and so on) becomes a route with framework nextjs.

Method calls. Any call of the form something.get('/path', handler) becomes a route. This works for get, post, put, patch, delete, del, head and options. The first argument must be a string that starts with / or is empty. The handler name is recorded only when the second argument is a plain identifier. If the file calls .basePath('/prefix'), the first such prefix is added to every route in the file.

The framework label comes from the file contents, checked in this order:

Condition Framework
Contains from 'hono', from "hono" or new Hono hono
Contains fastify or Fastify fastify
Contains express express
Otherwise typescript

Fastify route objects. fastify.route({ method: 'GET', url: '/v1/users' }) becomes a route with framework fastify. path works in place of url.

DTOs. Interfaces, object type aliases and const X = z.object({ ... }) Zod schemas. A field marked ?: or with an optional type is not required. For Zod fields, .optional() or .nullable() makes the field not required. Zod types map to number (or integer with .int()), boolean, array, object, or string for anything else.

Pattern Framework Notes
@x.route("/p", methods=[...]) flask Defaults to GET when methods is absent.
@x.get("/p"), @x.post("/p") and other verbs fastapi
path(...), re_path(...), url(...) django Always GET. The second argument is the handler. Calls containing include( are skipped.

For decorated functions:

  • response_dto comes from a response_model= argument, or else from the return annotation. list[...], List[...] and Optional[...] are unwrapped. Primitive types are ignored.
  • request_dto is the type of the first parameter that is not self, cls, request or req, has no Depends(, and has a non-primitive type starting with an uppercase letter.
  • auth_hint is FastAPI Depends when the parameters contain Depends(.

DTOs are classes that inherit from something containing BaseModel or Schema, and classes decorated with @dataclass. A field is required when it has no default (a default of Field(...) still counts as required) and its type is not optional.

Attribute macros. #[get("/p")], #[post("/p")] and the other verbs, and #[route("/p", method = "GET")], become routes with framework actix. When the macro arguments contain data = or format =, the framework is rocket. The line is the attribute’s line.

axum. Router chains are read inside function bodies.

  • .route("/p", ...) and .route_service("/p", ...) add routes.
  • .nest("/prefix", ...) and .nest_service(...) add a path prefix to the inner router.
  • .merge(...) is followed.
  • Method handlers are recognised as get(h), routing::post(h), the _service and _handler forms, chained calls such as get(a).delete(b), and .to(h).
  • Each method handler becomes its own route, at the line of the handler call.
  • A route with no recognised method handler becomes GET.

DTOs. Structs that are pub or that derive Serialize, Deserialize or JsonSchema, and that have named fields.

  • A field #[serde(rename = "x")] sets the wire name.
  • A struct #[serde(rename_all = "...")] is honoured for camelCase, lowercase and UPPERCASE. Other casings leave names unchanged.
  • Fields with #[serde(skip)] or skip_serializing are left out.
  • A field is not required when its type is Option<...> or its attributes contain default.

The framework comes from the file’s imports: go-chi/chi gives chi, gin-gonic/gin gives gin, labstack/echo gives echo, and anything else gives net/http.

  • Calls such as r.Get("/p", h) or r.GET("/p", h) with a string first argument.
  • HandleFunc and Handle. The pattern may include a method, as in "POST /v1/items". Without one the route is GET.
  • chi r.Route("/prefix", func(r chi.Router) { ... }) nests routes. chi r.Method("GET", "/p", h) is supported.
  • g := r.Group("/prefix") and .With(...) assignments set a prefix for calls on that variable.

DTOs are struct types. The json:"name" tag sets the wire name, json:"-" skips the field, and omitempty or a pointer type makes the field not required.

  • scope "/p" (or scope path: "/p") adds a prefix.
  • pipe_through :api sets auth_hint to pipe_through ... for routes in that scope.
  • get "/p", Controller, :action and the other verbs. The handler is Controller.action.
  • live "/p", ... becomes GET.
  • resources "/items", Controller creates index (GET /items), show (GET /items/:id), create (POST), update (PATCH) and delete (DELETE). only: and except: filter the list. Nested resources use /:{singular}_id, where the singular form drops a trailing s. No PUT, new or edit routes are generated.

DTOs come from Ecto schema "table" and embedded_schema blocks and Ash attributes blocks. An Ecto DTO is named after the table, singularised and in PascalCase (student_records becomes StudentRecord). Without a table name it takes the module name. Only field calls are read, and every Ecto field is marked not required. In Ash, an attribute with allow_nil?: false is required, and uuid_primary_key adds a field.

Every .rb file is scanned with the routes rules.

  • namespace :admin (or path:), scope and draw add prefixes.
  • resources :items creates index, show, create, update (PATCH) and destroy (DELETE). resource :item (singular) has no index, and its item path is the base path. only:, except:, path: and controller: are honoured. The handler is controller#action. Nested resources use /:{singular}_id.
  • match "/p", via: [:get, :post]. Without via: the route is GET.
  • get "/p", to: "c#a" and get "/p" => "c#a".

DTOs are classes with attribute :name, Type calls. A type that contains Optional makes the field not required.

The .mo scanner reads files line by line. ## starts a comment, and so does # outside a quoted string.

  • Inside an api ... end block, lines like get "/path" Handlers.list become routes with framework arvo, at their source line.
  • auth Name sets auth_hint for the following routes. scope "/p" adds a prefix. if, case and for blocks are tracked so that their end lines do not close the api block.
  • struct Name ... end defines a DTO from field: Type lines. Optional types make a field not required.
  • fn and pub fn signatures link handlers to DTOs. The request DTO is a parameter named input, body or payload, or else the first uppercase type that is not in a fixed skip list (Api.Request, Sqlite.Database, SecureRandom, Clock, Env, ReadFiles, Int, Text, Bool, Float, Member, Option(Member), Option(Text), Option(Int)). The response DTO is the first type inside Result(...), unless it is Api.Response or Unit.
  • After all files are read, handlers are linked to DTOs defined in other .mo files. Only DTO names that the scan found are linked.

OpenAPI and Swagger. A YAML or JSON file with a top-level openapi or swagger key. Each path and verb becomes a route with framework openapi. The handler name is the operationId. The request DTO comes from a $ref (or items.$ref) in the application/json request body. The response DTO comes from the 200 or 201 application/json response. The line is the first line in the file that contains the path string. Schemas with properties under components/schemas or definitions become DTOs.

MCP tool manifests. A YAML or JSON file with a top-level tools array. Each tool becomes POST /mcp/{name} with framework mcp.

GraphQL. type, input and extend type blocks. Each field of Query, Mutation or Subscription becomes POST /graphql/{field} with handler Type.field and the field’s return type as response_dto. Other types become DTOs. A ! makes a field required.

Protocol Buffers. rpc Name (Req) returns (Res) inside a service becomes POST /{package.Service}/{Name} with framework protobuf and handler Service.Name. Messages become DTOs. optional makes a field not required. repeated makes it an array.

A YAML or JSON file that does not parse, or that has none of these keys, is skipped without a warning.

Each DTO field has a raw_type (as written) and a logical_type. Optional wrappers such as Option<T>, Optional[T], T | None and T? are removed first. Then the first matching rule applies:

Logical type Matches
array Starts with Vec<, List<, List[, List(, Array< or [], ends with [], or contains repeated
object Starts with HashMap<, BTreeMap<, IndexMap<, Map(, Map[, Dict[ or Record<, or is object, json, value or map
integer i8 to i128, isize, u8 to u128, usize, int, int32, int64, uint32, uint64, sint32, sint64, integer, bigint, smallint, serial
number f32, f64, float, float32, float64, double, decimal, number, numeric
boolean bool, boolean
date date, naivedate
timestamp Contains datetime, timestamp, naive_datetime or utc_datetime, or is time.time
string str, string, text, char, uuid, email, &str, bytes, id, binary_id, or contains string or text
any any, unknown, interface{}
object Anything else, such as a named struct

Matching ignores case.

With --format json or --format agent, the command prints {"scan": ..., "sync": ...}. sync is null without --sync. Keys inside are sorted.

Field Description
root The directory that was scanned.
files_scanned Number of supported files read.
frameworks_detected Sorted, distinct framework labels of the routes found.
routes Array of routes.
dtos Array of DTOs.
warnings Non-fatal problems, such as a parser error in one file.
{
"auth_hint": "FastAPI Depends",
"framework": "fastapi",
"handler_name": "create_enrollment",
"id": "post-v2-enrollments-main:10",
"location": {
"file": "py/main.py",
"line": 10,
"symbol": "create_enrollment"
},
"method": "POST",
"path": "/v2/enrollments",
"raw_path": "/v2/enrollments",
"request_dto": "EnrollmentIn",
"response_dto": "EnrollmentIn"
}
Field Description
id {method}-{path slug}-{file stem}:{line}. The method is lowercase. Non-alphanumeric characters in the path become -. An empty slug becomes root.
method HTTP method.
path Normalised path.
raw_path The path as written in the source.
framework One of axum, actix, rocket, arvo, nextjs, hono, express, fastify, typescript, fastapi, flask, django, chi, gin, echo, net/http, phoenix, rails, openapi, graphql, protobuf, mcp.
location file (relative, with / separators), line (1-based) and optional symbol.
handler_name Handler or action name, when found. Omitted otherwise.
auth_hint Auth or pipeline hint, when found. Omitted otherwise.
request_dto, response_dto DTO names, when found. Omitted otherwise.
{
"fields": [
{
"logical_type": "string",
"name": "student_id",
"raw_type": "str",
"required": true
},
{
"logical_type": "string",
"name": "course",
"raw_type": "str",
"required": true
}
],
"language": "python",
"location": {
"file": "py/main.py",
"line": 4,
"symbol": "EnrollmentIn"
},
"name": "EnrollmentIn"
}

language is one of rust, typescript, python, go, elixir, ruby, mo, openapi, graphql or protobuf.

For each request in the workspace, Recon looks for a matching route:

  1. If the request already has a # @handler tag and a route sits at that exact file:line, that route matches.
  2. Otherwise the first route with the same method and a matching path wins.

When the match gives a different file:line than the request has, Recon sets the tag and counts the request in updated_existing.

Each .http file that holds an updated request is written again in full from the parsed requests. Text that the parser does not keep is lost. In the example above, the free text after ### was replaced by the request name.

Then Recon adds every route that no request covers yet to {collections_dir}/discovered.http. A route is covered when a workspace request or an entry already in discovered.http has the same method and a matching path. Each new request has:

  • A name equal to the handler name, or METHOD path when there is none.
  • A folder Code ({framework}).
  • A # @handler tag.
  • The URL {{base_url}} followed by the normalised path. Path parameters stay as {id}. They are not Recon variables, so you need to edit them before you send the request.
  • The assertion status in 200..299.
  • For POST, PUT, PATCH and DELETE, a sample JSON body when the route has a request_dto that the scan found. Each field gets a placeholder: 1 for integers, 1.0 for numbers, false, [], {}, or "" for anything else. A Content-Type: application/json header is added with the body.

The sync object reports:

Field Description
updated_existing Requests that received a new # @handler tag.
added_new Requests added to discovered.http.
generated_file Path of discovered.http when it was written. Omitted otherwise.
modified_files Every .http file that was written.

The tag has the form # @handler path/to/file.rs:16. The file part is everything before the last :. The line must be a positive integer. Backslashes become /. Recon uses the tag to find the handler when it exports a capsule and when it matches requests during a later sync. See .http Request Files for the full directive list.

Terminal window
recon scan [PATH] [--sync]
Argument Default Description
PATH the --workspace directory Directory to scan.
--sync off Stamp # @handler tags and write discovered.http. Sync always uses the requests of the --workspace workspace, even when PATH points elsewhere.

Human output prints a summary line, one line per route (method, path, [framework], file:line), and a Sync: line when --sync is set.

recon scan exits 0 after a scan. A missing directory is not an error: the scan finds nothing and the reason is in warnings.

Terminal window
recon scan /nonexistent/path --format json
{
"scan": {
"dtos": [],
"files_scanned": 0,
"frameworks_detected": [],
"root": "/nonexistent/path",
"routes": [],
"warnings": [
"walk warning: /nonexistent/path: IO error for operation on /nonexistent/path: No such file or directory (os error 2)"
]
},
"sync": null
}

The human output for the same command is ✓ Scanned 0 file(s): 0 route(s), 0 DTO(s) (none), with no sign of the problem.

A per-file parser failure is added to warnings as file: parse error in ... and the scan continues. Errors while writing .http files during --sync stop the command with a scan I/O error at message and exit code 2.

  • MCP tool recon_scan_codebase with arguments path and sync. See MCP Tools.
  • HTTP POST /api/v1/scan with {"path": "...", "sync": true}. Both fields are optional. The result is cached and used by the drift routes. GET /api/v1/routes lists routes. See HTTP API.
  • Web Studio command palette: “Scan Repository Codebase” and “Sync Code Routes to .http (# @handler)”.