Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions docs/codebase-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,19 @@ All modules include comprehensive `//!` documentation with:

### Core Infrastructure

**Bootstrap Module:**

Application initialization and lifecycle management:

- ✅ `src/bootstrap/mod.rs` - Bootstrap module root with re-exports
- ✅ `src/bootstrap/app.rs` - Main application bootstrap and entry point logic
- ✅ `src/bootstrap/container.rs` - Dependency injection container (Services)
- ✅ `src/bootstrap/help.rs` - Help and usage information display
- ✅ `src/bootstrap/logging.rs` - Logging configuration and utilities

**Root Level Files:**

- ✅ `src/main.rs` - Main binary entry point
- ✅ `src/container.rs` - Dependency injection container
- ✅ `src/logging.rs` - Logging configuration and utilities
- ✅ `src/lib.rs` - Library root module

**Binary Files:**
Expand Down Expand Up @@ -359,20 +367,28 @@ Generic utilities used across all layers:
- ✅ `src/shared/command/mod.rs` - Command execution utilities (used by all adapters)
- ✅ `src/shared/clock.rs` - Time abstraction for deterministic testing
- ✅ `src/shared/error/mod.rs` - Shared error types
- ✅ `src/shared/port_checker.rs` - Network port checking
- ✅ `src/shared/port_usage_checker.rs` - Port usage validation
- ✅ `src/shared/username.rs` - Username value object

Note: SSH and Docker adapters have been moved to `src/adapters/`
Note: SSH and Docker adapters have been moved to `src/adapters/`. Network testing utilities (port_checker, port_usage_checker) have been moved to `src/testing/network/`.

### Testing Infrastructure

**E2E Testing Framework:**

- ✅ `src/e2e/mod.rs` - E2E testing framework coordination
- ✅ `src/e2e/containers/mod.rs` - Container-based testing infrastructure
- ✅ `src/e2e/containers/actions/` - E2E test actions
- ✅ `src/e2e/containers/provisioned.rs` - Provisioned container management
- ✅ `src/testing/mod.rs` - Testing framework root module
- ✅ `src/testing/e2e/mod.rs` - E2E testing framework coordination
- ✅ `src/testing/e2e/containers/mod.rs` - Container-based testing infrastructure
- ✅ `src/testing/e2e/containers/actions/` - E2E test actions
- ✅ `src/testing/e2e/containers/provisioned.rs` - Provisioned container management
- ✅ `src/testing/integration/` - Integration testing utilities
- ✅ `src/testing/fixtures.rs` - Reusable test fixtures
- ✅ `src/testing/mock_clock.rs` - Mock clock implementation for deterministic testing

**Network Testing Utilities:**

- ✅ `src/testing/network/mod.rs` - Network testing utilities root
- ✅ `src/testing/network/port_checker.rs` - TCP port connectivity checking
- ✅ `src/testing/network/port_usage_checker.rs` - Port usage validation and process identification

**Configuration:**

Expand Down
2 changes: 1 addition & 1 deletion src/bin/e2e_config_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ use torrust_tracker_deployer_lib::testing::e2e::tasks::run_configure_command::ru
use tracing::{error, info};

use torrust_tracker_deployer_lib::adapters::ssh::{SshCredentials, DEFAULT_SSH_PORT};
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingBuilder};
use torrust_tracker_deployer_lib::domain::{Environment, EnvironmentName};
use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingBuilder};
use torrust_tracker_deployer_lib::shared::Username;
use torrust_tracker_deployer_lib::testing::e2e::context::{TestContext, TestContextType};
use torrust_tracker_deployer_lib::testing::e2e::tasks::{
Expand Down
2 changes: 1 addition & 1 deletion src/bin/e2e_provision_and_destroy_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ use tracing::{error, info};

// Import E2E testing infrastructure
use torrust_tracker_deployer_lib::adapters::ssh::{SshCredentials, DEFAULT_SSH_PORT};
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingBuilder};
use torrust_tracker_deployer_lib::domain::{Environment, EnvironmentName};
use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingBuilder};
use torrust_tracker_deployer_lib::shared::Username;
use torrust_tracker_deployer_lib::testing::e2e::context::{TestContext, TestContextType};
use torrust_tracker_deployer_lib::testing::e2e::tasks::virtual_machine::{
Expand Down
2 changes: 1 addition & 1 deletion src/bin/e2e_tests_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ use tracing::{error, info};

// Import E2E testing infrastructure
use torrust_tracker_deployer_lib::adapters::ssh::DEFAULT_SSH_PORT;
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingBuilder};
use torrust_tracker_deployer_lib::infrastructure::persistence::repository_factory::RepositoryFactory;
use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingBuilder};
use torrust_tracker_deployer_lib::shared::{Clock, SystemClock};
use torrust_tracker_deployer_lib::testing::e2e::context::{TestContext, TestContextType};
use torrust_tracker_deployer_lib::testing::e2e::tasks::{
Expand Down
2 changes: 1 addition & 1 deletion src/bin/test_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use std::path::PathBuf;

use clap::Parser;
use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingBuilder};
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingBuilder};
use tracing::{debug, error, info, trace, warn};

#[derive(Parser)]
Expand Down
6 changes: 3 additions & 3 deletions src/app.rs → src/bootstrap/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use clap::Parser;
use tracing::info;

use torrust_tracker_deployer_lib::{help, logging, presentation};
use crate::{bootstrap, presentation};

/// Main application entry point
///
Expand All @@ -42,7 +42,7 @@ pub fn run() {

let logging_config = cli.global.logging_config();

logging::init_subscriber(logging_config);
bootstrap::logging::init_subscriber(logging_config);

info!(
app = "torrust-tracker-deployer",
Expand All @@ -62,7 +62,7 @@ pub fn run() {
}
}
None => {
help::display_getting_started();
bootstrap::help::display_getting_started();
}
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions src/bootstrap/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Bootstrap Module
//!
//! This module contains application initialization and bootstrap concerns.
//! It handles application lifecycle, dependency injection, logging setup,
//! and help display.
//!
//! ## Modules
//!
//! - `app` - Main application bootstrap and entry point logic
//! - `container` - Service container for dependency injection
//! - `help` - Help and usage information display
//! - `logging` - Logging configuration and initialization

pub mod app;
pub mod container;
pub mod help;
pub mod logging;

// Re-export commonly used types for convenience
pub use container::Services;
pub use logging::{LogFormat, LogOutput, LoggingBuilder, LoggingConfig};
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::path::PathBuf;
/// Centralizes all deployment-related configuration including file paths,
/// service connection details, and runtime behavior settings.
///
/// Created once at deployment start and passed to [`Services::new()`](crate::container::Services::new).
/// Created once at deployment start and passed to [`Services::new()`](crate::bootstrap::container::Services::new).
pub struct Config {
/// Directory containing template files for rendering configurations.
///
Expand Down
8 changes: 2 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@
//!
//! ## Other Modules
//! - `adapters` - External tool adapters (thin CLI wrappers)
//! - `bootstrap` - Application initialization and bootstrap concerns
//! - `config` - Configuration management for deployment environments
//! - `container` - Service container for dependency injection
//! - `help` - Help and usage information display functions
//! - `logging` - Logging configuration and utilities
//! - `shared` - Shared modules used across different layers
//! - `testing` - Testing utilities (unit, integration, and end-to-end)

pub mod adapters;
pub mod application;
pub mod bootstrap;
pub mod config;
pub mod container;
pub mod domain;
pub mod help;
pub mod infrastructure;
pub mod logging;
pub mod presentation;
pub mod shared;
pub mod testing;
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Main binary entry point for Torrust Tracker Deployer.
//!
//! This binary provides the main CLI interface for the deployment infrastructure.
//! All application logic is contained in the `app` module.
//! All application logic is contained in the `bootstrap::app` module.

mod app;
use torrust_tracker_deployer_lib::bootstrap;

fn main() {
app::run();
bootstrap::app::run();
}
2 changes: 1 addition & 1 deletion src/presentation/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::path::PathBuf;

use crate::logging::{LogFormat, LogOutput, LoggingConfig};
use crate::bootstrap::logging::{LogFormat, LogOutput, LoggingConfig};

/// Global CLI arguments for logging configuration
///
Expand Down
4 changes: 0 additions & 4 deletions src/shared/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
pub mod clock;
pub mod command;
pub mod error;
pub mod port_checker;
pub mod port_usage_checker;
pub mod username;

// Re-export commonly used types for convenience
pub use clock::{Clock, SystemClock};
pub use command::{CommandError, CommandExecutor, CommandResult};
pub use error::{ErrorKind, Traceable};
pub use port_checker::{PortChecker, PortCheckerError};
pub use port_usage_checker::{PortUsageChecker, PortUsageError};
pub use username::{Username, UsernameError};
2 changes: 1 addition & 1 deletion src/testing/e2e/containers/actions/ssh_wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use std::time::{Duration, Instant};
use tracing::{debug, info, warn};

use crate::adapters::ssh::SshServiceChecker;
use crate::shared::PortChecker;
use crate::testing::network::PortChecker;

/// Specific error types for SSH wait operations
#[derive(Debug, thiserror::Error)]
Expand Down
2 changes: 1 addition & 1 deletion src/testing/e2e/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
use tempfile::TempDir;
use tracing::{info, warn};

use crate::bootstrap::container::Services;
use crate::config::Config;
use crate::container::Services;
use crate::domain::environment::state::AnyEnvironmentState;
use crate::domain::Environment;
use crate::infrastructure::external_tools::tofu::OPENTOFU_SUBFOLDER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use tracing::info;

use crate::adapters::ssh::SshCredentials;
use crate::application::steps::RenderAnsibleTemplatesStep;
use crate::container::Services;
use crate::bootstrap::container::Services;
use crate::infrastructure::external_tools::ansible::AnsibleTemplateRenderer;
use crate::testing::e2e::containers::actions::{SshKeySetupAction, SshWaitAction};
use crate::testing::e2e::containers::timeout::ContainerTimeouts;
Expand Down
2 changes: 1 addition & 1 deletion src/testing/integration/ssh_server/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::sync::Arc;

use crate::adapters::docker::DockerClient;
use crate::shared::port_usage_checker::PortUsageChecker;
use crate::testing::network::PortUsageChecker;

// Import constants only for the convenience function
use super::constants::{SSH_SERVER_IMAGE_NAME, SSH_SERVER_IMAGE_TAG};
Expand Down
3 changes: 3 additions & 0 deletions src/testing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
//! - `integration` - Integration testing utilities
//! - `fixtures` - Reusable test fixtures
//! - `mock_clock` - Mock clock implementation for deterministic time testing
//! - `network` - Network testing utilities (port checking, connectivity testing)

pub mod e2e;
pub mod fixtures;
pub mod integration;
pub mod mock_clock;
pub mod network;

// Re-export commonly used testing types
pub use mock_clock::MockClock;
pub use network::{PortChecker, PortCheckerError, PortUsageChecker, PortUsageError};

// Re-export E2E types for convenience
pub use e2e::{
Expand Down
17 changes: 17 additions & 0 deletions src/testing/network/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Network Testing Utilities
//!
//! This module provides network-related testing utilities for checking port
//! connectivity and port usage. These utilities are used exclusively in tests
//! to verify network connectivity and diagnose port conflicts.
//!
//! ## Modules
//!
//! - `port_checker` - TCP port connectivity checking
//! - `port_usage_checker` - Port usage and process identification

pub mod port_checker;
pub mod port_usage_checker;

// Re-export commonly used types for convenience
pub use port_checker::{PortChecker, PortCheckerError};
pub use port_usage_checker::{PortUsageChecker, PortUsageError};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! ```rust,no_run
//! use std::net::{SocketAddr, IpAddr, Ipv4Addr};
//! use std::time::Duration;
//! use torrust_tracker_deployer_lib::shared::PortChecker;
//! use torrust_tracker_deployer_lib::testing::network::PortChecker;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let checker = PortChecker::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This module provides functionality to check which processes are using specific ports
//! on the system. It uses system commands like `netstat` or `ss` to query port usage.
//!
//! This is different from [`crate::shared::port_checker`] which checks TCP connectivity
//! This is different from [`crate::testing::network::port_checker`] which checks TCP connectivity
//! to a port. This module checks which process is actually bound to a port.

use thiserror::Error;
Expand All @@ -22,7 +22,7 @@ use crate::adapters::network::{NetstatClient, NetworkError, SsClient};
/// # Example
///
/// ```rust,no_run
/// use torrust_tracker_deployer_lib::shared::port_usage_checker::PortUsageChecker;
/// use torrust_tracker_deployer_lib::testing::network::PortUsageChecker;
///
/// // Check if port 22 is in use
/// match PortUsageChecker::check_port(22) {
Expand Down Expand Up @@ -61,7 +61,7 @@ impl PortUsageChecker {
/// # Example
///
/// ```rust,no_run
/// use torrust_tracker_deployer_lib::shared::port_usage_checker::PortUsageChecker;
/// use torrust_tracker_deployer_lib::testing::network::PortUsageChecker;
///
/// match PortUsageChecker::check_port(8080) {
/// Ok(lines) => {
Expand Down Expand Up @@ -217,7 +217,7 @@ impl PortUsageError {
/// # Example
///
/// ```rust,no_run
/// use torrust_tracker_deployer_lib::shared::port_usage_checker::PortUsageChecker;
/// use torrust_tracker_deployer_lib::testing::network::PortUsageChecker;
///
/// if let Err(e) = PortUsageChecker::check_port(8080) {
/// eprintln!("Error: {e}");
Expand Down
2 changes: 1 addition & 1 deletion tests/logging_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::fs;
use std::path::PathBuf;
use std::process::Command;
use tempfile::TempDir;
use torrust_tracker_deployer_lib::logging::LOG_FILE_NAME;
use torrust_tracker_deployer_lib::bootstrap::logging::LOG_FILE_NAME;

/// Helper struct to manage test execution and cleanup
struct LoggingTest {
Expand Down
Loading