Giter VIP home page Giter VIP logo

create-rust-app's Introduction

Create Rust App

License: MIT OR Apache-2.0

Set up a modern rust+react web app by running one command. Join us on discord.

create-rust-app.dev

Requirements

  • Rust
  • diesel_cli
    • For SQLite, if you don't wish to dynamically link diesel_cli with your system's libsqlite3, you may run cargo install diesel_cli --no-default-features --features sqlite-bundled.

Install

cargo install create-rust-app_cli

Quick start

create-rust-app my-todo-app
# .. select backend framework, plugins, etc.
# Code-gen resources for your project
cd ./my-todo-app
create-rust-app
# .. select resource type / properties

Features

1. Project creation

create-rust-app create <project_name>
  • Run frontend & backend with a single command: cargo fullstack
  • Rust backend
    • One of the following frameworks: actix-web, poem or let us know which one you want to use!
    • Database migrations (using diesel.rs)
      • Generate diesel structs and types by running cargo dsync in your project (see codegen section below).
    • Sending mail
    • PostgreSQL, SQLite 3.35+ support
    • ViteJS (blazing fast frontend compile speeds)
    • SSR templating with an option to include bundles that are automatically code-split
      • The /views folder contains all templates
      • The /frontend/bundles folder contains all the bundles which can be included in your views via {{bundle(name="MyBundle.tsx")}}
    • Automatically route to your single page application(s)
      • Use create_rust_app::render_single_page_application("/app","your_spa.html")
  • React frontend (or install your own framework!)
    • Typescript, with backend type definition generation (run cargo tsync in your project folder; see codegen section below)
    • Routing (via react-router-dom)
    • Typed react-query hooks generation ($ cd my_project && create-rust-app, then select "Generate react-query hooks")

Available Plugins

  • Authentication (+ Authorization) plugin

    • Add JWT token-based auth with a simple command
    • Session management: restoration of previous session, revoking of refresh tokens
    • Credentials management/recovery
    • Email validation / activation flow
    • Adds frontend UI + react hooks
    • Adds auth service, and user / session models
    • Block your endpoints via Auth guard
    • Follows OWASP security best practices
    • RBAC permissions out of the box (assign roles and permissions to users)
  • Container plugin

    • Dockerfile to containerize your rust app into a single image
  • Development plugin

    • View your database via the admin portal at localhost:3000/admin (still in development)
    • A "devbox" on the frontend indicates when the backend is compiling or when the database is not reachable
    • Moreover, the devbox displays when migrations are pending + includes a "run migrations" button
    • In-browser compilation errors and migration checking:
  • Storage plugin

    • Adds Storage extractor which allows you to upload/download files from an S3-compatible object store

    • Seamlessly add single or multiple attachments to your models using Attachment::*!

    • Here are some examples:

      • Adding an avatar to a user in your users table:
      let s3_key = Attachment::attach("avatar", "users", user_id, AttachmentData {
          file_name: "image.png",
          data: bytes
      })?;
      • Getting the url for the attachment
      let storage: Storage // retreive this via the appropriate extractor in your frameowrk of choice
      let url = storage.download_uri(s3_key)?;

      (note: see Attachment::* and Storage::* for more functionality!)

  • GraphQL plugin

    • Adds all the boilerplate necessary to expose GraphQL
    • Requires the auth plugin: authentication and authorization setup out-of-the-box
    • Find a graphql playground at localhost:3000/graphql
  • Utoipa plugin

    • Uses the utoipa crate to add OpenAPI documentation and serve it in a SwaggerUI playground.
    • Find the playground at localhost:3000/swagger-ui
    • Requires the backend be Actix (for now ;) )
    • check out this page to see how to document your own API endpoints with a variety of backends

2. Code-gen to reduce boilerplate

cargo dsync
  • Run this commmand to generate diesel model structs and queries in your backend/models folder!
  • See dsync docs here
cargo tsync
  • Run this command to generate typescript types for your rust code marked with #[tsync::tsync]. You'll find the output for this command here: frontend/src/types/rust.d.ts.
  • See tsync docs here
cd my_project && create-rust-app
  • CRUD code-gen to reduce boilerplate
    • Scaffolds the db model, endpoints service file, and hooks it up in your /api!
  • react-query hooks generation for frontend
    • Generates a hook for each handler function defined in the services/ folder
    • Edit generated hooks afterwards -- they won't be regenerated unless you delete (or rename) the hook!

Walkthrough (old)

Gif

Contributing

Questions and comments are welcome in the issues section!

If you're experiencing slow compilation time, make sure there isn't any bloat in the template files (look for node_modules or typescript / parcel caches and delete them). Moreover, you can try using the mold linker which may also improve compilation times.

create-rust-app's People

Contributors

anthonymichaeltdm avatar dependabot[bot] avatar gx0r avatar kat-ms avatar liusen-adalab avatar roblperry avatar sansx avatar vishalsodani avatar wulf avatar xbagon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.