Skip to content

Commit 32d5518

Browse files
committed
Merge #60: Reorganize src/ structure: group bootstrap concerns and move network utilities to testing
bf81f0f fix: update doc test imports to use new bootstrap module paths (copilot-swe-agent[bot]) 59b165f docs: update codebase-architecture.md for new module structure (copilot-swe-agent[bot]) 1f320b9 refactor: reorganize src/ structure - move bootstrap and network utilities (copilot-swe-agent[bot]) 8d48c22 Initial plan (copilot-swe-agent[bot]) Pull request description: ## Reorganize src/ structure: bootstrap and testing utilities ✅ Successfully reorganized the src/ directory structure to improve code organization and semantic clarity. ### Changes Summary **1. Created `src/bootstrap/` module** - Groups application initialization concerns: - `app.rs` - Application bootstrap and entry point logic - `container.rs` - Dependency injection container (Services) - `help.rs` - Help and usage information display - `logging.rs` - Logging configuration and initialization - `mod.rs` - Module exports **2. Created `src/testing/network/` module** - Network testing utilities: - `port_checker.rs` - TCP port connectivity checking - `port_usage_checker.rs` - Port usage validation - `mod.rs` - Module exports **3. Updated all imports** across 24 files: - Binary executables (4 files) - Library modules (6 files) - Test infrastructure (6 files) - Presentation layer (1 file) - Documentation (2 files) - Integration test (1 file) **4. Fixed doc test imports** (latest commit): - Updated all doc comments in `bootstrap/logging.rs` to use correct paths - Updated doc comments in `bootstrap/help.rs` - Updated doc comments in `presentation/cli/args.rs` ### Benefits ✨ **Clearer src/ root**: Shows only main architectural layers (DDD + adapters + bootstrap + testing) ✨ **Semantic accuracy**: `shared/` truly contains pure utilities, not infrastructure code ✨ **Better discoverability**: Related bootstrap concerns grouped together ✨ **Honest organization**: Test utilities in `testing/`, not pretending to be shared production code ### Verification - ✅ **200 doc tests pass** - All documentation examples compile correctly - ✅ **987 unit tests pass** - All library tests successful - ✅ **No unused dependencies** - cargo machete clean - ✅ **Clippy clean** - No warnings or errors - ✅ **Build successful** - Compilation passes - ✅ **Documentation updated** - codebase-architecture.md reflects new structure ### File Changes ``` 26 files changed, 108 insertions(+), 59 deletions(-) ``` All acceptance criteria from the issue have been met. The refactoring is complete and all tests pass. <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> ---- *This section details on the original issue you should resolve* <issue_title>Reorganize `src/` structure: group bootstrap concerns and move network utilities to testing</issue_title> <issue_description>### 🎯 Motivation The current `src/` structure has some organizational inconsistencies: 1. **Bootstrap concerns scattered in root**: Files like `app.rs`, `container.rs`, `logging.rs`, and `help.rs` are bootstrap/initialization concerns that clutter the `src/` root alongside the main DDD layers 2. **Port checkers in wrong location**: `port_checker` and `port_usage_checker` are in `shared/` but they: - Are exclusively used in tests (not production code) - Perform infrastructure operations (network I/O) - Don't fit the semantic meaning of "shared utilities" ### 📋 Proposed Changes #### 1. Group Bootstrap Concerns in `src/bootstrap/` Move application initialization and setup files into a dedicated `bootstrap/` folder: ``` src/app.rs → src/bootstrap/app.rs src/container.rs → src/bootstrap/container.rs src/logging.rs → src/bootstrap/logging.rs src/help.rs → src/bootstrap/help.rs ``` **Rationale**: - Groups related concerns together (application lifecycle, DI container, logging setup, help display) - Cleans up `src/` root to show only the main architectural layers - Name "bootstrap" is clear and won't be confused with tracker setup/deployment #### 2. Move Port Checkers to `src/testing/network/` Move network testing utilities from shared to testing: ``` src/shared/port_checker.rs → src/testing/network/port_checker.rs src/shared/port_usage_checker.rs → src/testing/network/port_usage_checker.rs ``` **Rationale**: - These are **test-only utilities** (used exclusively in E2E and integration tests) - They perform **infrastructure operations** (network checks), not pure utility functions - Honest representation of their actual usage and purpose - Can be moved to `src/infrastructure/network/` later if needed in production ### 📊 Before and After **Current Structure**: ``` src/ ├── adapters/ ✅ Good ├── app.rs ⚠️ Bootstrap concern ├── application/ ✅ DDD layer ├── bin/ ✅ Standard location ├── config/ ✅ Configuration ├── container.rs ⚠️ Bootstrap concern ├── domain/ ✅ DDD layer ├── help.rs ⚠️ Bootstrap concern ├── infrastructure/ ✅ DDD layer ├── lib.rs ✅ Library root ├── logging.rs ⚠️ Bootstrap concern ├── main.rs ✅ Entry point ├── presentation/ ✅ DDD layer ├── shared/ ⚠️ Mixing utilities with infrastructure │ ├── clock.rs │ ├── command/ │ ├── error/ │ ├── port_checker.rs ❌ Test-only, infrastructure concern │ ├── port_usage_checker.rs ❌ Test-only, infrastructure concern │ └── username.rs └── testing/ ✅ Test utilities ``` **Proposed Structure**: ``` src/ ├── adapters/ ✅ External tool wrappers ├── application/ ✅ DDD layer ├── bin/ ✅ Binary executables ├── bootstrap/ ✨ NEW: Application initialization │ ├── app.rs │ ├── container.rs │ ├── help.rs │ └── logging.rs ├── config/ ✅ Configuration ├── domain/ ✅ DDD layer ├── infrastructure/ ✅ DDD layer ├── lib.rs ✅ Library root ├── main.rs ✅ Entry point ├── presentation/ ✅ DDD layer ├── shared/ ✅ Pure utilities only │ ├── clock.rs │ ├── command/ │ ├── error/ │ └── username.rs └── testing/ ✅ Test utilities ├── e2e/ ├── fixtures.rs ├── integration/ ├── mock_clock.rs └── network/ ✨ NEW: Network testing utilities ├── mod.rs ├── port_checker.rs └── port_usage_checker.rs ``` ### 🔧 Migration Steps 1. **Create new directories**: - `src/bootstrap/` - `src/testing/network/` 2. **Move bootstrap files**: - Move `app.rs`, `container.rs`, `help.rs`, `logging.rs` to `bootstrap/` - Create `src/bootstrap/mod.rs` with appropriate exports 3. **Move network utilities**: - Move `port_checker.rs` and `port_usage_checker.rs` to `testing/network/` - Create `src/testing/network/mod.rs` with appropriate exports 4. **Update imports** throughout the codebase: - `crate::app` → `crate::bootstrap::app` - `crate::container` → `crate::bootstrap::container` - `crate::logging` → `crate::bootstrap::logging` - `crate::help` → `crate::bootstrap::help` - `crate::shared::PortChecker` → `crate::testing::network::PortChecker` - `crate::shared::port_usage_checker::PortUsageChecker` → `crate::testing::network::PortUsageChecker` 5. **Update module exports** in: - `src/lib.rs` (add `bootstrap`, update `shared` and `testing` exports) - `src/shared/mod.rs` (remove port checker exports) - `src/testing/mod.rs` (add network module) 6. **Update documentation**: - Update `docs/codebase-architecture.m... </details> - Fixes #44 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/torrust/torrust-tracker-deployer/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. Top commit has no ACKs. Tree-SHA512: 038566cc707d35704995da5c7caabdb8b650b63456b87f2ff695febbfbd247285eb80a55fbaacd1d007389023840860a098e304fbe8df640865c6e8cf451e457
2 parents 8599b50 + bf81f0f commit 32d5518

File tree

24 files changed

+101
-52
lines changed

24 files changed

+101
-52
lines changed

docs/codebase-architecture.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,19 @@ All modules include comprehensive `//!` documentation with:
189189

190190
### Core Infrastructure
191191

192+
**Bootstrap Module:**
193+
194+
Application initialization and lifecycle management:
195+
196+
-`src/bootstrap/mod.rs` - Bootstrap module root with re-exports
197+
-`src/bootstrap/app.rs` - Main application bootstrap and entry point logic
198+
-`src/bootstrap/container.rs` - Dependency injection container (Services)
199+
-`src/bootstrap/help.rs` - Help and usage information display
200+
-`src/bootstrap/logging.rs` - Logging configuration and utilities
201+
192202
**Root Level Files:**
193203

194204
-`src/main.rs` - Main binary entry point
195-
-`src/container.rs` - Dependency injection container
196-
-`src/logging.rs` - Logging configuration and utilities
197205
-`src/lib.rs` - Library root module
198206

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

366-
Note: SSH and Docker adapters have been moved to `src/adapters/`
372+
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/`.
367373

368374
### Testing Infrastructure
369375

370376
**E2E Testing Framework:**
371377

372-
-`src/e2e/mod.rs` - E2E testing framework coordination
373-
-`src/e2e/containers/mod.rs` - Container-based testing infrastructure
374-
-`src/e2e/containers/actions/` - E2E test actions
375-
-`src/e2e/containers/provisioned.rs` - Provisioned container management
378+
-`src/testing/mod.rs` - Testing framework root module
379+
-`src/testing/e2e/mod.rs` - E2E testing framework coordination
380+
-`src/testing/e2e/containers/mod.rs` - Container-based testing infrastructure
381+
-`src/testing/e2e/containers/actions/` - E2E test actions
382+
-`src/testing/e2e/containers/provisioned.rs` - Provisioned container management
383+
-`src/testing/integration/` - Integration testing utilities
384+
-`src/testing/fixtures.rs` - Reusable test fixtures
385+
-`src/testing/mock_clock.rs` - Mock clock implementation for deterministic testing
386+
387+
**Network Testing Utilities:**
388+
389+
-`src/testing/network/mod.rs` - Network testing utilities root
390+
-`src/testing/network/port_checker.rs` - TCP port connectivity checking
391+
-`src/testing/network/port_usage_checker.rs` - Port usage validation and process identification
376392

377393
**Configuration:**
378394

src/bin/e2e_config_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ use torrust_tracker_deployer_lib::testing::e2e::tasks::run_configure_command::ru
6565
use tracing::{error, info};
6666

6767
use torrust_tracker_deployer_lib::adapters::ssh::{SshCredentials, DEFAULT_SSH_PORT};
68+
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingBuilder};
6869
use torrust_tracker_deployer_lib::domain::{Environment, EnvironmentName};
69-
use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingBuilder};
7070
use torrust_tracker_deployer_lib::shared::Username;
7171
use torrust_tracker_deployer_lib::testing::e2e::context::{TestContext, TestContextType};
7272
use torrust_tracker_deployer_lib::testing::e2e::tasks::{

src/bin/e2e_provision_and_destroy_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ use tracing::{error, info};
5454

5555
// Import E2E testing infrastructure
5656
use torrust_tracker_deployer_lib::adapters::ssh::{SshCredentials, DEFAULT_SSH_PORT};
57+
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingBuilder};
5758
use torrust_tracker_deployer_lib::domain::{Environment, EnvironmentName};
58-
use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingBuilder};
5959
use torrust_tracker_deployer_lib::shared::Username;
6060
use torrust_tracker_deployer_lib::testing::e2e::context::{TestContext, TestContextType};
6161
use torrust_tracker_deployer_lib::testing::e2e::tasks::virtual_machine::{

src/bin/e2e_tests_full.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ use tracing::{error, info};
6161

6262
// Import E2E testing infrastructure
6363
use torrust_tracker_deployer_lib::adapters::ssh::DEFAULT_SSH_PORT;
64+
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingBuilder};
6465
use torrust_tracker_deployer_lib::infrastructure::persistence::repository_factory::RepositoryFactory;
65-
use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingBuilder};
6666
use torrust_tracker_deployer_lib::shared::{Clock, SystemClock};
6767
use torrust_tracker_deployer_lib::testing::e2e::context::{TestContext, TestContextType};
6868
use torrust_tracker_deployer_lib::testing::e2e::tasks::{

src/bin/test_logging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
use std::path::PathBuf;
3232

3333
use clap::Parser;
34-
use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingBuilder};
34+
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingBuilder};
3535
use tracing::{debug, error, info, trace, warn};
3636

3737
#[derive(Parser)]

src/app.rs renamed to src/bootstrap/app.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use clap::Parser;
2121
use tracing::info;
2222

23-
use torrust_tracker_deployer_lib::{help, logging, presentation};
23+
use crate::{bootstrap, presentation};
2424

2525
/// Main application entry point
2626
///
@@ -42,7 +42,7 @@ pub fn run() {
4242

4343
let logging_config = cli.global.logging_config();
4444

45-
logging::init_subscriber(logging_config);
45+
bootstrap::logging::init_subscriber(logging_config);
4646

4747
info!(
4848
app = "torrust-tracker-deployer",
@@ -62,7 +62,7 @@ pub fn run() {
6262
}
6363
}
6464
None => {
65-
help::display_getting_started();
65+
bootstrap::help::display_getting_started();
6666
}
6767
}
6868

src/help.rs renamed to src/bootstrap/help.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/// # Example
3030
///
3131
/// ```rust
32-
/// use torrust_tracker_deployer_lib::help;
32+
/// use torrust_tracker_deployer_lib::bootstrap::help;
3333
///
3434
/// // Display help when user runs app without arguments
3535
/// help::display_getting_started();
@@ -73,7 +73,7 @@ pub fn display_getting_started() {
7373
/// # Example
7474
///
7575
/// ```rust
76-
/// use torrust_tracker_deployer_lib::help;
76+
/// use torrust_tracker_deployer_lib::bootstrap::help;
7777
///
7878
/// // Display troubleshooting info when user encounters issues
7979
/// help::display_troubleshooting();

src/logging.rs renamed to src/bootstrap/logging.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//!
2828
//! ```rust,no_run
2929
//! use std::path::Path;
30-
//! use torrust_tracker_deployer_lib::logging::{LogOutput, LogFormat, LoggingBuilder};
30+
//! use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, LogFormat, LoggingBuilder};
3131
//!
3232
//! // Flexible builder API
3333
//! LoggingBuilder::new(Path::new("./data/logs"))
@@ -40,7 +40,7 @@
4040
//!
4141
//! ```rust,no_run
4242
//! use std::path::Path;
43-
//! use torrust_tracker_deployer_lib::logging::{LogOutput, init_compact};
43+
//! use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, init_compact};
4444
//!
4545
//! // E2E tests - enable stderr visibility with production log location
4646
//! init_compact(Path::new("./data/logs"), LogOutput::FileAndStderr);
@@ -151,7 +151,7 @@ impl LoggingConfig {
151151
///
152152
/// ```rust,no_run
153153
/// use std::path::Path;
154-
/// use torrust_tracker_deployer_lib::logging::{LogOutput, LogFormat, LoggingBuilder};
154+
/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, LogFormat, LoggingBuilder};
155155
///
156156
/// // Basic usage with defaults (Compact file format, Pretty stderr format, FileAndStderr output)
157157
/// LoggingBuilder::new(Path::new("./data/logs")).init();
@@ -314,7 +314,7 @@ impl LoggingBuilder {
314314
///
315315
/// ```rust,no_run
316316
/// use std::path::PathBuf;
317-
/// use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingConfig, init_subscriber};
317+
/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingConfig, init_subscriber};
318318
///
319319
/// let config = LoggingConfig::new(
320320
/// PathBuf::from("./data/logs"),
@@ -589,7 +589,7 @@ fn create_log_file_appender(log_dir: &Path) -> tracing_appender::non_blocking::N
589589
/// # Example
590590
/// ```rust,no_run
591591
/// use std::path::Path;
592-
/// use torrust_tracker_deployer_lib::logging::{LogOutput, init};
592+
/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, init};
593593
///
594594
/// // E2E tests - enable stderr visibility with production location
595595
/// init(Path::new("./data/logs"), LogOutput::FileAndStderr);
@@ -632,7 +632,7 @@ pub fn init(log_dir: &Path, output: LogOutput) {
632632
/// # Example
633633
/// ```rust,no_run
634634
/// use std::path::Path;
635-
/// use torrust_tracker_deployer_lib::logging::{LogOutput, init_json};
635+
/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, init_json};
636636
///
637637
/// // E2E tests - enable stderr visibility with production location
638638
/// init_json(Path::new("./data/logs"), LogOutput::FileAndStderr);
@@ -675,7 +675,7 @@ pub fn init_json(log_dir: &Path, output: LogOutput) {
675675
/// # Example
676676
/// ```rust,no_run
677677
/// use std::path::Path;
678-
/// use torrust_tracker_deployer_lib::logging::{LogOutput, init_compact};
678+
/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, init_compact};
679679
///
680680
/// // E2E tests - enable stderr visibility with production location
681681
/// init_compact(Path::new("./data/logs"), LogOutput::FileAndStderr);
@@ -716,7 +716,7 @@ pub fn init_compact(log_dir: &Path, output: LogOutput) {
716716
/// # Example
717717
/// ```rust,no_run
718718
/// use std::path::Path;
719-
/// use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, init_with_format};
719+
/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, init_with_format};
720720
///
721721
/// // Initialize with JSON format for E2E tests with production location
722722
/// init_with_format(Path::new("./data/logs"), LogOutput::FileAndStderr, &LogFormat::Json);

src/bootstrap/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Bootstrap Module
2+
//!
3+
//! This module contains application initialization and bootstrap concerns.
4+
//! It handles application lifecycle, dependency injection, logging setup,
5+
//! and help display.
6+
//!
7+
//! ## Modules
8+
//!
9+
//! - `app` - Main application bootstrap and entry point logic
10+
//! - `container` - Service container for dependency injection
11+
//! - `help` - Help and usage information display
12+
//! - `logging` - Logging configuration and initialization
13+
14+
pub mod app;
15+
pub mod container;
16+
pub mod help;
17+
pub mod logging;
18+
19+
// Re-export commonly used types for convenience
20+
pub use container::Services;
21+
pub use logging::{LogFormat, LogOutput, LoggingBuilder, LoggingConfig};

0 commit comments

Comments
 (0)