This tutorial demonstrates how to use the Torch CLI to build a complete blog application from scratch, showcasing all the major CLI features.
- Rust installed (1.75+)
- Torch CLI installed:
cargo install torch-web --features cli - PostgreSQL running (optional, for database features)
# Create a new Torch application
torch new torch-blog
# Navigate to the project
cd torch-blog
# Check the project structure
ls -laThis creates a complete project structure with:
src/- Application source codetemplates/- Ember templatesstatic/- Static assetsconfig/- Configuration filesmigrations/- Database migrationsstorage/- Application storage
# Start development server with hot reload
torch serve --hotVisit http://localhost:3000 to see your application running.
# Generate User model with migration, factory, seeder, and policy
torch make model User --migration --factory --seeder --policy
# Generate Post model with all features
torch make model Post --migration --factory --seeder --policy
# Generate Comment model
torch make model Comment --migration --factory --seederThis creates:
- Model files in
src/models/ - Migration files in
migrations/ - Factory files in
src/factories/ - Seeder files in
src/seeders/ - Policy files in
src/policies/
# Generate resource controllers for API endpoints
torch make controller UserController --resource --api
torch make controller PostController --resource --api
torch make controller CommentController --resource --api
# Generate web controllers for HTML pages
torch make controller WebController
torch make controller AuthController# Create layout templates
torch make template layouts/app
torch make template layouts/auth
# Create user templates
torch make template users/index --layout app
torch make template users/show --layout app
torch make template users/profile --layout app
# Create post templates
torch make template posts/index --layout app
torch make template posts/show --layout app
torch make template posts/create --layout app
torch make template posts/edit --layout app
# Create auth templates
torch make template auth/login --layout auth
torch make template auth/register --layout auth
# Create component templates
torch make template components/navbar
torch make template components/footer
torch make template components/post-card# Generate authentication middleware
torch make middleware AuthMiddleware
# Generate CORS middleware
torch make middleware CorsMiddleware
# Generate rate limiting middleware
torch make middleware RateLimitMiddleware
# Generate logging middleware
torch make middleware LoggingMiddleware# Install migration repository
torch migrate install
# Run migrations
torch migrate
# Check migration status
torch migrate status
# Seed the database
torch db seed
# Check database status
torch db status# Generate events
torch make event UserRegistered
torch make event PostPublished
torch make event CommentPosted
# Generate listeners
torch make listener SendWelcomeEmail --event UserRegistered
torch make listener NotifySubscribers --event PostPublished
torch make listener SendCommentNotification --event CommentPosted# Generate background jobs
torch make job SendEmailJob
torch make job ProcessImageJob
torch make job GenerateReportJob --sync
torch make job CleanupTempFilesJob# Generate notification classes
torch make notification WelcomeNotification
torch make notification PostPublishedNotification
torch make notification CommentNotification
torch make notification WeeklyDigestNotification# Generate unit tests
torch make test UserTest --unit
torch make test PostTest --unit
torch make test CommentTest --unit
# Generate integration tests
torch make test ApiTest
torch make test WebTest
torch make test AuthTest# Run all tests
torch test
# Run specific tests
torch test --filter user
# Run only unit tests
torch test --unit
# Run only integration tests
torch test --integration# Cache configuration for better performance
torch config cache
# Cache routes
torch route cache
# Cache views
torch view cache
# Check cache statistics
torch cache stats# Start interactive shell
torch tinkerIn the tinker shell, try:
# Check application info
app
# List routes
routes
# Show configuration
config
# Show models
models
# Test expressions
2 + 2
$app_name
chrono::Utc::now()
# Exit
exit
# Start queue worker in background
torch queue work --queue default &
# Check failed jobs
torch queue failed
# Restart workers
torch queue restart# Generate scheduled task
torch make command DailyCleanupCommand
# List scheduled tasks
torch schedule list
# Run scheduled tasks manually
torch schedule run# Optimize application for production
torch optimize
# Build optimized release
torch build --release
# Check the deployment artifacts
ls -la target/deploy/# Put application in maintenance mode
torch down --secret mySecret123
# Check if it's working (visit your app)
# Bring application back online
torch uptorch-blog/
├── src/
│ ├── controllers/
│ │ ├── user_controller.rs
│ │ ├── post_controller.rs
│ │ ├── comment_controller.rs
│ │ ├── web_controller.rs
│ │ └── auth_controller.rs
│ ├── models/
│ │ ├── user.rs
│ │ ├── post.rs
│ │ └── comment.rs
│ ├── middleware/
│ │ ├── auth_middleware.rs
│ │ ├── cors_middleware.rs
│ │ ├── rate_limit_middleware.rs
│ │ └── logging_middleware.rs
│ ├── events/
│ │ ├── user_registered.rs
│ │ ├── post_published.rs
│ │ └── comment_posted.rs
│ ├── listeners/
│ │ ├── send_welcome_email.rs
│ │ ├── notify_subscribers.rs
│ │ └── send_comment_notification.rs
│ ├── jobs/
│ │ ├── send_email_job.rs
│ │ ├── process_image_job.rs
│ │ ├── generate_report_job.rs
│ │ └── cleanup_temp_files_job.rs
│ ├── notifications/
│ │ ├── welcome_notification.rs
│ │ ├── post_published_notification.rs
│ │ ├── comment_notification.rs
│ │ └── weekly_digest_notification.rs
│ ├── factories/
│ │ ├── user_factory.rs
│ │ ├── post_factory.rs
│ │ └── comment_factory.rs
│ ├── seeders/
│ │ ├── user_seeder.rs
│ │ ├── post_seeder.rs
│ │ └── comment_seeder.rs
│ ├── policies/
│ │ ├── user_policy.rs
│ │ └── post_policy.rs
│ └── main.rs
├── templates/
│ ├── layouts/
│ │ ├── app.ember
│ │ └── auth.ember
│ ├── users/
│ │ ├── index.ember
│ │ ├── show.ember
│ │ └── profile.ember
│ ├── posts/
│ │ ├── index.ember
│ │ ├── show.ember
│ │ ├── create.ember
│ │ └── edit.ember
│ ├── auth/
│ │ ├── login.ember
│ │ └── register.ember
│ └── components/
│ ├── navbar.ember
│ ├── footer.ember
│ └── post-card.ember
├── migrations/
│ ├── 2024_01_01_000001_create_users_table.rs
│ ├── 2024_01_01_000002_create_posts_table.rs
│ └── 2024_01_01_000003_create_comments_table.rs
├── tests/
│ ├── user_test.rs
│ ├── post_test.rs
│ ├── comment_test.rs
│ ├── api_test.rs
│ ├── web_test.rs
│ └── auth_test.rs
├── config/
│ ├── app.toml
│ └── database.toml
├── static/
│ ├── css/
│ ├── js/
│ └── images/
├── storage/
│ ├── logs/
│ └── framework/
├── target/
│ └── deploy/
│ ├── server
│ ├── static/
│ ├── templates/
│ ├── manifest.json
│ └── Dockerfile
├── Cargo.toml
├── README.md
└── .gitignore
- Project Creation:
torch new - Code Generation:
torch make(controller, model, middleware, etc.) - Database:
torch migrate,torch db - Development:
torch serve --hot - Testing:
torch test - Caching:
torch cache,torch config cache,torch route cache - Interactive:
torch tinker - Production:
torch optimize,torch build --release - Maintenance:
torch down,torch up
- Customize the generated code to fit your specific requirements
- Add business logic to controllers and models
- Style your templates with CSS and JavaScript
- Configure your database connection
- Set up deployment using the generated Dockerfile
- Add monitoring and logging for production
- Use resource controllers for standard CRUD operations
- Generate complete features with all related files at once
- Use hot reload during development for faster iteration
- Cache everything for production performance
- Test regularly with the built-in test runner
- Use tinker for debugging and experimentation
- Optimize before deployment for best performance
This tutorial demonstrates the power of the Torch CLI in rapidly scaffolding a complete web application with all the necessary components for a production-ready system.