Author:
Ruangyot Nanchiang (Lookhin)
This is a simple example of a Rust project using the Clean Architecture principles.
The project is a simple REST API that allows you to record a new item into the database but need to validate the item fisrt in-case of the item is already exist in the database.
here is the flow of the project:
Rust
Axum
SQLx
PostgreSQL
📂rust-clean-architecture-v1/
| 📄.gitignore
| 📄Cargo.lock
| 📄Cargo.toml
| 📄README.md
| 📄Setting.toml
|
+---📂src/
| 📄lib.rs
| 📄main.rs
| 📄setting.rs
| 📄database.rs
| 📄time_helper.rs
|
+---📂entities/
| 📄items.rs
| 📄mod.rs
|
+---📂handlers/
| 📄staff.rs
| 📄mod.rs
|
+---📂models/
| 📄item.rs
| 📄error.rs
| 📄mod.rs
|
+---📂repositories/
| 📄items.rs
| 📄staff.rs
| 📄mod.rs
|
+---📂usecases/
📄staff_test.rs
📄staff.rs
📄mod.rs
- Start the PostgreSQL database
docker pull postgres:alpine
- Create a new PostgreSQL container
docker run --name mygamedb -p 5432:5432 -e POSTGRES_PASSWORD=123456 -d postgres:alpine
- Create a new database
docker exec -it mygamedb bash
psql -U postgres
CREATE DATABASE mygamedb;
- Create a new table
\c mygamedb;
begin;
create table items (
"id" serial primary key,
"name" varchar(64) not null,
"category" varchar(64) not null,
"created_at" timestamp not null,
"updated_at" timestamp not null
);
commit;
- Clone the project
git clone https://github.com/Rayato159/rust-clean-architecture-v1.git
- Install the dependencies
cargo build
- Run the project
cargo run
- Test the project
cargo test