Brylix
A Rust framework for building GraphQL APIs on AWS Lambda with SeaORM and multi-tenant support.
Features
- GraphQL API - Built on async-graphql with playground support
- AWS Lambda - Optimized for serverless deployment with cargo-lambda
- SeaORM - Type-safe database operations with MySQL/PostgreSQL support
- Multi-tenant - Pool-per-droplet architecture for SaaS applications
- JWT Authentication - Secure token-based authentication with multi-role support
- Validation - Built-in input validation utilities
- Email Provider - SMTP email support with attachments
- S3 Provider - Presigned URL generation for file uploads/downloads
- Pagination - Generic pagination utilities for GraphQL connections
- Helpers - JSON parsing, timestamps, soft delete, and ID parsing utilities
Installation
[]
= "0.2"
Quick Start
use *;
use ;
async
Feature Flags
| Feature | Description | Default |
|---|---|---|
mysql |
MySQL/MariaDB support via sqlx | Yes |
postgres |
PostgreSQL support via sqlx | No |
playground |
GraphQL Playground IDE | Yes |
multi-tenant |
Multi-tenant support | No |
email |
SMTP email with attachments | No |
s3 |
S3 presigned URLs for file uploads | No |
full |
All features enabled | No |
# PostgreSQL instead of MySQL
= { = "0.2", = false, = ["postgres", "playground"] }
# Multi-tenant support
= { = "0.2", = ["multi-tenant"] }
# Email support
= { = "0.2", = ["email"] }
# S3 presigned URLs
= { = "0.2", = ["s3"] }
Utilities
Pagination
use *;
// In a resolver:
async
// Or use IntoConnection trait with (Vec<T>, u64) tuples:
let result: = ;
let connection = result.into_connection;
GraphQL ID Parsing
use *;
// Parse string IDs to i64
let user_id = parse_gql_id?; // Ok(123)
let id = parse_gql_id_field?; // Custom error field name
// Or use the macro
let id = gql_id!;
let id = gql_id!;
JSON Column Helpers
use *;
use json;
// Parse JSON database columns into typed structs
let json_col: = Some;
let parsed: = json_col.parse_as;
let with_default: = json_col.parse_or_default;
Timestamp Helpers
use *;
let now = utc_now; // chrono::DateTime<Utc>
// Implement Timestamped for your ActiveModel:
let mut model = ActiveModel ;
model.set_timestamps; // Sets both created_at and updated_at
Soft Delete
use *;
// Use status constants
let active = ACTIVE; // "active"
let deleted = DELETED; // "deleted"
// Implement SoftDeletable for your models
Multi-Role Authentication
use *;
// Configure multiple JWT secrets
let jwt_config = new
.add_role
.add_role;
// Validate token to determine role
let role = jwt_config.validate; // Option<AuthRole>
// Set role in context
let ctx = single_tenant;
// Use guards in resolvers
let admin_id = require_admin?; // Errors if not admin
let role = get_auth_role; // Option<&AuthRole>
Environment Variables
# Required
DATABASE_URL=mysql://user:password@host/database
JWT_SECRET=your-secret-key
JWT_EXP_DAYS=7
# Email (optional, requires `email` feature)
SMTP_HOST=smtp.example.com
SMTP_PORT=465
SMTP_USER=your-email@example.com
SMTP_PASSWORD=your-password
SMTP_FROM_NAME=Your App Name
SMTP_FROM_EMAIL=noreply@example.com
# S3 (optional, requires `s3` feature)
S3_BUCKET=my-bucket-name
S3_REGION=us-east-1
S3_UPLOAD_EXPIRES_SECS=3600
S3_DOWNLOAD_EXPIRES_SECS=3600
# Custom credentials for local development (optional)
# If not set, falls back to default AWS credential chain (IAM role for Lambda)
S3_ACCESS_KEY_ID=your-access-key
S3_SECRET_ACCESS_KEY=your-secret-key
Documentation
Full documentation is available at docs.rs/brylix.
License
Licensed under either of Apache License 2.0 or MIT License at your option.