Expand description
Domain Layer Marker Traits
This module provides marker traits for enforcing domain-driven design boundaries
at compile time. Types marked with these traits are guaranteed to be free of
infrastructure dependencies (sqlx, sea_orm, http, axum, etc.).
§Usage
Use the #[domain_model] attribute macro to mark domain types:
ⓘ
use modkit_macros::domain_model;
#[domain_model]
pub struct User {
pub id: Uuid,
pub email: String,
pub created_at: DateTime<Utc>,
}The macro will:
- Implement
DomainModelfor the type - Validate at macro-expansion time that all fields are free of infrastructure types
- Generate clear error messages if forbidden types are detected
§Enforcement
Domain services can use trait bounds to ensure they only work with domain types:
ⓘ
pub trait UserRepository: Send + Sync {
type Model: DomainModel;
async fn find(&self, id: Uuid) -> Result<Option<Self::Model>>;
}§Validation Strategy
The #[domain_model] macro performs validation by checking field type names against
a list of forbidden patterns (e.g., sqlx::, http::, sea_orm::). This provides
clear error messages at macro expansion time, similar to how #[api_dto] validates
its arguments.
Additional enforcement is provided by Dylint lints:
DE0301: Prohibits infrastructure imports in domain layerDE0308: Prohibits HTTP types in domain layer
Traits§
- Domain
Error Marker - Marker trait for domain errors.
- Domain
Model - Marker trait for domain models (business entities).