rust-saas-boilerplate

Crates.iorust-saas-boilerplate
lib.rsrust-saas-boilerplate
version0.1.0
created_at2026-01-22 18:58:38.752947+00
updated_at2026-01-22 18:58:38.752947+00
descriptionProduction-grade Rust SaaS boilerplate - A complete starter template for building SaaS applications with authentication, user management, and more
homepage
repositoryhttps://github.com/HardikKSavaliya/rust-saas-backend
max_upload_size
id2062379
size68,981
Hardik Savaliya (HardikKSavaliya)

documentation

README

Rust SaaS Boilerplate

A production-grade, modular Rust SaaS boilerplate - A complete starter template for building SaaS applications using Axum, PostgreSQL, SeaORM, JWT authentication, and Stripe billing.

This boilerplate is designed to:

  • Serve as a complete SaaS application starter template
  • Be interview-ready for Rust backend roles
  • Scale cleanly to multi-tenant, subscription-based products
  • Power real products like 100daysofchallenge.io
  • Act as a boilerplate similar to ABP (ASP.NET Boilerplate) for Rust

๐Ÿš€ Features

  • โœ… REST API using Axum
  • โœ… JWT-based authentication (access + refresh tokens)
  • โœ… Secure password hashing (Argon2)
  • โœ… PostgreSQL with SeaORM
  • โœ… Modular domain-driven architecture
  • โœ… Role-based access control (RBAC)
  • โœ… Stripe subscriptions & webhooks (optional)
  • โœ… Dockerized deployment
  • โœ… Health checks & structured logging
  • โœ… Ready for Fly.io / Railway / Render

๐Ÿ—๏ธ Architecture

src/
โ”œโ”€โ”€ app.rs
โ”œโ”€โ”€ main.rs
โ”œโ”€โ”€ config/
โ”œโ”€โ”€ db/
โ”œโ”€โ”€ middleware/
โ”œโ”€โ”€ modules/
โ”‚   โ”œโ”€โ”€ auth/
โ”‚   โ”œโ”€โ”€ users/
โ”‚   โ”œโ”€โ”€ billing/
โ”‚   โ”œโ”€โ”€ orgs/
โ”‚   โ””โ”€โ”€ health/
โ””โ”€โ”€ error.rs

Each module follows:

  • handler.rs โ†’ HTTP layer
  • service.rs โ†’ Business logic
  • model.rs โ†’ DB/domain models
  • routes.rs โ†’ Router wiring

๐Ÿ› ๏ธ Tech Stack

Layer Tech
Language Rust
Web Axum
Runtime Tokio
Database PostgreSQL
ORM SeaORM
Auth JWT + Argon2
Billing Stripe
Logging tracing
Deployment Docker

๐Ÿ“ฆ Using as a Package/Boilerplate

This boilerplate can be used as a library dependency in other Rust projects or as a starting point for your SaaS application.

Add to Your Project

[dependencies]
rust-saas-boilerplate = { path = "../rust-saas-boilerplate" }
# Or from git:
# rust-saas-boilerplate = { git = "https://github.com/HardikKSavaliya/rust-saas-backend.git" }

Quick Start

use rust_saas_boilerplate::create_app;

let app = create_app();
// Use in your Axum router

See USAGE.md for detailed usage examples.


โš™๏ธ Getting Started (Standalone Server)

1๏ธโƒฃ Prerequisites

  • Rust 1.75+
  • Docker
  • PostgreSQL (or Docker)

2๏ธโƒฃ Clone & Setup

git clone https://github.com/HardikKSavaliya/rust-saas-backend.git
cd rust-saas-boilerplate
cp .env.example .env

3๏ธโƒฃ Run Database

docker-compose up -d db

4๏ธโƒฃ Run Migrations

# Using sea-orm-cli (install with: cargo install sea-orm-cli)
sea-orm-cli migrate up

5๏ธโƒฃ Start Server

cargo run

Server runs at:

http://localhost:3000

๐Ÿ” Example API

POST /auth/register
POST /auth/login
GET  /users/me
GET  /health

๐Ÿ“ฆ Environment Variables

# Server Configuration
HOST=0.0.0.0
PORT=3000
ENVIRONMENT=development  # or "production"

# Database
DATABASE_URL=postgres://postgres:postgres@localhost:5432/saas

# Authentication
JWT_SECRET=supersecretkey

# Billing (optional)
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...

# Logging (optional - overrides default)
# RUST_LOG=info,rust_saas_boilerplate=debug

Logging Behavior

  • Production (ENVIRONMENT=production): Only ERROR level logs are shown
  • Development (ENVIRONMENT=development): All logs (INFO, DEBUG, etc.) are shown
  • Override: Set RUST_LOG environment variable to override default behavior
  • Errors: ERROR level logs always show in both environments

๐Ÿงช Testing

cargo test

๐Ÿณ Docker

docker build -t rust-saas-boilerplate .
docker run -p 3000:3000 rust-saas-boilerplate

๐Ÿ“ˆ Roadmap

See TODO.md


๐Ÿง  Why This Project

This repo demonstrates:

  • Real-world Rust backend engineering
  • Clean modular architecture
  • Production SaaS patterns (auth, billing, tenancy)
  • Scalable system design

Perfect for:

  • Rust backend interviews
  • SaaS MVPs
  • Startup foundations

๐Ÿ“œ License

MIT


๐Ÿค Contributing

PRs welcome. Fork, branch, commit, and submit.


โญ If this helped you

Give the repo a โญ and feel free to fork it for your own SaaS ideas!

Commit count: 15

cargo fmt