-
-
Notifications
You must be signed in to change notification settings - Fork 0
quick start
Get your first NestForge application up and running in minutes. This guide covers project creation, basic routing, and running the server.
Ensure you have the Rust toolchain installed:
The CLI is the recommended way to manage NestForge projects.
# Install from crates.io
cargo install nestforge-cli
# OR install from a local checkout (if developing the framework)
cargo install --path crates/nestforge-cliScaffold a fresh HTTP project:
nestforge new my-nestforge-app
cd my-nestforge-appThe initial scaffold now creates a root barrel in src/lib.rs so the binary can import app
symbols directly from the package crate:
src/
lib.rs
main.rs
app_config.rs
app_controller.rs
app_module.rs
health_controller.rs
That means generated bootstrap code now looks more like:
use my_nestforge_app::AppModule;
use nestforge::prelude::*;Feature modules can still use nested controllers/, services/, and dto/ folders when you generate them that way.
NestForge projects use standard Cargo commands:
cargo runBy default, the server will be available at http://127.0.0.1:3000.
NestForge supports two generator layouts:
-
nested: controllers, services, and DTOs go into their own subfolders. -
flat: generated files stay side-by-side in the feature folder.
Use --flat when generating a module or resource:
nestforge g module users --flat
nestforge g resource users --module users --flatWhen you run the resource generator in a terminal, NestForge can prompt for DTO fields and required/optional flags so the generated Create*Dto, Update*Dto, and entity DTO are usable immediately. Use --no-prompt if you want the default scaffold without interaction.
Flat layout output:
src/users/
mod.rs
user_dto.rs
create_user_dto.rs
update_user_dto.rs
users_controller.rs
users_service.rs
Nested layout output:
src/users/
mod.rs
controllers/
users_controller.rs
services/
users_service.rs
dto/
user_dto.rs
create_user_dto.rs
update_user_dto.rs
If you prefer the older nested layout, just omit --flat.
A minimal NestForge app consists of an AppModule and a Controller.
Define your routes in a struct marked with #[controller].
use nestforge::prelude::*;
#[controller("/")]
pub struct AppController;
#[routes]
impl AppController {
#[nestforge::get("/")]
async fn get_hello() -> ApiResult<String> {
Ok(axum::Json("Hello from NestForge!".to_string()))
}
}Wire everything together in a module.
use nestforge::prelude::*;
use crate::AppController;
#[module(
controllers = [AppController],
providers = [],
)]
pub struct AppModule;Bootstrap the app using NestForgeFactory.
use my_nestforge_app::AppModule;
use nestforge::prelude::*;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
NestForgeFactory::<AppModule>::create()?
.listen(3000)
.await?;
Ok(())
}NestForge provides nestforge::prelude::* for the framework items most apps use repeatedly:
use nestforge::prelude::*;Generated apps also add a root src/lib.rs barrel that re-exports top-level symbols such as
AppModule and AppConfig, so app code can stay flatter:
use my_nestforge_app::AppModule;
use my_nestforge_app::AppConfig;- Add OpenAPI Documentation: Learn how to setup OpenAPI from scratch.
-
Export a Static Spec: Run
nestforge export-docs --format yaml --output docs/openapi.yamlonce your app enables theopenapifeature. -
Generate Features: Use
nestforge g module <name>to add new features. -
Use Flat Feature Layouts: Pass
--flatto keep generated controllers, services, and DTOs directly in the feature folder, for examplenestforge g resource users --module users --flat. - Dependency Injection: Explore the Module System.
NestForge Docs | Home | Quick Start | Project Structure | GitHub Repo