HACKER Q&A
📣 ekusiadadus

How to structure Rust, Axum, and SQLx for clean architecture?


I would like to know the best practices for structuring directories and packages to implement clean architecture using Rust, Axum, and SQLx.

Specifically, I have created a mock-up as shown in the URL below: https://github.com/ekusiadadus/rust-clean-arch

The structure is as follows:

``` . ├── Cargo.lock ├── Cargo.toml ├── Makefile ├── README.md ├── cfn │ ├── Cargo.toml │ └── src │ └── main.rs ├── docker-compose.yml ├── migrations │ └── 20240504184155_create_user.sql └── src ├── application │ ├── Cargo.toml │ └── src │ ├── lib.rs │ ├── session_service.rs │ └── user_service.rs ├── controller │ ├── Cargo.toml │ └── src │ ├── lib.rs │ └── user_controller.rs ├── domain │ ├── Cargo.toml │ └── src │ ├── lib.rs │ ├── repository.rs │ ├── session.rs │ └── user.rs ├── infrastructure │ ├── Cargo.toml │ └── src │ ├── db.rs │ ├── lib.rs │ ├── session_repository.rs │ └── user_repository.rs └── main.rs ```

Please let me know if there is anyone familiar with DDD (Domain-Driven Design) or clean architecture.


  👤 AA-BA-94-2A-56 Accepted Answer ✓
Architecture looks good. I went off the deep end looking into ways to structure Axum projects. I looked into separating services and having them talk to each other with channels.

In the end, the best practice for engineering software is usually to keep it simple. I've had to learn that I'm too often trying to overengineer things, and I end up getting nothing done.


👤 ianpurton
You can check out https://github.com/bionic-gpt/bionic-gpt

Basically I put db in it's own crate then crates for controller and another for pages.

The folders for each section of the web application.