Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gerust

> 后端框架
Open source

Gerust is a project generator for Rust backend projects. It takes care of the accidental complexity so you can stay focused on what matters.

176 stars0 likes2 views
WebsiteGitHub

About

Gerust is a project generator for Rust backend projects. It takes care of the accidental complexity so you can stay focused on what matters.

Gerust

Gerust provides an architecture and tooling for Rust backend projects. It takes care of the accidental complexity that comes with writing backends with Rust so you can stay focused on the essence of the system you're building:

  • Separating distinct parts of the system into separate crates
  • Organizing files into a logical folder structure
  • Maintaining and running database migrations
  • Isolating test cases that access the database
  • Tracing and error handling
  • and much more

For now, Gerust is just a project generator that creates the files and structure to get you started. There is no runtime dependency on Gerust – all the code that goes into your project remains under your control.

Gerust projects are based on axum and use SQLx and PostgreSQL for data storage (if data storage is used at all).

[!NOTE] This project has been created by Mainmatter.

Check out our landing page if you're looking for Rust consulting or training!

Installation

Gerust can be installed with cargo:

bash
cargo install gerust

Creating a new project

A new project is created with the gerust command, e.g.:

bash
gerust my-app

By default, Gerust will generate an empty project with the complete project structure as described below but without any actual entities, controllers, etc. If you're just getting started looking at Gerust, creating a full project, complete with example implementations of all concepts via --full might be a better starting point:

bash
gerust my-app --full

For projects that do not need database access, there is also the --minimal option that will generate a project without any of the concepts and structure related to database access – no db crate, no sqlx dependency.

Project Structure

Gerust uses Cargo workspaces to separate distinct parts of the system into separate crates:

.
├── cli    // CLI tools for e.g. running DB migrations or generating project files
├── config // Defines the `Config` struct and handles building the configuration from environment-specific TOML files and environment variables
├── db     // Encapsulates database access, migrations, as well as entity definitions and related code (if the project uses a database)
├── macros // Contains macros, e.g. for application tests
└── web    // The web interface as well as tests for it

Let's see what these crates are resonsible for and how they work in detail:

The web crate

The web crate contains the main axum application, providing the web interface of the system. It contains the controllers with the implementations of the exposed endpoints, as well as any middlewares. The web crate also contains the application's main executable, which when starting up, will determine the environment the application runs in, load the configuration, initialize the app state, set up tracing and error handling, and bind the server to the configured interface.

The crate uses a simple folder structure:

web
├── controllers // Controllers implement request handlers for the exposed endpoints
├── middlewares // Tower middlewares for pre-processing requests before they are passed to the request handlers
├── lib.rs      // Code for starting up the server
├── main.rs     // Main entrypoint of the application
├── routes.rs   // Mapping of request handlers to routes
├── state.rs    // Definition and construction of the application state
└── tests       // Application tests

Testing

Application tests that cover the entire stack of the system including middlewares, controller, as well as database access are maintained in the web crate.

Testing backends is typically straight forward: request a particular endpoint with a particular method and potentially query string and/or request body and assert the response is what you expect. However, things become more complicated when the server you're testing uses a database. In your tests, you then need to seed the database with test data to establish a well-defined state for the test. You also need to clean up afterwards or better, use isolated database states for the different tests so they don't interfere with each other. There are several mechanisms for that like transactions, cleanup scripts, etc.

Gerust uses an approach for test isolation that allows parallel execution of tests without adding a ton of complexity: every test runs in its own database. These test-specific databases are automatically created as copies of the main test database and destroyed after the test has completed. All that is made easily available via the [db_test] macro:

…

The concept of changesets as well as the database access utilities like create_task, are explained below.

The db crate

The db crate only exists for projects that use a database and contains all functionality related to database access from entity definitions, functions for reading and writing data, as well as migrations. Gerust uses SQLx and PostgreSQL without any additional ORM on top. Instead, it defines entities as simple structs along with functions for retrieving and persisting those entities. Validations are implemented via changesets that can get applied to or be converted to entities if they are valid:

…

Database queries are checked for correctness at compile time using sqlx's compile-time checked queries.

The crate's folder structure consists of 3 main folders:

db
├── migrations       // Database migrations as plain SQL files
├── src
    ├── entities     // Entity structs, changesets and related functions for retrieving and persisting records (see example above)
    └── test-helpers // Functions for retrieving and persisting records that are only relevant for tests (these are defined behind the `test-helpers` feature)

Test helpers allow to make specific database access functions available only for application tests but not for actual application code. If e.g. the system does not allow for creating new user accounts but tests need to be able to create users, a create_user function could be defined in db/src/test_helpers/users.rs in the db crate.

The config crate

The config crate contains the Config struct that holds all configuration values at runtime as well as code for parsing the configuration based on a hierarchy of TOML files and environment variables. The Config struct contains fields for the server and database configuration (if the application uses a database) and can be extended freely:

rust
#[derive(Deserialize, Clone, Debug)]
pub struct Config {
    pub server: ServerConfig,
    pub database: DatabaseConfig, // The database configuration only exists for projects that use a database
    // add your config settings here…
}

The values for the server and database configuration are read from the APP_SERVER__IP, APP_SERVER__PORT, and APP_DATABASE__URL environment variables. Any application-specific settings are read from app.toml as well as environment-specific file, e.g. production.toml such that settings in the environment-specific files override those in app.toml.

The main files and folders in the crate are:

…

The cli crate

The cli crate contains the db binary for running database operations such as executing migrations (this binary only exists for projects that use a database) as well as the generate binary for generating project files such as entities, controllers, tests, or middlewares. The workspace is configured so that those binaries can be executed with just cargo db and cargo generate:

…
…

You would typically not have to make any changes to the cli crate.

The macros crate

The macros crate contains the implementation of the db_test macro. You would typically not have to make any changes to the cli crate.

Testing & CI

Projects generated by Gerust come with a complete CI setup for GitHub Actions that includes:

  • checking the format of all Rust source files
  • running Clippy on the entire project
  • running all tests in all crates

Gerust development

When making changes to Gerust itself and you'd like to manually test out your changes, you can generate a sandbox app with:

bash
cargo run -- --full my-app

Then edit with your favorite editor:

bash
${EDITOR} my-app

And:

  • Make changes to generated code and test it.
  • Backport changes to gerust
  • Generate new app and validate changes
bash
cargo run -- -f my-new-app

Rinse:

bash
rm -rf my-app my-new-app

[!IMPORTANT] The generated CI configuration uses offline query validation during its Clippy job. On first check-in, and each time the SQL queries in the db crate get updated, ensure cargo db prepare is run.

What's a "Gerust"?

"Gerust" is a play on "Gerüst", the German word for "framework" and Rust – thanks to @skade who had the idea originally and allowed us to use it!

License

Gerust is developed by and © Mainmatter GmbH and contributors. It is released under the MIT License.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustbackendrust

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架