rvy

Crates.iorvy
lib.rsrvy
version0.1.2
created_at2025-12-18 09:28:11.601012+00
updated_at2025-12-24 08:18:53.246037+00
descriptionA modular Rust CLI framework for generating services, tools, and project scaffolds.
homepagehttps://github.com/reverny/rvy
repositoryhttps://github.com/reverny/rvy
max_upload_size
id1992027
size75,134
ReVerNy (rvy-reverny)

documentation

https://docs.rs/rvy

README

RVY - Rust Code Generator

License: MIT Rust

A powerful CLI tool for scaffolding production-ready Rust projects with Clean Architecture, REST APIs, OpenAPI/Swagger documentation, and multiple database support.

โœจ Features

  • ๐Ÿ—๏ธ Clean Architecture - Service โ†’ Usecase โ†’ Repository โ†’ Adapter pattern
  • ๐Ÿš€ REST API - Full CRUD operations with Axum framework
  • ๐Ÿ“š OpenAPI 3.1.0 - Auto-generated Swagger documentation with Authorization
  • ๐Ÿ—„๏ธ Multi-Database - Runtime switching between PostgreSQL, MySQL, SQLite, MongoDB
  • ๐Ÿ” Bearer Auth - Built-in authorization support in all endpoints
  • โšก Async/Await - Tokio-based async runtime
  • ๐ŸŽฏ Type-Safe - Full Rust type safety with SQLx compile-time checks
  • ๐Ÿ“ฆ Zero Configuration - Works out of the box with sensible defaults

Installation

From crates.io (Recommended)

cargo install rvy

From source

git clone https://github.com/rvy-reverny/rvy.git
cd rvy
cargo install --path .

Verify installation

rvy --help

Usage

Create a new project

rvy new project my_app

This creates a new project with the following structure:

my_app/
โ”œโ”€โ”€ Cargo.toml
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.rs
โ”‚   โ”œโ”€โ”€ service/
โ”‚   โ”œโ”€โ”€ usecase/
โ”‚   โ”œโ”€โ”€ repository/
โ”‚   โ””โ”€โ”€ data/

Generate all layers at once (Recommended)

# Generate complete entity with all layers, database adapters, and REST API
rvy new-all user

This generates:

  • โœ… Service layer: src/service/user_service.rs
  • โœ… Usecase layer: src/usecase/user_usecase.rs
  • โœ… Repository trait: src/repository/user.rs
  • โœ… Data model: src/data/user_data.rs
  • โœ… REST API Handler: src/handler/user_handler.rs with OpenAPI annotations
  • โœ… Database adapters: src/adapter/user_{postgres,mysql,mongodb,sqlite}.rs
  • โœ… Factory pattern: src/factory/user_factory.rs
  • โœ… Database config: src/config/database.rs
  • โœ… Usage examples: examples/user_example.rs and docs/user_USAGE.md
  • โœ… Auto-updated main.rs with routes and Swagger UI

Generate individual components

# Generate specific layers
rvy gen service user
rvy gen usecase user
rvy gen repository user
rvy gen data user

# Generate REST API handler with OpenAPI docs
rvy gen handler user

# Generate database adapters
rvy gen adapter user

# Generate factory for runtime DB selection
rvy gen factory user

๐Ÿš€ Quick Start

1. Create a new project

rvy new project my_api
cd my_api

2. Generate your first entity

rvy new-all product

3. Set up database connection

Create a .env file:

DATABASE_URL=postgres://user:password@localhost:5432/mydb
# Or use other databases:
# DATABASE_URL=mysql://user:password@localhost:3306/mydb
# DATABASE_URL=sqlite://data.db
# DATABASE_URL=mongodb://localhost:27017/mydb

4. Run the application

cargo run

5. Access Swagger UI

Open your browser: http://127.0.0.1:3000/swagger-ui

You'll see:

  • ๐Ÿ“š Complete API documentation
  • ๐Ÿ” Authorization button (click to add Bearer token)
  • ๐Ÿงช Try it out feature for testing endpoints
  • ๐Ÿ“‹ Multiple API specs (one per entity)

๐Ÿ“Š Generated Project Structure

my_api/
โ”œโ”€โ”€ Cargo.toml
โ”œโ”€โ”€ .env
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.rs              # Auto-configured with routes & Swagger
โ”‚   โ”œโ”€โ”€ lib.rs
โ”‚   โ”œโ”€โ”€ service/             # Business logic
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ””โ”€โ”€ product_service.rs
โ”‚   โ”œโ”€โ”€ usecase/             # Application use cases
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ””โ”€โ”€ product_usecase.rs
โ”‚   โ”œโ”€โ”€ repository/          # Data access traits
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ””โ”€โ”€ product.rs
โ”‚   โ”œโ”€โ”€ data/                # DTOs with OpenAPI schemas
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ””โ”€โ”€ product_data.rs
โ”‚   โ”œโ”€โ”€ handler/             # REST API with OpenAPI annotations
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ””โ”€โ”€ product_handler.rs
โ”‚   โ”œโ”€โ”€ adapter/             # Database implementations
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ”œโ”€โ”€ product_postgres.rs
โ”‚   โ”‚   โ”œโ”€โ”€ product_mysql.rs
โ”‚   โ”‚   โ”œโ”€โ”€ product_mongodb.rs
โ”‚   โ”‚   โ””โ”€โ”€ product_sqlite.rs
โ”‚   โ”œโ”€โ”€ factory/             # Runtime DB selection
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ””โ”€โ”€ product_factory.rs
โ”‚   โ””โ”€โ”€ config/
โ”‚       โ”œโ”€โ”€ mod.rs
โ”‚       โ””โ”€โ”€ database.rs      # DB configuration
โ”œโ”€โ”€ examples/
โ”‚   โ””โ”€โ”€ product_example.rs
โ””โ”€โ”€ docs/
    โ””โ”€โ”€ product_USAGE.md

๐Ÿ”ง Options

  • --dry-run: Preview what will be generated without writing files
  • --force: Overwrite existing files

๐Ÿ’ก Examples

# Preview generation
rvy new-all user --dry-run

# Force overwrite existing files
rvy gen handler user --force

# Generate multiple entities
rvy new-all product
rvy new-all user
rvy new-all order

๐Ÿ—๏ธ Architecture

RVY follows Clean Architecture principles with clear separation of concerns:

Handler (REST API)
    โ†“
Service (Business Logic)
    โ†“
Usecase (Application Logic)
    โ†“
Repository (Data Access Interface)
    โ†“
Adapter (Database Implementation)
    โ†“
Database (PostgreSQL/MySQL/SQLite/MongoDB)

Layer Responsibilities

  • Handler: REST API endpoints, request/response handling, OpenAPI documentation
  • Service: Business rules and domain logic
  • Usecase: Application-specific business rules
  • Repository: Data access interface (trait)
  • Adapter: Concrete database implementations
  • Data: DTOs with serialization and validation
  • Factory: Runtime database adapter selection
  • Config: Application configuration and environment variables

๐Ÿ“š API Documentation

Generated APIs include:

Endpoints (per entity)

  • GET /{entity}s - Get all records
  • GET /{entity}s/{id} - Get record by ID
  • POST /{entity}s - Create new record
  • PUT /{entity}s/{id} - Update record
  • DELETE /{entity}s/{id} - Delete record

OpenAPI Features

  • โœ… OpenAPI 3.1.0 specification
  • โœ… Bearer Authentication - Token-based auth on all endpoints
  • โœ… Request/Response Schemas - Full type definitions
  • โœ… Example Values - Sample data for testing
  • โœ… Multiple API Specs - Separate docs per entity
  • โœ… Interactive Testing - Try endpoints directly from Swagger UI

๐Ÿ—„๏ธ Database Support

Supported Databases

Database Connection String Example
PostgreSQL postgres://user:pass@localhost:5432/db
MySQL mysql://user:pass@localhost:3306/db
SQLite sqlite://data.db
MongoDB mongodb://localhost:27017/db

Runtime Selection

The database adapter is selected at runtime based on the DATABASE_URL environment variable. No need to recompile for different databases!

// Automatically detected from DATABASE_URL
let config = DatabaseConfig::from_env();
let repository = create_product_repository(&config).await?;

๐Ÿ” Authentication

All generated endpoints include Bearer token authentication:

#[utoipa::path(
    get,
    path = "/products",
    responses(/* ... */),
    security(("bearer_auth" = [])) // ๐Ÿ”’ Requires authentication
)]

To test with Swagger UI:

  1. Click Authorize button ๐Ÿ”“
  2. Enter: Bearer your-token-here
  3. Click Authorize
  4. All requests will include the token

๐Ÿ› ๏ธ Technology Stack

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built with โค๏ธ using Rust
  • Inspired by Clean Architecture principles
  • OpenAPI 3.1.0 specification
  • Community feedback and contributions

Made with ๐Ÿฆ€ Rust

Commit count: 0

cargo fmt