Available on crate feature
di only.Expand description
Clean Architecture enforcement with compile-time dependency injection.
The arch module provides traits and utilities for enforcing Clean Architecture
patterns in your application. Use the #[inject] macro to wire up dependencies.
§Example
ⓘ
use allframe::arch::*;
#[inject]
struct MyService {
repo: Arc<dyn UserRepository>,
}Clean Architecture enforcement
This module provides compile-time and runtime support for Clean Architecture. AllFrame enforces architectural boundaries at compile time, preventing violations like handlers directly accessing repositories.
§Architecture Layers
┌─────────────────────────────────────┐
│ Layer 4: Handler │ ← HTTP/gRPC/GraphQL endpoints
│ (depends on Use Cases) │
└─────────────────────────────────────┘
↓
┌─────────────────────────────────────┐
│ Layer 3: Use Case │ ← Application logic
│ (depends on Repositories, Domain) │
└─────────────────────────────────────┘
↓
┌─────────────────────────────────────┐
│ Layer 2: Repository │ ← Data access
│ (depends on Domain) │
└─────────────────────────────────────┘
↓
┌─────────────────────────────────────┐
│ Layer 1: Domain │ ← Business logic (no deps)
└─────────────────────────────────────┘§Usage
ⓘ
use allframe_core::arch::{domain, repository, use_case, handler};
// Domain entities - pure business logic
#[domain]
struct User {
id: String,
email: String,
}
// Repository - data access
#[repository]
trait UserRepository: Send + Sync {
async fn find(&self, id: &str) -> Option<User>;
}
// Use case - application logic
#[use_case]
struct GetUserUseCase {
repo: Arc<dyn UserRepository>, // ✅ Can depend on repository
}
// Handler - entry point
#[handler]
struct GetUserHandler {
use_case: Arc<GetUserUseCase>, // ✅ Can depend on use case
// repo: Arc<dyn UserRepository>, // ❌ COMPILE ERROR - cannot skip use case!
}Structs§
- Layer
Metadata - Layer metadata for runtime introspection
Attribute Macros§
- domain
- Marks a type as part of the Domain layer (Layer 1)
- handler
- Marks a type as part of the Handler layer (Layer 4)
- repository
- Marks a type as part of the Repository layer (Layer 2)
- use_
case - Marks a type as part of the Use Case layer (Layer 3)