Bloom (Rust, Actix-Web, SQLx)
A lightweight backend framework that focuses on developer ergonomics by combining:
- Actix-Web for high‑performance HTTP
- SQLx (MySQL) for async, compile‑time checked database access
- Declarative macros to auto‑register controllers/routes, entities/migrations, and scheduled jobs
- Inventory-based discovery: drop in code, it self-registers
- Optional OpenAPI generation and Swagger UI via utoipa
- Simple, timestamped logging macro
- Config-first setup using a TOML file (config.toml)
Features
- Convention-over-configuration controller macro: implement methods and have routes auto-wired
- Route mapping macros (get_mapping, post_mapping, put_mapping, delete_mapping, patch_mapping)
- Entity derive macro that can generate basic migration SQL and CRUD helper bindings
- Repository attribute macro to generate common CRUD helpers for an entity
- Inventory registries for:
- Controllers (auto-configured onto Actix service)
- Entities/migrations (run at boot)
- Scheduled jobs (spawned on boot)
- Built-in optional Swagger UI and OpenAPI JSON
- Flexible CORS controlled via config.toml
Architecture
The Bloom framework consists of three main components:
1. bloom-core
Contains the core framework functionality:
- Application builder and configuration
- Entity registry for database models
- Controller registry for HTTP handlers
- Swagger documentation generation
- Scheduler for background tasks
- Logging utilities
2. bloom-macros
Procedural macros for code generation:
#[derive(Entity)]
- Generates database entity code#[get_mapping]
,#[put_mapping]
, etc. - HTTP route mapping#[repository(Entity)]
- Repository pattern implementation#[scheduled(interval)]
- Background job scheduling
3. bloom
(main crate)
The unified API that ties everything together:
- Re-exports all functionality from sub-crates
- Provides convenient prelude module
- Main entry point for users
Quick Start
-
Configure your database and server port in config.toml at the repository root:
= 8080 = "mysql://user:pass@host:3306/dbname" [] = true = ["http://localhost:3000"] = ["GET", "POST", "PUT", "DELETE", "PATCH"] = ["Content-Type", "Authorization"] = true = 3600
2. Create your first entity
use *;
3. Create a repository
;
4. Add REST endpoints
pub async
pub async
5. Set up your application
use application;
async
Requirements
- Rust toolchain (stable)
- MySQL compatible database
Entity Attributes
The #[derive(Entity)]
macro supports various attributes:
Table Configuration
Field Configuration
Relationships
HTTP Route Mapping
Available route mapping macros:
#[get_mapping("/path")]
#[post_mapping("/path")]
#[put_mapping("/path")]
#[delete_mapping("/path")]
#[patch_mapping("/path")]
Path Parameters
pub async
JSON Payloads
pub async
Repository Pattern
The #[repository(Entity)]
macro generates common CRUD operations:
;
// Generated methods:
// - find_all_raw(pool) -> Result<Vec<MySqlRow>>
// - find_by_id_raw(pool, id) -> Result<Option<MySqlRow>>
// - exists_by_id(pool, id) -> Result<bool>
// - count(pool) -> Result<i64>
// - delete_by_id(pool, id) -> Result<u64>
// - create(pool, entity) -> Result<u64>
// - update(pool, entity) -> Result<u64>
// - insert_or_update(pool, entity) -> Result<u64>
Scheduled Jobs
// Run every 60 seconds
pub async
OpenAPI/Swagger Integration
// Add to your struct for automatic API documentation
Access Swagger UI at: http://localhost:8080/swagger-ui/
Configuration
Building and Testing
Build the project
Run tests
Build documentation
Check the project
Advanced Features
Complex Entity Relationships
Auto-Registration System
All components use Rust's inventory
crate for automatic registration:
- Entities automatically register their table creation functions
- Routes automatically register with the HTTP server
- Repositories are automatically available
- Scheduled jobs automatically start on server boot
No manual configuration required - just add the macros and everything works!
Production Notes
Performance
- Built on Actix-Web, one of the fastest Rust web frameworks
- Compile-time SQL validation with SQLx
- Zero-cost abstractions through procedural macros
Security
- Type-safe SQL queries prevent injection attacks
- Compile-time verification of database schemas
- Proper error handling with Result types
Deployment
# Build optimized release version
# The binary will be in target/release/
This project is licensed under the MIT License - see the LICENSE file for details.