Realworld Rust Axum Prisma
This project utilizes Rust with the Axum v0.7 framework along with the Prisma Client Rust to build a realworld application. For Prisma Client Rust ORM, refer to Prisma and Prisma Client Rust Repository for more information.
Prerequisites
Make sure you have the following installed:
- Rust
- Docker
- MySQL
Getting Started
Installation
- Clone this repository.
- Set up your environment variables by creating a
.env
file in the root directory. Use the provided examples in the README as a guide. - Ensure your MySQL server is running.
- Apply migrations
- Generate Prisma Client
If you want to use other databases, you need to change the database URL in the .env
file and change database provider in schema.prisma file. For more information check out Docs.
Running the Application
You can use the provided justfile
for various commands:
just setup
: Apply migrations usingprisma-cli
.just generate
: Generate the Prisma Client usingprisma-cli
.just run
: Run the application usingcargo run
.just watch
: Usecargo watch
to automatically reload the application on file changes.just build
: Build the application using the development profile.just release
: Build the application for release.just test
: Run tests usingcargo test
.
Docker Setup
If you prefer Docker, follow these steps:
-
Build the Docker image:
The Dockerfile includes steps to build the project within a Docker container. Particularly, the
cargo prisma generate
command is used to generate the Prisma Client during the Docker image build process. This command parses the Prisma schema and creates a client tailored to the defined database structure.docker-compose build
-
Start the containers:
docker-compose up
Environment Variables
Ensure your environment variables are appropriately set. Here are some examples:
DATABASE_URL
: MySQL database URL.PORT
: Port on which the application runs.RUST_LOG
: Rust logging level.JWT_SECRET
: Secret key for JWT authentication.MYSQL_ROOT_PASSWORD
: If using docker-compose make sure to set MySQL root password.
⚠️
Important Note
This project cannot be built in release mode using Rust stable toolchain version 1.7.4 (stable-aarch64-apple-darwin
) due to a compilation error with the psl-core
library. However, it can be successfully built in debug mode using this toolchain.
Contributing
Contributions are welcome! Feel free to open issues or pull requests.
License
This project is licensed under the MIT License.