cargo-forge 0.1.0

A powerful, interactive Rust project generator with intelligent templates and enterprise features
docs.rs failed to build cargo-forge-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

โš’๏ธ Cargo Forge

A powerful, interactive Rust project generator with intelligent templates and enterprise features

Crates.io Documentation CI License Test Coverage

Generate production-ready Rust projects in seconds with intelligent templates, best practices, and optional features

๐Ÿš€ Quick Start

# Install cargo-forge
cargo install cargo-forge

# Create a new project interactively
cargo forge new

# Or specify project type directly
cargo forge new my-api --project-type api-server

# Initialize in current directory
cargo forge init --project-type library

๐Ÿ“– Detailed Installation Guide - Including shell completions, pre-built binaries, and platform-specific instructions.

โœจ Features

๐ŸŽฏ Project Types

Cargo Forge supports 7 specialized project types, each with tailored templates and best practices:

Type Description Key Features
cli-tool Command-line applications โ€ข Clap argument parsingโ€ข Colored outputโ€ข Progress indicatorsโ€ข Error handling
library Rust library crates โ€ข Documentation templatesโ€ข Example codeโ€ข Benchmark setupโ€ข CI/CD ready
api-server REST API servers โ€ข Axum web frameworkโ€ข JWT authenticationโ€ข Database integrationโ€ข OpenAPI docs
wasm-app WebAssembly applications โ€ข wasm-bindgen setupโ€ข Web-sys integrationโ€ข Build scriptsโ€ข HTML template
game-engine Game development โ€ข Bevy engineโ€ข Asset pipelineโ€ข ECS architectureโ€ข Dev tools
embedded Embedded systems โ€ข no_std setupโ€ข Memory configurationโ€ข HAL integrationโ€ข Debug configs
workspace Multi-crate projects โ€ข Organized structureโ€ข Shared dependenciesโ€ข Cross-crate testingโ€ข Unified CI

๐Ÿ› ๏ธ Optional Features

Enable powerful features during project creation:

CI/CD Integration

  • GitHub Actions: Automated testing, releases, and deployment
  • GitLab CI: Complete pipeline configuration with caching
  • Custom CI: Template for other CI systems

Database Support

  • PostgreSQL: SQLx integration with migrations
  • MySQL: Full MySQL/MariaDB support
  • SQLite: Embedded database with migrations

Authentication

  • JWT: JSON Web Token authentication
  • OAuth: OAuth2 with popular providers
  • Password: Bcrypt-based password authentication

Additional Features

  • Docker: Multi-stage Dockerfile and docker-compose
  • Testing Frameworks: Property testing, benchmarks, integration tests
  • Documentation: Auto-generated docs with examples
  • Logging: Structured logging with tracing

๐Ÿ“‹ Comparison with cargo-generate

Feature cargo-forge cargo-generate
Interactive Mode โœ… Built-in with beautiful TUI โŒ Requires manual input
Project Types โœ… 7 specialized types โš ๏ธ Generic templates
Smart Defaults โœ… Intelligent suggestions โŒ Manual configuration
Feature Combinations โœ… Validated combinations โš ๏ธ No validation
Dry Run Mode โœ… Preview before creation โŒ Not available
Config Files โœ… Save/load preferences โš ๏ธ Limited support
Non-interactive Mode โœ… CI-friendly with defaults โœ… Available
Custom Templates โœ… Tera templates โœ… Various engines
Conditional Logic โœ… Smart conditionals โœ… Basic support
Post-generation Hooks โœ… Automatic setup โš ๏ธ Manual scripts
Error Recovery โœ… Graceful handling โš ๏ธ Basic errors
Performance โœ… ~1.5s generation โš ๏ธ Varies by template

๐ŸŽฎ Usage Examples

Interactive Mode (Recommended)

$ cargo forge new
โš’๏ธ Welcome to Cargo Forge!
? What's your project name? โ€บ my-awesome-api
? Select project type โ€บ API Server
? Add authentication? โ€บ JWT
? Include database? โ€บ PostgreSQL
? Add Docker support? โ€บ Yes
? Setup CI/CD? โ€บ GitHub Actions

โœจ Project created successfully at ./my-awesome-api

Command-Line Mode

# Create an API server with PostgreSQL and JWT auth
cargo forge new my-api \
  --project-type api-server \
  --author "Jane Doe" \
  --description "My awesome API"

# Create a CLI tool in non-interactive mode (great for CI)
cargo forge new my-cli \
  --project-type cli-tool \
  --non-interactive

# Initialize a library in current directory
cargo forge init --project-type library

# Dry run to preview what will be created
cargo forge new my-project --dry-run

# Use saved configuration
cargo forge new my-project --from-config ~/.forge/defaults.toml

Advanced Usage

# Create a workspace with multiple crates
cargo forge new my-workspace --project-type workspace

# Generate a game with Bevy engine
cargo forge new my-game --project-type game-engine

# Create an embedded project for STM32
cargo forge new my-firmware --project-type embedded

๐Ÿ“ Generated Project Structure

Example: API Server

my-api/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.rs           # Application entry point
โ”‚   โ”œโ”€โ”€ routes/           # HTTP route handlers
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ”œโ”€โ”€ health.rs
โ”‚   โ”‚   โ””โ”€โ”€ users.rs
โ”‚   โ”œโ”€โ”€ models/           # Data models
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ””โ”€โ”€ user.rs
โ”‚   โ”œโ”€โ”€ middleware/       # HTTP middleware
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ””โ”€โ”€ auth.rs
โ”‚   โ””โ”€โ”€ utils/            # Utility functions
โ”‚       โ”œโ”€โ”€ mod.rs
โ”‚       โ””โ”€โ”€ config.rs
โ”œโ”€โ”€ migrations/           # Database migrations
โ”‚   โ””โ”€โ”€ 001_initial.sql
โ”œโ”€โ”€ tests/                # Integration tests
โ”‚   โ””โ”€โ”€ api_tests.rs
โ”œโ”€โ”€ .github/              # GitHub Actions CI
โ”‚   โ””โ”€โ”€ workflows/
โ”‚       โ””โ”€โ”€ ci.yml
โ”œโ”€โ”€ Dockerfile            # Multi-stage Docker build
โ”œโ”€โ”€ docker-compose.yml    # Local development setup
โ”œโ”€โ”€ .env.example          # Environment variables template
โ”œโ”€โ”€ Cargo.toml            # Project manifest
โ””โ”€โ”€ README.md             # Project documentation

๐Ÿ”ง Configuration

Global Configuration

Save your preferences for future projects:

# ~/.config/cargo-forge/config.toml
[defaults]
author = "Your Name"
license = "MIT OR Apache-2.0"
vcs = "git"

[preferences]
always_add_ci = true
default_ci = "github"
prefer_workspace = false

Project Configuration

Each project type supports specific configuration:

# forge.toml in your project
[project]
type = "api-server"
features = ["database", "auth", "docker"]

[database]
type = "postgresql"
migrations_dir = "./migrations"

[auth]
type = "jwt"
expires_in = "24h"

๐Ÿ“Š Template Syntax

Cargo Forge uses Tera templates with custom helpers:

// Conditional compilation based on features
{% if database %}
use sqlx::{PgPool, postgres::PgPoolOptions};
{% endif %}

// Smart defaults with fallbacks
const PORT: u16 = {{ port | default(value=3000) }};

// Case transformations
mod {{ name | snake_case }};
struct {{ name | pascal_case }};

// Feature combinations
{% if auth and database %}
// Authentication with database backend
{% endif %}

๐Ÿงช Testing

Generated projects include comprehensive test setups:

# Run all tests
cargo test

# Run with coverage
cargo tarpaulin

# Benchmarks (if enabled)
cargo bench

# Property tests (if enabled)
cargo test --features proptest

๐Ÿšข CI/CD Integration

All project types can include CI/CD configuration:

GitHub Actions

  • Multi-platform testing (Windows, Mac, Linux)
  • Rust version matrix (stable, beta, nightly)
  • Security audits and dependency checks
  • Release automation with cargo-release
  • Code coverage with Codecov

GitLab CI

  • Cached dependencies for faster builds
  • Parallel job execution
  • Deploy stages for different environments
  • Container registry integration

๐Ÿณ Docker Support

Generated Dockerfiles use multi-stage builds for optimal image size:

# Build stage
FROM rust:1.70 as builder
WORKDIR /app
COPY . .
RUN cargo build --release

# Runtime stage
FROM debian:bookworm-slim
COPY --from=builder /app/target/release/app /usr/local/bin/
CMD ["app"]

๐Ÿ”’ Security

Cargo Forge follows security best practices:

  • No hardcoded secrets in templates
  • Secure default configurations
  • Environment variable usage for sensitive data
  • Security audit integration in CI
  • OWASP compliance for web projects

๐Ÿค Contributing

We love contributions! See CONTRIBUTING.md for guidelines.

Development Setup

# Clone the repository
git clone https://github.com/yourusername/cargo-forge
cd cargo-forge

# Run tests
cargo test

# Run with coverage
cargo tarpaulin

# Build for release
cargo build --release

๐Ÿ“ˆ Performance

Cargo Forge is optimized for speed:

  • Project generation: ~1.5 seconds
  • Template rendering: <100ms
  • Feature validation: <50ms
  • Cross-platform: Works on Windows, Mac, and Linux

๐Ÿ› Troubleshooting

Common Issues

Q: Command not found after installation

# Ensure cargo bin directory is in PATH
export PATH="$HOME/.cargo/bin:$PATH"

Q: Permission denied errors

# Check directory permissions
ls -la .
# Use sudo if needed (not recommended)

Q: Template rendering fails

# Validate your input
cargo forge new --dry-run
# Check for special characters in project name

Getting Help

๐Ÿ“š Documentation

๐Ÿ“œ License

Licensed under either of:

at your option.

๐Ÿ™ Acknowledgments

  • The Rust community for invaluable feedback
  • Contributors who help make Cargo Forge better
  • Projects that inspired us: cargo-generate, create-react-app, Rails generators

Built with โค๏ธ by the Rust community

Website โ€ข Documentation โ€ข Crates.io