Skip to content

To implement and experiment how to do clean architecture in Rust Axum + PostgreSQL usin SQLx

Notifications You must be signed in to change notification settings

Rayato159/rust-clean-architecture-v1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Clean Architecture V1

Author: Ruangyot Nanchiang (Lookhin)

Introduction

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:

bussiness_diagram

Tech Stack

  • Rust
  • Axum
  • SQLx
  • PostgreSQL

Project Structure

📂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

  1. Start the PostgreSQL database
docker pull postgres:alpine
  1. Create a new PostgreSQL container
docker run --name mygamedb -p 5432:5432 -e POSTGRES_PASSWORD=123456 -d postgres:alpine
  1. Create a new database
docker exec -it mygamedb bash
psql -U postgres
CREATE DATABASE mygamedb;
  1. 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;

Start the project

  1. Clone the project
git clone https://github.com/Rayato159/rust-clean-architecture-v1.git
  1. Install the dependencies
cargo build
  1. Run the project
cargo run
  1. Test the project
cargo test

About

To implement and experiment how to do clean architecture in Rust Axum + PostgreSQL usin SQLx

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published