Skip to content

Architecture

How NestForge Web is structured internally

NestForge Web combines a Next.js-inspired frontend serving layer with NestForge’s Rust backend into a unified fullstack framework.

┌─────────────────────────────────────────────────────────────┐
│ NestForge Web │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────┐ ┌─────────────────────────┐ │
│ │ Frontend │ │ Backend │ │
│ │ (TypeScript) │◄──►│ (Rust) │ │
│ │ │ │ │ │
│ │ ┌────────────────┐ │ │ ┌───────────────────┐ │ │
│ │ │ React Pages │ │ │ │ NestForge Modules │ │ │
│ │ │ API Routes │ │ │ │ Controllers │ │ │
│ │ │ Components │ │ │ │ Services │ │ │
│ │ │ Layouts │ │ │ │ Middleware │ │ │
│ │ └────────────────┘ │ │ └───────────────────┘ │ │
│ └─────────────────────┘ └─────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ HTTP Server (Axum) │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Routing │ │ HMR │ │ OpenAPI │ │ │
│ │ │ Matcher │ │ Client │ │ Generator│ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Rust Runtime │ │
│ │ tokio ─ async/await, task scheduling │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘

Core framework primitives:

ModuleResponsibility
routingFile-based routing, URL matching
apiAPI route handlers, HTTP methods
openapiOpenAPI spec generation
hmrHot module replacement client/server
serverHTTP server (Axum integration)
configConfiguration loading

Public API crate that re-exports nfw-core:

pub use nfw_core::*;
pub mod prelude {
pub use nfw_core::prelude::*;
}

CLI binary for development:

Terminal window
nestforge-web new <name> # Scaffold project
nestforge-web dev # Start dev server
nestforge-web build # Production build
nestforge-web generate # Code generation
1. Browser → HTTP Request
2. Axum Server receives request
3. Route matcher identifies page component
4. Backend modules prepare data (DI resolves services)
5. React component renders to HTML
6. HTML + serialized data sent to client
7. Browser receives complete page (hydrates)
1. Browser → API Request (/api/users)
2. Axum routes to NestForge controller
3. Middleware runs (auth, logging)
4. Guard checks authorization
5. Service executes business logic
6. Response serialized (JSON)
7. Client receives response
1. File changes detected (watcher)
2. Change notification sent to browser (WebSocket)
3. Browser fetches changed modules
4. React fast-refresh updates component
5. State preserved where possible
// Frontend calls API
const users = await fetch('/api/users').then(r => r.json());
// API returns JSON
// TypeScript types match Rust structs

Rust structs generate TypeScript types:

// Rust
#[derive(Debug, Serialize, Deserialize)]
pub struct User {
pub id: Uuid,
pub name: String,
pub email: String,
}
// Generated TypeScript
interface User {
id: string;
name: string;
email: string;
}
┌─────────────────────────────────────────┐
│ Application Module │
│ (user defines in src/backend/) │
├─────────────────────────────────────────┤
│ NestForge Modules │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ Users │ │ Posts │ │ Auth │ │
│ └────┬────┘ └────┬────┘ └────┬────┘ │
├───────┼───────────┼───────────┼─────────┤
│ │ │ │ │
│ ┌────▼───────────▼───────────▼────┐ │
│ │ DI Container │ │
│ │ Service Resolution + Lifecycle│ │
│ └─────────────────────────────────┘ │
├─────────────────────────────────────────┤
│ Database Adapters │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │Postgres│ │ Redis │ │ MongoDB │ │
│ └─────────┘ └─────────┘ └─────────┘ │
└─────────────────────────────────────────┘
Terminal window
cargo build --release
./target/release/my-app
FROM rust:1.75-slim
WORKDIR /app
COPY . .
RUN cargo build --release
EXPOSE 3000
CMD ["./target/release/my-app"]
Terminal window
# Configure for Cloudflare
nestforge-web build --target cloudflare-workers
ComponentOptimization
Cold Start< 50ms (native binary)
Memory< 20MB baseline
Throughput100k+ req/s
TTFB< 10ms (local)