cargo-forge 0.1.1

A powerful, interactive Rust project generator with intelligent templates and enterprise features
<div align="center">

# โš’๏ธ Cargo-Forge

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

[![Crates.io](https://img.shields.io/crates/v/cargo-forge.svg)](https://crates.io/crates/cargo-forge)
[![Documentation](https://docs.rs/cargo-forge/badge.svg)](https://docs.rs/cargo-forge)
[![CI](https://github.com/marcuspat/cargo-forge/workflows/CI/badge.svg)](https://github.com/marcuspat/cargo-forge/actions)
[![License](https://img.shields.io/crates/l/cargo-forge.svg)](https://github.com/marcuspat/cargo-forge#license)
[![Test Coverage](https://img.shields.io/badge/coverage-45.84%25-yellow.svg)](https://github.com/marcuspat/cargo-forge)

<!-- Demo GIF placeholder - add demo recording here -->

*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:

| Type | Description | Key Features |
|------|-------------|--------------|
| **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

| 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)

```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
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:

```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>