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 |
admin-override |
Temporary admin elevation for POS/kiosk | 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"] }
# Admin override (POS/kiosk temporary admin elevation)
= { = "0.2", = ["admin-override"] }
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>
Admin Override (POS/Kiosk Pattern)
Allows a logged-in user (e.g. cashier) to perform admin-only actions when an admin "taps in"
with a short-lived override token. Requires the admin-override feature.
use *;
// 1. After verifying admin credentials, issue a short-lived token
let config = new
.with_expiry_secs; // 60 seconds default
let token = issue_admin_override_token?;
// 2. Frontend sends both headers for the privileged action:
// Authorization: Bearer <cashier_token>
// X-Admin-Override: <admin_override_token>
// 3. In resolvers, require_admin() works for BOTH scenarios:
async
// 4. Or require BOTH user auth + admin override explicitly:
let = require_auth_with_admin_override?;
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
# Admin Override (optional, requires `admin-override` feature)
ADMIN_JWT_SECRET=your-admin-secret # Same secret used for admin role JWT
ADMIN_OVERRIDE_EXPIRY_SECS=60 # Optional, default 60 seconds
Documentation
Full documentation is available at docs.rs/brylix.
License
Licensed under either of Apache License 2.0 or MIT License at your option.