-
-
Notifications
You must be signed in to change notification settings - Fork 0
example app
Path: examples/hello-nestforge
Related examples:
examples/hello-nestforge-graphqlexamples/hello-nestforge-grpc
- Root
src/lib.rsbarrel with app-level re-exports - Nest-style module imports (
UsersModule,SettingsModule,VersioningModule) - Root app controllers at
src/level - Feature folders for each domain
- Global guard + interceptor registration
- Route-level guards/interceptors
- Route versioning (
v1,v2) - Config loading with schema checks
-
main.rsimportsAppModulefrom the example crate root and creates the app withNestForgeFactory::<AppModule>::create() - Factory applies global prefix (
api) - Factory registers global guard/interceptor
- Module graph is resolved and providers/controllers are registered
- HTTP server starts on port
3000
app_module.rs does three main jobs:
- imports feature modules
- registers root controllers (
AppController,HealthController) - registers root providers (
AppConfig,Db)
It also validates env values using:
ConfigModule::for_rootConfigOptionsEnvSchema
src/users/ contains:
controllers/users_controller.rsservices/users_service.rsdto/*
For new projects, the CLI also supports a flat feature layout with --flat, which generates those files directly under src/users/ instead of nested controllers/, services/, and dto/ folders.
The controller demonstrates:
- full CRUD routes
- validation with
ValidatedBody<T> - route-level guards/interceptors
- cleaner error mapping with
or_bad_request()andor_not_found_id()
src/settings/ contains CRUD endpoints plus runtime config endpoint:
GET /api/v1/settings/runtime
This endpoint shows DI config injection (Inject<AppConfig>).
The example also uses nestforge::prelude::* in entrypoints and root app files to keep framework
imports short, while its src/lib.rs barrel keeps app imports flat.
src/versioning/controllers/versioning_controller.rs has two versions of the same route:
GET /api/v1/versioning/helloGET /api/v2/versioning/hello
- Guards:
src/guards/ - Interceptors:
src/interceptors/
Example uses the macro-based short style (nestforge::guard!, nestforge::interceptor!) to keep code small.
NestForge Docs | Home | Quick Start | Project Structure | GitHub Repo