> ## Documentation Index
> Fetch the complete documentation index at: https://nestrs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI REPL — nestrs-cli repl

> Static DI graph explorer — modules, controllers, routes, providers, and DTOs from your crate's source.

`nestrs-cli repl` introspects a nestrs crate by reading its source —
no need to launch the binary, no runtime hook required. Useful for:

* answering "what routes does this app expose?" without booting it
* auditing which module owns which providers / controllers
* generating a Markdown table of every DTO
* piping graph data into a script via `--format json`

The parser is regex-driven (no `syn` dependency). It recognises
`#[module(...)]`, `#[controller(prefix = "/...")]`, `#[injectable]`,
`#[dto]` / mapped-type macros (`#[partial_type]`, `#[omit_type]`,
`#[pick_type]`, `#[intersection_type]`), and HTTP-method macros
(`#[get]` / `#[post]` / `#[put]` / `#[patch]` / `#[delete]`). Struct names
are captured positionally — only types that immediately follow the
attribute are added to the graph.

## Subcommands

### `nestrs-cli repl graph`

Prints a tree of modules, their imports / controllers / providers,
and every controller's routes.

```
nestrs DI graph (2 modules, 2 controllers, 2 providers, 2 DTOs)

module UsersModule  (src/users/module.rs)
  controllers: UsersController
  providers:   UsersService
    controller UsersController (prefix = /users)
         GET /users              -> UsersController::list
       POST /users              -> UsersController::create
      PATCH /users/:id          -> UsersController::update

module AppModule  (src/app/module.rs)
  imports:    UsersModule
```

### `nestrs-cli repl routes`

Flattened, sorted route table — handy for piping into a Markdown
doc or an OpenAPI generation script.

```
METHOD  PATH                                     HANDLER
   GET  /                                        AppController::root
   GET  /health                                  AppController::health
   GET  /users                                   UsersController::list
  POST  /users                                   UsersController::create
 PATCH  /users/:id                               UsersController::update
```

### `nestrs-cli repl providers`

Groups `#[injectable]` types by the module that declares them.
Providers that aren't referenced by any module (orphan services)
fall under `unassigned:`.

### `nestrs-cli repl dtos`

Lists every `#[dto]`-decorated struct (heuristic: name ends with
`Dto`, `Entity`, or `Model`).

### `nestrs-cli repl live`

Dumps the **running** provider and route registries from an app that
enabled the `admin` feature and called `use_admin`. This is the
runtime counterpart of the static scanner: conditional
`cfg!(feature = …)` providers show up here because they actually
exist in the process.

```bash theme={null}
nestrs-cli repl live --url http://127.0.0.1:7777
nestrs-cli repl live --url http://127.0.0.1:7777 --bearer-token "$ADMIN_TOKEN" --format json
```

The CLI shells out to `curl`:

1. `GET {url}/__nestrs/providers`
2. `GET {url}/__nestrs/routes`

Auth is `Authorization: Bearer <token>` on the header. The token is
**never** accepted as a query string (URLs leak into access logs).
curl argv always places `--` before the URL so a malformed URL cannot
be parsed as a flag. Requires `curl` on `$PATH`.

Enable the sidecar:

```rust theme={null}
use nestrs::admin::{AdminOptions, AdminHandle};

let handle: AdminHandle = app.use_admin(AdminOptions {
    addr: "127.0.0.1:7777".parse()?,
    token: Some("secret".into()),
});
tokio::spawn(async move { handle.serve().await });
```

## Flags

* `--path <dir>` — source root to scan. Defaults to `./src`. Use
  this when your crate's source lives somewhere non-standard
  (`src-tauri/`, `services/<name>/src/`, etc.).
* `--format text|json` — `text` (default) is human-readable;
  `json` is machine-readable and round-trips through
  `serde_json`.

## Examples

```bash theme={null}
# show every HTTP route the current crate exposes
nestrs-cli repl routes

# dump the full DI graph as JSON for a tooling pipeline
nestrs-cli repl graph --format json | jq '.modules[] | .name'

# audit a sub-crate
nestrs-cli repl providers --path services/payments/src

# list DTOs across the whole workspace
nestrs-cli repl dtos --path .

# live providers + routes from a running admin sidecar
nestrs-cli repl live --url http://127.0.0.1:7777 --bearer-token "$ADMIN_TOKEN"
```

## Limitations

* The scanner is **static** — it does not run your code. Conditional
  providers (e.g. `if cfg!(feature = "x") { ... }`) are not
  modelled.
* `impl_routes!` blocks that declare routes without `#[get("/")]`
  attributes are not extracted (rare in 1.0.0; the common
  `#[controller] + impl + #[get]` pattern is fully covered).
* Multi-line `#[module(controllers = [\n    Foo,\n    Bar,\n])]`
  lists parse correctly via `[^]]*` capture; nested generics in
  provider types are not parsed.

For these cases, prefer `nestrs-cli repl live --url <admin>` against a
running app with the `admin` feature, or inspect via your existing logging.
