nestrs-cli

Crates.ionestrs-cli
lib.rsnestrs-cli
version0.1.1
created_at2026-01-17 23:55:32.969475+00
updated_at2026-01-17 23:59:32.346489+00
descriptionNestRS CLI - generate a NestJS-like Rust web API structure
homepagehttps://github.com/SantiagoLopezDeharo/nestrs-cli
repositoryhttps://github.com/SantiagoLopezDeharo/nestrs-cli
max_upload_size
id2051439
size37,183
Santiago Lopez de haro (SantiagoLopezDeharo)

documentation

README

NestRS CLI

NestRS is a lightweight, single-thread async Rust web API starter with a NestJS-like folder structure. This repository contains the CLI (nestrs) used to generate new NestRS projects.

Features

  • Single-thread async runtime (Tokio current-thread)
  • Strongly inspired on NestJS proven development patterns
  • Request/Response primitives with automatic status lines
  • Controller-first route declarations (NestJS-like)
  • Domain-driven structure: controller, service, repo, DTO
  • CLI scaffold to generate new entities

CLI Usage

Generate a new NestRS project:

nestrs new my-app

This will create a new folder with the full base structure and files.

Template Project Structure

src/
  bin/
    scaffold_entity.rs
  domain/
    dog/
      controller.rs
      service.rs
      repo.rs
      dto.rs
      mod.rs
    mod.rs
  primitives/
    http/
      request.rs
      response.rs
      mod.rs
    mod.rs
  routing/
    init.rs
    mod.rs
  main.rs

Running the Generated Server

cargo run

The server listens on 127.0.0.1:8080.

Routing Flow

  1. The router is initialized at startup via init(init_routes()).
  2. Each controller exposes a routes() method returning Route definitions.
  3. The router matches method/path and invokes the controller handler.
  4. The controller returns a Response, which is written back to the client.

Creating a New Entity

Use the scaffold CLI to generate a new domain entity:

cargo run --bin scaffold_entity -- Dog

This will:

  • Create src/domain/dog/ with controller/service/repo/dto files.
  • Add the entity to src/domain/mod.rs.
  • Register the controller routes in src/routing/init.rs.

Adding Controller Routes

Routes are declared inside each controller’s routes() method using the route! macro:

Route::new("GET", &["dog"], route!(DogController::get_all))

Handlers receive:

  • Request
  • RouteParams (path params like :id are available via params.get("id"))

Example Request

curl http://127.0.0.1:8080/dog

The default Dog controller responds with:

Woof

Notes

  • Responses automatically include Content-Length and Connection: close if not provided.
  • The router is a singleton registry initialized before the server starts listening.
Commit count: 16

cargo fmt