Rust implementation demo app showcasing the use of Axum web framework for scaffold usage of backend apis built with Axum.
This project is heavily inspired by current realworld axum projects made by launchbadge and JoeyMckenzie.
- Axum server setup
- AWS DynamoDB
- Openapi json generation with Utoipa
- Swagger-ui documentation page generated with Utoipa-swagger
- Github Actions to run tests using Schemathesis
This project follows the controller service repository pattern approach to building backend apis
controllers
- API entrypoints with
server.rs
holding all the routers together - Controllers are to hold their individual routers that will then be nested together in
server.rs
- API entrypoints with
domain
- Place to hold structs relating to parsing data grabbed from our database(
models
) and responses/requests to/from client(view_models
) - Models is where we hold database related structs
- Place to hold structs relating to parsing data grabbed from our database(
repositories
- Database adapters or external adapters such as DynamoDb or RabbitMq should lie here
- Only focus on returning pure data from source
services
- Contains core business logics utilizing repositories
- E.g mutating, sorting, pagination are done here before sending back to the controllers
- Services will be injected into controller handlers with a
/services/service_register.rs
file.
This project doesn't make use of many useful trait usage for the sake of simplicity, which results in being unable to work out mocks easily.
git clone https://github.com/ElvisYong/rust-axum-scaffold.git
cd rust-axum-scaffold
Install Rust
Create an env file according to .env.example
mkdir .env
cargo build
cargo run
cargo test
Build the docker image
docker build -t rust-axum-scaffold .
Run the image according to the environment port that you've opened, and fill up your environments
docker run -p 5000:5000 rust-axum-scaffold . -e YOUR_ENVIRONMENTS