create-rust-app

repository·main·Indexed 23 days ago

https://github.com/wulf/create-rust-app

A scaffolding tool for building modern full-stack web applications with a Rust backend (supporting actix-web and poem) and a React frontend. It automates boilerplate through code generation for database models via cargo dsync, TypeScript types via cargo tsync, and React Query hooks via qsync. The tool includes plugins for authentication (local and OIDC), S3 storage, GraphQL, Docker containerization, and OpenAPI documentation with utoipa.

Tokens
18K
Snippets
50
Records
98
Agent score
82%

What's inside create-rust-app

  1. Generate React Query hooks with qsync

    main

    The qsync crate provides a macro-based system to automatically generate React Query hooks for your Rust services. It works by inspecting your service methods and generating corresponding TypeScript hooks for use in your frontend.

    Key Requirements & Assumptions:

    • React Query Version: Last tested with "react-query": "^3.39.3".
    • Data Format: Endpoints must return JSON compatible with fetch(..).json().
    • Routing: The directory structure of your Rust project determines the generated API paths.
    • Macro Ordering: When using web frameworks like actix_web, you must place the #[qsync] attribute above the framework's routing attribute (e.g., #[get("..")]). This is because Rust evaluates macros from the outermost to the innermost, and qsync needs to wrap the method before the framework defines the route.
  2. Run the application in development mode

    main

    Use cargo fullstack to run the entire application in development mode with file watching enabled. The app will be available at http://localhost:3000.

    • Frontend: Changes appear instantly.
    • Backend: Changes require recompilation (handled by cargo-watch).

    If you want to run the app in development mode without watching for file changes, use cargo run instead.

    Debugging Production Builds: To test/debug production-specific code paths while in development, set debug-assertions = true for [profile.dev] in your Cargo.toml.

    cargo fullstack
  3. Install create-rust-app CLI

    main

    To use create-rust-app, you must first install the CLI tool via cargo.

    Prerequisites

    • Rust
    • diesel_cli
      • For SQLite users: If you want to avoid dynamic linking with your system's libsqlite3, use: cargo install diesel_cli --no-default-features --features sqlite-bundled.
    cargo install create-rust-app_cli
  4. Install requirements for Create Rust App

    main

    To use projects bootstrapped with Create Rust App, ensure you have the following installed:

    • Stable Rust: The standard Rust toolchain.
    • Diesel CLI: Required for database management. Install based on your database type:
      • Postgres: cargo install diesel_cli --no-default-features --features postgres
      • SQLite: cargo install diesel_cli --no-default-features --features sqlite-bundled
    • cargo-watch: Required for continuous compilation and the cargo fullstack command.
      • cargo install cargo-watch
    cargo install diesel_cli --no-default-features --features postgres
    cargo install cargo-watch
  5. Quick start: Generate resources for an existing project

    main

    To add new resources (like database models or API endpoints) to an existing project, navigate to your project directory and run the create-rust-app command again to enter the interactive code-generation menu.

    cd ./my-todo-app
    create-rust-app
  6. Quick start: Create a new project

    main

    You can scaffold a new modern Rust + React web application by running the create-rust-app command followed by your desired project name. The CLI will guide you through selecting a backend framework, plugins, and other configurations.

    create-rust-app my-todo-app
  7. Run the website in local development mode

    main

    Start a local development server using yarn start. This command will automatically open a browser window, and most changes will be reflected live via hot reloading without requiring a server restart.

    $ yarn start
  8. Run background tasks with the Tasks Plugin

    main

    The Tasks plugin (supporting actix-web and postgresql) uses the fang crate for background job processing.

    1. Add a task to the queue using create_rust_app::tasks::queue().
    2. Run the task worker using the following command:
    cargo run --bin tasks