SkillAgentSearch skills...

Torch

Torch is a fast, secure, and production-ready web framework for Rust. Built on Tokio and Hyper, it provides everything you need to build modern web applications with minimal configuration.

Install / Use

/learn @Enigmatikk/Torch
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Torch 🔥

The web framework that doesn't get in your way.

Torch is a fast, secure, and production-ready web framework for Rust. Built on Tokio and Hyper, it provides everything you need to build modern web applications with minimal configuration.

use torch_web::{App, Request, Response, main};

#[main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let app = App::new()
        .get("/", |_req: Request| async {
            Response::ok().body("Hello, World! 🔥")
        })
        .get("/users/:id", |req: Request| async move {
            let id = req.param("id").unwrap_or("Anonymous");
            Response::ok().body(format!("Hello, {}! 🔥", id))
        });

    println!("🔥 Server running at http://localhost:3000");
    app.listen("127.0.0.1:3000").await
}

<a href="https://buymeacoffee.com/enigmatikk" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>

Why developers choose Torch:

  • 🚀 Blazing Fast - Built on Tokio + Hyper for maximum performance
  • Compile-Time Routes - Zero-cost route validation with type-safe extractors
  • 🔥 Ember Templates - Laravel Blade-inspired templating with inheritance
  • 🏗️ Modular Architecture - Multi-crate project structure for large applications
  • 🛡️ Secure by Design - Security features and beautiful error pages included
  • 📊 Production Ready - Monitoring, caching, and database support
  • Real-time Capable - WebSocket and SSE support out of the box
  • 🎯 Simple & Familiar - Sinatra-inspired API that just works
  • 😄 Fun Error Pages - Beautiful 404 pages with rotating flame-themed messages
  • 🛠️ Powerful CLI - Laravel Artisan-inspired command-line tools for rapid development

✨ Features

Compile-Time Route Registration

  • Zero-cost abstractions - Routes validated at compile time
  • Type-safe parameter extraction - Path<T>, Query<T>, Json<T>
  • IDE support - Full autocomplete and error checking
  • No runtime overhead - All validation happens at build time
use torch_web::{routes, get, Path, Query};

routes! {
    #[get("/users/{id}")]
    async fn get_user(Path(id): Path<u32>) -> Response {
        Response::ok().json(format!("User {}", id))
    }

    #[get("/users")]
    async fn list_users(Query(params): Query<UserQuery>) -> Response {
        // Type-safe query parameter extraction
        Response::ok().json(params)
    }
}

🔥 Ember Template Engine

  • Laravel Blade-inspired syntax - @extends, @section, @foreach
  • Template inheritance for consistent layouts across pages
  • Component system with @include for reusable templates
  • Automatic XSS protection and input escaping
  • Hot reloading in development, intelligent caching in production
use torch_web::{ember::*, main};

#[main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let app = App::new()
        .get("/", |_req| async {
            let data = EmberData::new()
                .with("title", "Welcome to Torch")
                .with("users", vec!["Alice", "Bob", "Charlie"]);

            ember("home", data).await
        });

    app.listen("127.0.0.1:3000").await
}

Template file (templates/home.ember):

@extends('layout')

@section('content')
    <h1>{{ $title }}</h1>

    @if(count($users) > 0)
        <ul>
        @foreach($users as $user)
            <li>🔥 {{ $user }}</li>
        @endforeach
        </ul>
    @else
        <p>No users found.</p>
    @endif
@endsection

🏗️ Modular Architecture

  • Multi-crate project structure - Prevent large monolithic crates
  • Workspace support - Organize code across focused crates
  • Clear separation of concerns - Core, Web, Auth, Database layers
  • Team scalability - Multiple teams can work in parallel
my-torch-app/
├── crates/
│   ├── core/          # Business logic
│   ├── web/           # Torch web application
│   ├── auth/          # Authentication
│   ├── database/      # Data layer
│   └── api/           # External integrations

🎯 Type-Safe Extractors

  • Path parameters - Extract :id, :name with automatic type conversion
  • Query strings - Parse ?key=value into structs or HashMaps
  • JSON bodies - Deserialize request bodies with serde
  • Headers - Access any HTTP header with type safety
  • Application state - Share data across handlers with dependency injection
  • Multiple extractors - Combine any extractors in a single handler

🚀 High Performance

  • Built on Tokio + Hyper for maximum async performance
  • Handles thousands of concurrent connections efficiently
  • Zero-copy parsing and minimal allocations
  • HTTP/1.1 and HTTP/2 support

🛡️ Security First

  • Input validation and sanitization
  • HMAC request signing for API security
  • IP whitelisting and rate limiting
  • Security headers and CSRF protection

📊 Production Ready

  • Structured logging with tracing support
  • Metrics collection for monitoring
  • Health checks and graceful shutdown
  • Configuration management via TOML and environment variables

Real-time Support

  • WebSocket support for real-time applications
  • Server-Sent Events (SSE) for live updates
  • Connection management and broadcasting

🗄️ Database & Caching

  • PostgreSQL support with connection pooling
  • Redis caching integration
  • Query builder for safe database operations
  • Migration runner for schema management

Beautiful Error Pages

  • Stunning default error pages with Torch branding
  • Sinatra-inspired 404 messages with flame themes
  • Fully customizable error page templates
  • Responsive design that works on all devices

🔥 Ember Template Engine

  • Laravel Blade-inspired syntax - familiar and powerful
  • Template inheritance with @extends and @section
  • Component system for reusable templates
  • Automatic XSS protection and input escaping
  • Hot reloading and intelligent caching
  • Zero-config setup - just create .ember files

🔧 Developer Experience

  • Sinatra-inspired API - familiar and intuitive
  • Type-safe request/response handling
  • Middleware system for composable functionality
  • Hot reloading in development mode

🛠️ Developer Tools

# Install VS Code extension for .ember template support
code --install-extension enigmatikk.torch-ember

🚀 Quick Start

Installation

For full-featured applications with templates:

cargo add torch-web --features templates,json,database

For API-only applications:

cargo add torch-web --features json

For maximum features (production apps):

[dependencies]
torch-web = {
    version = "0.2.2",
    features = ["templates", "json", "database", "cache", "websocket"]
}

CLI Tool (Optional):

Install the Torch CLI for Laravel Artisan-like functionality:

cargo install torch-web --features cli

The CLI will automatically show PATH setup instructions for your operating system. If the torch command is not found after installation, follow the displayed instructions to add ~/.cargo/bin (or %USERPROFILE%\.cargo\bin on Windows) to your system PATH.

Quick CLI usage:

torch new my-app        # Create new Torch application
cd my-app
torch serve --hot       # Start development server with hot reload
torch make controller   # Generate controllers, models, etc.
torch --help           # Show all available commands

Available Features:

  • templates - Ember templating engine with Laravel Blade-like syntax
  • json - JSON request/response handling with serde
  • database - PostgreSQL support with SQLx
  • cache - Redis caching integration
  • websocket - WebSocket support for real-time apps
  • api - Enhanced API development tools
  • cli - Command-line interface with Laravel Artisan-like functionality
  • cli - Laravel Artisan-inspired command-line tools

🛠️ Torch CLI - Laravel Artisan for Rust

Torch includes a powerful CLI tool inspired by Laravel's Artisan, providing rapid scaffolding and development utilities:

# Install the CLI
cargo install torch-web --features cli

# Create a new Torch application
torch new my-app

# Generate controllers, models, and more
torch make controller UserController --resource
torch make model User --migration --factory --seeder

# Start development server with hot reload
torch serve --hot

# Run database migrations
torch migrate

# Interactive REPL for debugging
torch tinker

# Build for production
torch build --release

Available CLI Commands

Project Management:

  • torch new <name> - Create new Torch application
  • torch serve --hot - Development server with hot reload
  • torch build --release - Production build with optimizations

Code Generation:

  • torch make controller <name> - Generate controllers (with --resource, --api flags)
  • torch make model <name> - Generate models (with --migration, --factory, --seeder flags)
  • torch make middleware <name> - Generate middleware
  • torch make template <name> - Generate Ember templates
  • torch make migration <name> - Generate database migrations
  • torch make test <name> - Generate tests

Database Operations:

  • torch migrate - Run migrations (with rollback, fresh, status subcommands)
  • torch db seed - Seed databa

Related Skills

View on GitHub
GitHub Stars19
CategoryDevelopment
Updated3mo ago
Forks0

Languages

Rust

Security Score

77/100

Audited on Dec 5, 2025

No findings