Files
sta/backend/src/application/mod.rs
Lucien Cartier-Tilet 5287baadbb feat(application): implement US1 relay control use cases
Add GetAllRelaysUseCase (T043) for retrieving all 8 relay states with
labels, coordinating controller reads and repository label lookups
with comprehensive error handling and logging.

Implement ToggleRelayUseCase (T041) for toggling individual relay
states with read-before-write pattern, state validation, and label
retrieval.

Add use_cases module (T044) with trait-based dependency injection for
testability, exposing both use cases for presentation layer
integration.

Comprehensive test coverage includes 7 toggle tests (state
transitions, error handling, double-toggle idempotency) and 9 get-all
tests (count, ordering, state correctness, label inclusion, error
scenarios).

Ref: T041 T042 T043 T044 (specs/001-modbus-relay-control/tasks.org)
2026-03-04 12:27:19 +01:00

69 lines
2.5 KiB
Rust

//! Application layer - Use cases and orchestration logic
//!
//! This module implements business use cases by coordinating domain entities and
//! infrastructure services. It contains the application logic that orchestrates
//! domain behavior without implementing domain rules directly.
//!
//! # Architecture Principles
//!
//! - **Depends on Domain layer**: Uses domain entities, value objects, and traits
//! - **Framework-independent**: No dependencies on HTTP, database, or other infrastructure
//! - **Use case driven**: Each module represents a specific business use case
//! - **Testable in isolation**: Can be tested with mock infrastructure implementations
//!
//! # Submodules
//!
//! - `health`: Health monitoring service
//! - `health_monitor`: Tracks system health status and state transitions
//!
//! # Planned Submodules
//!
//! - `relay`: Relay control use cases
//! - `get_status`: Retrieve current state of one or all relays
//! - `toggle_relay`: Switch relay on/off with validation
//! - `bulk_control`: Control multiple relays (all on, all off, pattern)
//! - `update_label`: Manage relay labels with persistence
//! - `get_health`: Check device health and connectivity
//!
//! # Use Case Pattern
//!
//! Each use case follows this pattern:
//! 1. Accept domain types as input (validated at boundary)
//! 2. Orchestrate domain entities and services
//! 3. Return domain types or application-specific results
//! 4. Depend on traits (RelayController, RelayLabelRepository), not concrete types
//!
//! # Example Use Case Structure
//!
//! ```rust,ignore
//! pub struct ToggleRelay {
//! controller: Arc<dyn RelayController>,
//! repository: Arc<dyn RelayLabelRepository>,
//! }
//!
//! impl ToggleRelay {
//! pub async fn execute(&self, relay_id: RelayId) -> Result<Relay, ApplicationError> {
//! // 1. Read current state
//! let current = self.controller.read_relay_state(relay_id).await?;
//!
//! // 2. Toggle state (domain logic)
//! let new_state = current.toggle();
//!
//! // 3. Write new state
//! self.controller.write_relay_state(relay_id, new_state).await?;
//!
//! // 4. Return updated relay
//! Ok(Relay::new(relay_id, new_state))
//! }
//! }
//! ```
//!
//! # References
//!
//! - Architecture: `specs/constitution.md` - Hexagonal Architecture principles
//! - Use cases: `specs/001-modbus-relay-control/plan.md` - Implementation plan
//! - Domain types: [`crate::domain`] - Domain entities and value objects
pub mod health;
pub mod use_cases;