| Crates.io | corteq |
| lib.rs | corteq |
| version | 0.1.0 |
| created_at | 2025-11-21 10:25:29.793885+00 |
| updated_at | 2025-11-21 10:25:29.793885+00 |
| description | Enterprise-grade multi-tenant SaaS framework for Rust with security-first design |
| homepage | https://github.com/Trendium-Labs/corteq |
| repository | https://github.com/Trendium-Labs/corteq |
| max_upload_size | |
| id | 1943372 |
| size | 207,032 |
Enterprise-Grade Multi-Tenant SaaS Framework for Rust
Corteq is a security-first, production-ready framework for building multi-tenant SaaS applications in Rust. Built on Actix Web, it provides comprehensive tenant isolation, authentication, encryption, and compliance features out of the box.
[dependencies]
corteq = "0.1"
actix-web = "4.9"
tokio = { version = "1", features = ["full"] }
use actix_web::{web, App, HttpServer};
use corteq::CorteqApp;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let app_config = CorteqApp::builder()
.with_database("postgres://user:pass@localhost/db")
.with_jwt_secret("your-secret-key-min-32-chars!!")
.build()
.await?;
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(app_config.clone()))
.service(
web::scope("/api")
.wrap(corteq::TenantContextMiddleware)
.route("/data", web::get().to(get_tenant_data))
)
})
.bind("0.0.0.0:8080")?
.run()
.await
}
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTTP Request โ
โ Authorization: Bearer <jwt_token> โ
โโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TenantContextMiddleware โ
โ โข Extracts JWT from Bearer token or Cookie โ
โ โข Validates signature and expiration โ
โ โข Loads tenant context from cache/database โ
โโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Handler Function โ
โ (tenant: TenantExtractor) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TenantDatabase โ
โ โข Begins transaction โ
โ โข Sets app.current_tenant_id session variable โ
โ โข RLS policies automatically filter queries โ
โโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PostgreSQL with RLS Enabled โ
โ โข Row-Level Security enforces tenant isolation โ
โ โข Only returns rows matching current_tenant_id โ
โ โข Blocks INSERT/UPDATE/DELETE for other tenants โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// Automatically filtered by tenant_id
let mut db = TenantDatabase::begin(&pool, &tenant_ctx).await?;
let docs = sqlx::query!("SELECT * FROM documents")
.fetch_all(db.connection())
.await?;
// โ
Only returns documents for current tenant
// Bearer Token
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
// HTTP Cookie (automatically handled)
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
let encryption = EncryptionService::new();
// Encrypt with tenant-specific key
let encrypted = encryption.encrypt(plaintext, &tenant_ctx)?;
let bytes = encrypted.to_bytes(); // Store in database
// Decrypt
let decrypted = encryption.decrypt(&encrypted, &tenant_ctx)?;
.
corteq/ # Framework library crate
โโโ src/
โ โโโ lib.rs # Main library exports
โ โโโ auth.rs # JWT authentication
โ โโโ cache.rs # Tenant caching layer
โ โโโ database/ # RLS database wrapper
โ โโโ domain.rs # Tenant, TenantContext models
โ โโโ encryption.rs # AES-256-GCM encryption
โ โโโ error.rs # Framework error types
โ โโโ middleware.rs # Tenant context middleware
โ โโโ repository/ # Tenant repository
โโโ tests/ # Integration & security tests
cargo doc --open)# All tests
cargo test
# Specific test suite
cargo test --test test_encryption
cargo test --test test_security_critical
cargo test --test test_rls_isolation
# With output
cargo test -- --nocapture
# Integration tests only
cargo test --test '*'
# 1. Clone repository
git clone https://github.com/Trendium-Labs/corteq
cd corteq
# 2. Start PostgreSQL
docker-compose up -d postgres
# 3. Run migrations (automatic on first run)
# Migrations run automatically when CorteqApp::builder().build() is called
# 4. Run demo app
cargo run --bin server
# 5. Test the API
curl http://localhost:3000/health
# Generate demo token
curl -X POST http://localhost:3000/auth/demo-token \
-H "Content-Type: application/json" \
-d '{"tenant_id": "11111111-1111-1111-1111-111111111111"}'
# Use token
curl -H "Authorization: Bearer <token>" \
http://localhost:3000/api/me
Perfect for building:
FROM rust:1.75 AS builder
WORKDIR /app
COPY . .
RUN cargo build --release
FROM debian:bookworm-slim
COPY --from=builder /app/target/release/app /usr/local/bin/
EXPOSE 8080
CMD ["app"]
DATABASE_URL=postgres://user:pass@host:5432/db
JWT_SECRET=your-production-secret-key-min-32-chars!!
RUST_LOG=info
SERVER_PORT=8080
This project is currently in active development. Contributions, issues, and feature requests are welcome!
Licensed under MIT License (LICENSE-MIT)
Built with these amazing technologies:
Built with โค๏ธ by Trendium Labs
โญ Star this repo if you find it useful!