corteq 0.1.0

Enterprise-grade multi-tenant SaaS framework for Rust with security-first design
Documentation
//! Repository patterns for tenant-scoped data access

pub mod tenant;

use crate::{Result, TenantContext};
use async_trait::async_trait;
use uuid::Uuid;

pub use tenant::TenantRepository;

/// Trait for tenant-scoped repository operations
///
/// This trait ensures all data access operations are scoped to a tenant.
/// Implementations MUST enforce tenant isolation at the database level.
#[async_trait]
pub trait TenantScopedRepository<T>: Send + Sync {
    /// Find an entity by ID within a tenant
    async fn find_by_id(&self, tenant: &TenantContext, id: Uuid) -> Result<Option<T>>;

    /// List all entities for a tenant
    async fn list_by_tenant(&self, tenant: &TenantContext) -> Result<Vec<T>>;

    /// Save an entity (create or update)
    async fn save(&self, tenant: &TenantContext, entity: &T) -> Result<T>;

    /// Delete an entity by ID within a tenant
    async fn delete(&self, tenant: &TenantContext, id: Uuid) -> Result<()>;
}

// Integration tests are in tests/ directory