Rust template
A lightweight and flexible project template built with cargo generate. This template is designed to simplify the creation of projects that apply a Vertical Slice Architecture.
cargo install cargo-generate
cargo generate --git https://github.com/MYuitsu/rust-template
Answer the prompts and a new project will be created.
- Install Rust
- Run
cargo run
to build and run service - Install
cargo-make
cargo install cargo-make
project_root/ │ ├── src/ │ ├── main.rs // Entry point for the application │ ├── app.rs // Application setup and configuration │ ├── config.rs // Configuration-related structures and functions │ ├── slices/ // Vertical slices of the application │ │ ├── feature_x/ // A feature slice (e.g., users, orders, etc.) │ │ │ ├── commands/ // CQRS commands for the feature │ │ │ │ ├── create_command.rs │ │ │ │ ├── create_command_handler.rs │ │ │ ├── queries/ // CQRS queries for the feature │ │ │ │ ├── get_by_id.rs │ │ │ │ ├── get_by_id_handler.rs │ │ │ ├── endpoints.rs // Axum endpoints for the feature │ │ │ ├── models.rs // Domain models for the feature │ │ │ ├── traits.rs // Domain models for the feature │ │ │ ├── services.rs // Business logic for the feature │ │ │ ├── repository.rs // Repository for the feature │ │ │ ├── validators.rs // Validators for the feature │ │ │ ├── messages.rs // Messages for the feature │ │ │ ├── tests/ // Tests for the feature │ │ │ │ ├── unit_tests.rs │ │ │ │ ├── integration_tests.rs │ │ ├── feature_y/ // Another feature slice │ │ │ ├── .... │ │ │ ├── infrastructure/ // Infrastructure concerns │ │ ├── migrations/ // Database migrations │ │ │ ├──yyyyddmm-hhMMss-create.sql // Migration SQL script │ │ ├── database.rs // Database connection and management │ │ ├── auth.rs // Integration for authentication │ │ ├── monitoring.rs // Monitoring setup (e.g., Prometheus, Grafana) │ │ └── ... │ │ │ ├── middleware/ // Custom middleware for logging, tracing, etc. │ │ ├── logging.rs │ │ ├── tracing.rs │ │ ├── metrics.rs // Custom middleware for metrics collection │ │ └── ... │ │ │ └── utils/ // Utility modules │ └── ... │ ├── Cargo.toml // Rust package manifest ├── Makefile.toml // Makefile for project ├── Cargo.lock // Lock file for dependencies └── .env // Environment variables for local development
- Using
Vertical Slice Architecture
forarchitecture
level. - Using
Test Driven Development (TDD)
for allbusiness processes
.
This project is a work in progress
Feature | Status |
---|---|
Connect to DB | In Progress |
cargo-make
cargo-make
- Build automation tool for Cargo projects.axum
- A web application framework that focuses on ergonomics and modularity.dotenv
- Library for loading environment variables from.env
files.
testcontainers
- Testcontainers for Rustgrcov
- Code coverage tool for Rust projects.
cargo make coverage
This project is made available under the MIT license. See LICENSE for details.