torrust_tracker_deployer_lib/application/command_handlers/register/mod.rs
1//! Register Command Module
2//!
3//! This module implements the delivery-agnostic `RegisterCommandHandler`
4//! for registering existing instances with environments.
5//!
6//! ## Architecture
7//!
8//! The `RegisterCommandHandler` implements the Command Pattern and uses Dependency Injection
9//! to interact with infrastructure services through interfaces:
10//!
11//! - **Repository Pattern**: Persists environment state via `EnvironmentRepository`
12//! - **Clock Abstraction**: Provides deterministic time for testing via `Clock` trait
13//! - **Domain-Driven Design**: Uses domain objects from `domain::environment`
14//!
15//! ## Design Principles
16//!
17//! - **Delivery-Agnostic**: Works with CLI, REST API, or any delivery mechanism
18//! - **Asynchronous**: Uses async/await for network operations
19//! - **Explicit State Transitions**: Type-safe state machine for environment lifecycle
20//! - **Explicit Errors**: All errors implement `.help()` with actionable guidance
21//!
22//! ## Register Workflow
23//!
24//! The command handler orchestrates a simple workflow:
25//!
26//! 1. **Load environment** - Retrieve environment in Created state
27//! 2. **Validate SSH connectivity** - Test connection to existing instance
28//! 3. **Update runtime outputs** - Store the instance IP address
29//! 4. **Transition state** - Move from Created to Provisioned
30//!
31//! ## State Management
32//!
33//! The command handler integrates with the type-state pattern for environment lifecycle:
34//!
35//! - Accepts `Environment<Created>` as input
36//! - Returns `Environment<Provisioned>` on success
37//!
38//! This is an alternative path to the `provision` command - both result in
39//! `Environment<Provisioned>` state, but `register` uses existing infrastructure
40//! instead of provisioning new infrastructure.
41
42pub mod errors;
43pub mod handler;
44
45#[cfg(test)]
46mod tests;
47
48// Re-export main types for convenience
49pub use errors::RegisterCommandHandlerError;
50pub use handler::RegisterCommandHandler;