CLI Workflow
A detailed guide to the NestForge CLI, including generators, DB commands, and current utility commands.
The NestForge CLI currently groups its workflow into five areas:
newfor scaffolding a fresh appgorgeneratefor adding code to an existing appdbfor migration-oriented database workflowsexport-docsordocsfor OpenAPI exportfmtfor project formatting
Scaffold a new app
Section titled “Scaffold a new app”Base syntax:
nestforge new <app-name>nestforge new <app-name> --transport <http|graphql|grpc|microservices|websockets>nestforge new <app-name> --openapiWhat the transport flag changes:
http: classic controller-first applicationgraphql: schema-first bootstrap with GraphiQL supportgrpc: tonic-oriented transport setup withproto/andbuild.rsmicroservices: pattern registry plus in-process client examplewebsockets: gateway-first bootstrap andsrc/ws/
The default HTTP scaffold now keeps the bootstrap files at the root of src/
and uses .with_global_prefix("api") and .with_version("v1") in
src/main.rs.
Generate application code
Section titled “Generate application code”Generators are designed to work inside an application folder containing Cargo.toml
and src/.
Core generators:
nestforge g module usersnestforge g resource users --module usersnestforge g controller usersnestforge g service usersCross-cutting generators:
nestforge g guard authnestforge g decorator correlation_idnestforge g filter rewrite_bad_requestnestforge g middleware auditnestforge g interceptor loggingnestforge g serializer userTransport-specific generators:
nestforge g graphql usersnestforge g grpc billingnestforge g gateway eventsnestforge g microservice usersTarget a feature module
Section titled “Target a feature module”To generate inside a feature boundary instead of at the app root:
nestforge g resource users --module usersThe CLI will:
- verify the feature module exists
- write DTO, service, and controller files under
src/users/ - patch the module exports, providers, and controller wiring
Flat and nested layouts
Section titled “Flat and nested layouts”The resource generator supports both nested and flat module layouts.
Use the default nested layout:
nestforge g resource users --module usersOr generate a flat layout:
nestforge g resource users --module users --flatThe flat layout keeps generated files together in the feature root instead of
placing them in controllers/, services/, and dto/.
DTO prompting
Section titled “DTO prompting”When nestforge g resource runs in an interactive terminal, the CLI can prompt
for DTO fields so the generated Create*Dto, Update*Dto, and entity DTO
match your domain.
nestforge g resource users --module users --flatnestforge g resource users --module users --flat --no-promptUse --no-prompt when you want the generator to skip the DTO field prompt and
fall back to the default field set.
Database commands
Section titled “Database commands”The CLI includes a lightweight migration workflow.
nestforge db initnestforge db generate create_users_tablenestforge db migratenestforge db statusBehavior to know:
initcreatesmigrations/and.nestforge/applied_migrations.txtgeneratecreates a timestamped SQL filemigratereadsDATABASE_URLand applies pending filesstatuscompares migration files with recorded state and reports drift
If you want the full SQL application path around those commands, continue with:
Utility commands
Section titled “Utility commands”nestforge export-docsnestforge docsnestforge fmtexport-docsgenerates a static OpenAPI artifact from the current appdocsis an alias forexport-docsfmtrunscargo fmtin the app root
You can export JSON or YAML:
nestforge export-docs --format yaml --output docs/openapi.yamlPractical advice
Section titled “Practical advice”Use the CLI to accelerate structure, not to avoid understanding the output. After each generation step, inspect the generated code and make sure:
- module wiring is correct
- feature flags in
Cargo.tomlmatch the transport or runtime you want .envdefaults match your local environment- generated stubs are replaced with application-specific logic before production use