# ๐ cargo-setupx
> **Automate Rust project setup with modular configuration packs**
A Rust-based CLI and library that automates the initial setup of new Rust projects. Provides modular configuration packs that can be selectively applied to standardize development environments.
[](https://crates.io/crates/cargo-setupx)
[](https://opensource.org/licenses/MIT)
## ๐ฏ Features
- **Quality Pack** - Code quality configuration files
- `rustfmt.toml` - Code formatting rules
- `clippy.toml` - Linting configuration
- `_typos.toml` - Spell checking setup
- `Makefile` - Common development commands
- **Hooks Pack** - Git hooks for automated quality checks
- `.githooks/pre-push` - Pre-push quality gate
- `.githooks/setup.sh` - Hooks installation script
- Configures `core.hooksPath` automatically
- **Architecture Pack** - Project structure scaffolding
- Clean Architecture (domain, application, infrastructure, presentation)
- Additional patterns planned (hexagonal, onion - see Roadmap)
## ๐ฆ Installation
```bash
cargo install cargo-setupx
```
Or install from source:
```bash
git clone https://github.com/ricardoferreirades/cargo-setupx.git
cd cargo-setupx
cargo install --path .
```
## ๐ Quick Start
### Apply All Packs
```bash
# In your Rust project directory
cargo setupx --all
```
### Apply Specific Packs
```bash
# Quality pack only
cargo setupx --quality
# Hooks pack only
cargo setupx --hooks
# Architecture pack (clean)
cargo setupx --arch=clean
# Quality + Hooks
cargo setupx --quality --hooks
```
### Force Overwrite
```bash
# Overwrite existing files
cargo setupx --all --force
# Skip confirmation prompt
cargo setupx --all --yes
```
## ๐ Usage
### As a Cargo Subcommand
```bash
# Show help
cargo setupx --help
# Apply to current directory
cargo setupx --quality --hooks
# Apply to specific directory
cargo setupx --all /path/to/project
# Force overwrite with no prompts
cargo setupx --all --force --yes
```
### As a Library
```rust
use cargo_setupx::{Config, apply_packs};
use std::path::Path;
let config = Config {
quality: true,
hooks: true,
arch: Some("clean".to_string()),
force: false,
yes: false,
};
apply_packs(&config, Path::new(".")).expect("Failed to apply packs");
```
## ๐ What Gets Created
### Quality Pack (`--quality`)
Creates the following files in your project root:
```
clippy.toml # Clippy linter configuration
rustfmt.toml # Rustfmt formatter settings
_typos.toml # Typos spell checker config
Makefile # Development commands
```
**Makefile commands:**
- `make fmt` - Format code (cargo fmt + taplo)
- `make lint` - Run clippy linter
- `make lint-fix` - Auto-fix linting issues
- `make check` - Type check without building
- `make spell` - Check spelling
- `make spell-fix` - Auto-fix spelling errors
- `make quality` - Run all quality checks
- `make test` - Run tests
- `make run` - Run the application
### Hooks Pack (`--hooks`)
Creates Git hooks for automated quality checks:
```
.githooks/
โโโ pre-push # Pre-push quality gate (executable)
โโโ setup.sh # Hook installation script (executable)
โโโ README.md # Hooks documentation
```
The pre-push hook runs:
1. โ
Code formatting check (`cargo fmt --check`)
2. โ
TOML formatting check (`taplo format --check`)
3. โ
Linting (`cargo clippy -- -D warnings`)
4. โ
Spell check (`typos`)
5. โ
Type check (`cargo check`)
6. โ
Tests (`cargo test`)
**Push is blocked if any check fails!**
### Architecture Pack (`--arch=clean`)
**Note:** Currently only Clean Architecture is supported. Other patterns (hexagonal, onion) are planned.
Creates Clean Architecture folder structure:
```
src/
โโโ domain/
โ โโโ entities/
โ โโโ repositories/
โ โโโ services/
โโโ application/
โ โโโ dto/
โ โโโ use_cases/
โโโ infrastructure/
โ โโโ database/
โ โโโ config/
โ โโโ http/
โโโ presentation/
โโโ handlers/
```
Each directory includes:
- `mod.rs` with documentation
- Stub files for quick start
## ๐ง Prerequisites
For full functionality, install these tools:
```bash
# Taplo (TOML formatter)
cargo install taplo-cli
# Typos (spell checker)
cargo install typos-cli
```
## ๐ ๏ธ Development Workflow
After running `cargo setupx --all`, use these commands:
```bash
# Initial setup
make setup-hooks # Configure git hooks
# Daily development
make quality # Run all checks
make fmt # Format code
make lint-fix # Fix linting issues
make spell-fix # Fix spelling
# Testing
make test # Run tests
make check # Quick type check
# Building
make build # Build release
make clean # Clean artifacts
```
## โ๏ธ Configuration
### Idempotent Setup
Running `cargo setupx` multiple times is safe. It will:
- Skip existing files (unless `--force` is used)
- Show clear status messages (Created, Skipped, Overwrote)
- Never corrupt existing files
### Force Overwrite
Use `--force` to overwrite existing files:
```bash
cargo setupx --all --force
```
### Skip Confirmation
Use `--yes` to skip confirmation prompts:
```bash
cargo setupx --all --yes
```
## ๐จ Examples
### New Project Setup
```bash
# Create new Rust project
cargo new my-awesome-project
cd my-awesome-project
# Apply all packs
cargo setupx --all
# Setup git hooks
make setup-hooks
# Verify everything works
make quality
```
### Existing Project Setup
```bash
# In your existing project
cd my-existing-project
# Apply quality + hooks (no architecture changes)
cargo setupx --quality --hooks --yes
# Setup hooks
make setup-hooks
```
### Library Project
```bash
# Create library
cargo new --lib my-library
cd my-library
# Apply quality pack + clean architecture
cargo setupx --quality --arch=clean
# Verify
make quality
```
## ๐งช Testing
Run the test suite:
```bash
cargo test
```
Run specific tests:
```bash
cargo test quality
cargo test hooks
cargo test architecture
```
## ๐ Documentation
Generate and open documentation:
```bash
cargo doc --open
```
## ๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
1. Fork the repository
2. Create your feature branch (`git checkout -b feat/amazing-feature`)
3. Make your changes
4. Run quality checks (`make quality`)
5. Commit your changes (`git commit -m 'feat: add amazing feature'`)
6. Push to the branch (`git push origin feat/amazing-feature`)
7. Open a Pull Request
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## ๐ Acknowledgments
- Inspired by the need for consistent Rust project setups
- Built with [Clap](https://github.com/clap-rs/clap) for CLI parsing
- Quality tools: [Clippy](https://github.com/rust-lang/rust-clippy), [Rustfmt](https://github.com/rust-lang/rustfmt), [Typos](https://github.com/crate-ci/typos)
## ๐ Links
- [Repository](https://github.com/ricardoferreirades/cargo-setupx)
- [Issue Tracker](https://github.com/ricardoferreirades/cargo-setupx/issues)
- [Documentation](https://docs.rs/cargo-setupx)
## ๐ง Roadmap
- [ ] Support for hexagonal architecture
- [ ] Support for onion architecture
- [ ] Custom pack definitions via `.setupx.toml`
- [ ] CI/CD configuration packs (GitHub Actions, GitLab CI)
- [ ] Docker configuration pack
- [ ] Plugin system for community packs
- [ ] Interactive mode for pack selection
---
**Made with โค๏ธ by Ricardo Ferreira**