MYuitsu / rust-template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

Table of Contents

Quick Start

cargo install cargo-generate

Create a new project

cargo generate --git https://github.com/MYuitsu/rust-template

Answer the prompts and a new project will be created.

Installation

  • Install Rust
  • Run cargo run to build and run service
  • Install cargo-make
  cargo install cargo-make

Structure of Project

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

The Goals of This Project

Monolithic application

  • Using Vertical Slice Architecture for architecture level.
  • Using Test Driven Development (TDD) for all business processes.

Plan

This project is a work in progress

Feature Status
Connect to DB In Progress

Technologies - Libraries

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.

Testing

Gathering code coverage

  cargo make coverage

Project References & Credits

License

This project is made available under the MIT license. See LICENSE for details.

About

License:MIT License


Languages

Language:Rust 100.0%