Architecture
How NestForge Web is structured internally
Architecture
Section titled “Architecture”NestForge Web combines a Next.js-inspired frontend serving layer with NestForge’s Rust backend into a unified fullstack framework.
High-Level Overview
Section titled “High-Level Overview”┌─────────────────────────────────────────────────────────────┐│ 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 │ ││ └─────────────────────────────────────────────────────┘ ││ │└─────────────────────────────────────────────────────────────┘Crate Structure
Section titled “Crate Structure”nfw-core
Section titled “nfw-core”Core framework primitives:
| Module | Responsibility |
|---|---|
routing | File-based routing, URL matching |
api | API route handlers, HTTP methods |
openapi | OpenAPI spec generation |
hmr | Hot module replacement client/server |
server | HTTP server (Axum integration) |
config | Configuration loading |
nestforge-web
Section titled “nestforge-web”Public API crate that re-exports nfw-core:
pub use nfw_core::*;
pub mod prelude { pub use nfw_core::prelude::*;}nestforge-web-cli
Section titled “nestforge-web-cli”CLI binary for development:
nestforge-web new <name> # Scaffold projectnestforge-web dev # Start dev servernestforge-web build # Production buildnestforge-web generate # Code generationRequest Flow
Section titled “Request Flow”SSR Request
Section titled “SSR Request”1. Browser → HTTP Request2. Axum Server receives request3. Route matcher identifies page component4. Backend modules prepare data (DI resolves services)5. React component renders to HTML6. HTML + serialized data sent to client7. Browser receives complete page (hydrates)API Request
Section titled “API Request”1. Browser → API Request (/api/users)2. Axum routes to NestForge controller3. Middleware runs (auth, logging)4. Guard checks authorization5. Service executes business logic6. Response serialized (JSON)7. Client receives responseHMR Flow
Section titled “HMR Flow”1. File changes detected (watcher)2. Change notification sent to browser (WebSocket)3. Browser fetches changed modules4. React fast-refresh updates component5. State preserved where possibleData Flow
Section titled “Data Flow”Frontend → Backend
Section titled “Frontend → Backend”// Frontend calls APIconst users = await fetch('/api/users').then(r => r.json());
// API returns JSON// TypeScript types match Rust structsType Sharing
Section titled “Type Sharing”Rust structs generate TypeScript types:
// Rust#[derive(Debug, Serialize, Deserialize)]pub struct User { pub id: Uuid, pub name: String, pub email: String,}// Generated TypeScriptinterface User { id: string; name: string; email: string;}Module Dependencies
Section titled “Module Dependencies”┌─────────────────────────────────────────┐│ Application Module ││ (user defines in src/backend/) │├─────────────────────────────────────────┤│ NestForge Modules ││ ┌─────────┐ ┌─────────┐ ┌─────────┐ ││ │ Users │ │ Posts │ │ Auth │ ││ └────┬────┘ └────┬────┘ └────┬────┘ │├───────┼───────────┼───────────┼─────────┤│ │ │ │ ││ ┌────▼───────────▼───────────▼────┐ ││ │ DI Container │ ││ │ Service Resolution + Lifecycle│ ││ └─────────────────────────────────┘ │├─────────────────────────────────────────┤│ Database Adapters ││ ┌─────────┐ ┌─────────┐ ┌─────────┐ ││ │Postgres│ │ Redis │ │ MongoDB │ ││ └─────────┘ └─────────┘ └─────────┘ │└─────────────────────────────────────────┘Deployment Options
Section titled “Deployment Options”Standalone Binary
Section titled “Standalone Binary”cargo build --release./target/release/my-appDocker
Section titled “Docker”FROM rust:1.75-slimWORKDIR /appCOPY . .RUN cargo build --releaseEXPOSE 3000CMD ["./target/release/my-app"]Edge (Cloudflare Workers)
Section titled “Edge (Cloudflare Workers)”# Configure for Cloudflarenestforge-web build --target cloudflare-workersPerformance Characteristics
Section titled “Performance Characteristics”| Component | Optimization |
|---|---|
| Cold Start | < 50ms (native binary) |
| Memory | < 20MB baseline |
| Throughput | 100k+ req/s |
| TTFB | < 10ms (local) |