MCPcopy Index your code
hub / github.com/MSC29/clean-architecture-rust

github.com/MSC29/clean-architecture-rust @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
103 symbols 181 edges 63 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Clean architecture: rust

A Clean Architecture template for a Rest API in rust

How it works

Motivations, explanations, requirements & more details in my article Practical Clean Architecture in Typescript, Rust & Python

Installing

cargo build

Database setup

It's currently configured to run with PostgreSQL through Diesel (ORM), but this being clean architecture feel free to change it :)

I suggest

Then install diesel_cli

diesel setup --database-url postgresql://postgres:postgres@localhost/animal_fact_db
diesel migration run --database-url postgresql://postgres:postgres@localhost/animal_fact_db

Running

define the environment on which we're running by adding ENV=<env>, which will use the .env.<env> file

ENV=dev cargo run

Code quality & security

Used in CI/CD

cargo fmt --all -- --check
cargo clippy --all-targets
cargo audit
cargo outdated

Testing

Here's what done in order to mock the SPI

  • db: every test is creating a new database from TestContextPostgreSQL with json fixtures in test/fixtures & spawns the app with this database
  • http: every test also spins up another rust api (if not already up) with the expected routes but test data in test/fixtures
ENV=test cargo test

API Documentation

TODO: https://github.com/paperclip-rs/paperclip

Extension points exported contracts — how you extend this code

AbstractUseCase (Interface)
(no doc) [4 implementers]
src/application/usecases/interfaces.rs
ApiMapper (Interface)
(no doc) [2 implementers]
src/application/mappers/api_mapper.rs
HttpMapper (Interface)
(no doc) [1 implementers]
src/application/mappers/http_mapper.rs
DbMapper (Interface)
(no doc) [1 implementers]
src/application/mappers/db_mapper.rs
DogFactsRepositoryAbstract (Interface)
(no doc) [1 implementers]
src/application/repositories/dog_facts_repository_abstract.rs

Core symbols most depended-on inside this repo

execute
called by 11
src/application/usecases/get_all_cat_facts_usecase.rs
get_pool
called by 6
src/adapters/spi/db/db_connection.rs
spawn_app
called by 4
tests/utils/utils_setup.rs
setup
called by 4
tests/utils/utils_setup.rs
get_error_message
called by 3
src/domain/error.rs
execute
called by 3
src/application/usecases/get_all_dog_facts_usecase.rs
run
called by 2
src/lib.rs
client
called by 2
src/adapters/spi/http/http_connection.rs

Shape

Method 36
Function 33
Class 28
Interface 6

Languages

Rust100%

Modules by API surface

src/application/usecases/get_all_dog_facts_usecase.rs6 symbols
src/application/usecases/get_all_cat_facts_usecase.rs6 symbols
tests/utils/utils_setup.rs5 symbols
src/application/utils/error_handling_utils.rs5 symbols
src/application/usecases/get_one_random_cat_fact_usecase.rs5 symbols
src/application/usecases/get_one_dog_fact_by_id_usecase.rs5 symbols
src/adapters/api/shared/error_presenter.rs5 symbols
src/domain/error.rs4 symbols
tests/utils/test_context.rs3 symbols
src/adapters/spi/http/http_mappers.rs3 symbols
src/adapters/spi/http/http_cat_facts_repository.rs3 symbols
src/adapters/spi/db/db_mappers.rs3 symbols

Datastores touched

animal_fact_dbDatabase · 1 repos

For agents

$ claude mcp add clean-architecture-rust \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact