<div align="center">
# โ๏ธ Cargo-Forge
**A powerful, interactive Rust project generator with intelligent templates and enterprise features**
[](https://crates.io/crates/cargo-forge)
[](https://docs.rs/cargo-forge)
[](https://github.com/marcuspat/cargo-forge/actions)
[](https://github.com/marcuspat/cargo-forge#license)
[](https://github.com/marcuspat/cargo-forge)
*Generate production-ready Rust projects in seconds with intelligent templates, best practices, and optional features*
</div>
## ๐ Quick Start
```bash
# 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](INSTALLATION.md)** - 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:
| **cli-tool** | Command-line applications | โข Clap argument parsing<br>โข Colored output<br>โข Progress indicators<br>โข Error handling |
| **library** | Rust library crates | โข Documentation templates<br>โข Example code<br>โข Benchmark setup<br>โข CI/CD ready |
| **api-server** | REST API servers | โข Axum web framework<br>โข JWT authentication<br>โข Database integration<br>โข OpenAPI docs |
| **wasm-app** | WebAssembly applications | โข wasm-bindgen setup<br>โข Web-sys integration<br>โข Build scripts<br>โข HTML template |
| **game-engine** | Game development | โข Bevy engine<br>โข Asset pipeline<br>โข ECS architecture<br>โข Dev tools |
| **embedded** | Embedded systems | โข no_std setup<br>โข Memory configuration<br>โข HAL integration<br>โข Debug configs |
| **workspace** | Multi-crate projects | โข Organized structure<br>โข Shared dependencies<br>โข Cross-crate testing<br>โข 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
| **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)
```bash
$ 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
```bash
# 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
```bash
# 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:
```toml
# ~/.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:
```toml
# 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:
```rust
// Conditional compilation based on features
{% if database %}
use sqlx::{PgPool, postgres::PgPoolOptions};
{% endif %}
// Smart defaults with fallbacks
// 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:
```bash
# 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:
```dockerfile
# 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](CONTRIBUTING.md) for guidelines.
### Development Setup
```bash
# 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**
```bash
# Ensure cargo bin directory is in PATH
export PATH="$HOME/.cargo/bin:$PATH"
```
**Q: Permission denied errors**
```bash
# Check directory permissions
ls -la .
# Use sudo if needed (not recommended)
```
**Q: Template rendering fails**
```bash
# Validate your input
cargo forge new --dry-run
# Check for special characters in project name
```
### Getting Help
- ๐ [Documentation](https://docs.rs/cargo-forge)
- ๐ฌ Discord Community (coming soon)
- ๐ [Issue Tracker](https://github.com/marcuspat/cargo-forge/issues)
- ๐ง Email Support (coming soon)
## ๐ Documentation
- **[Quick Reference](docs/QUICK_REFERENCE.md)** - Command cheat sheet and quick examples
- **[Project Types Guide](docs/PROJECT_TYPES.md)** - Detailed guide for each project type
- **[Template Syntax](docs/TEMPLATE_SYNTAX.md)** - Tera template documentation
- **[FAQ](docs/FAQ.md)** - Frequently asked questions
- **[Troubleshooting](docs/TROUBLESHOOTING.md)** - Common issues and solutions
- **[Contributing](CONTRIBUTING.md)** - Development guidelines
- **[Changelog](CHANGELOG.md)** - Version history and roadmap
## ๐ License
Licensed under either of:
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
- MIT license ([LICENSE-MIT](LICENSE-MIT))
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
---
<div align="center">
**Built with โค๏ธ by the Rust community**
[Documentation](https://docs.rs/cargo-forge) โข [Crates.io](https://crates.io/crates/cargo-forge)
</div>