Refactor user_output.rs Module to Folder Structure
Issue: #149
Parent Epic: #102 - User Output Architecture Improvements
Specification: docs/issues/149-refactor-user-output-module-to-folder-structure.md
Overview
The src/presentation/user_output.rs file has grown to 4,226 lines, making it difficult to navigate and maintain. This task refactors the monolithic file into a well-organized folder module structure with focused, cohesive submodules that follow project conventions.
This refactoring improves:
- Discoverability: Clear separation makes it easier to find specific functionality
- Maintainability: Smaller, focused files are easier to understand and modify
- Testability: Tests are co-located with their code using
#[cfg(test)] modules
- Collaboration: Multiple developers can work on different aspects simultaneously
- Code Review: Smaller, focused changes are easier to review
Goals
Proposed Structure
src/presentation/user_output/
├── mod.rs # Public API, re-exports, module documentation
├── core.rs # UserOutput main struct and core impl
├── theme.rs # Theme struct and predefined themes
├── verbosity.rs # VerbosityLevel enum and VerbosityFilter
├── channel.rs # Channel enum
├── traits.rs # OutputMessage, FormatterOverride, OutputSink traits
├── messages/ # Message type implementations
│ ├── mod.rs
│ ├── progress.rs # ProgressMessage + tests
│ ├── success.rs # SuccessMessage + tests
│ ├── warning.rs # WarningMessage + tests
│ ├── error.rs # ErrorMessage + tests
│ ├── result.rs # ResultMessage + tests
│ ├── steps.rs # StepsMessage and builder + tests
│ └── info_block.rs # InfoBlockMessage and builder + tests
├── sinks/ # OutputSink implementations
│ ├── mod.rs
│ ├── standard.rs # StandardSink + tests
│ ├── composite.rs # CompositeSink + tests
│ ├── file.rs # FileSink + tests
│ ├── telemetry.rs # TelemetrySink + tests
│ └── writers.rs # StdoutWriter, StderrWriter wrappers + tests
├── formatters/ # FormatterOverride implementations
│ ├── mod.rs
│ └── json.rs # JsonFormatter + tests
└── test_support.rs # TestWriter, TestUserOutput (shared test utilities)
Note on Test Organization: All tests are unit tests that only depend on types within the user_output module. Following project conventions, they will be co-located with their code using #[cfg(test)] modules within each file. This improves discoverability and maintainability.
Implementation Plan
Phase 1: Create Folder Structure and Core Modules (1-2 hours)
Phase 2: Extract Traits and Core Logic (1-2 hours)
Phase 3: Organize Message Types (2-3 hours)
Phase 4: Organize Sink Implementations (1-2 hours)
Phase 5: Organize Formatters (30 minutes)
Phase 6: Organize Test Infrastructure (30 minutes)
Phase 7: Documentation and Cleanup (30 minutes)
Phase 8: Final Verification (30 minutes)
Acceptance Criteria
Note for Contributors: These criteria define what the PR reviewer will check. Use this as your pre-review checklist before submitting the PR to minimize back-and-forth iterations.
Quality Checks:
Structural Criteria:
Backward Compatibility:
Code Quality:
Testing:
Related Documentation
Estimated Time
8-10 hours total for complete refactoring with testing and documentation
Refactor user_output.rs Module to Folder Structure
Issue: #149
Parent Epic: #102 - User Output Architecture Improvements
Specification: docs/issues/149-refactor-user-output-module-to-folder-structure.md
Overview
The
src/presentation/user_output.rsfile has grown to 4,226 lines, making it difficult to navigate and maintain. This task refactors the monolithic file into a well-organized folder module structure with focused, cohesive submodules that follow project conventions.This refactoring improves:
#[cfg(test)]modulesGoals
user_output.rstouser_output/folder moduleProposed Structure
Note on Test Organization: All tests are unit tests that only depend on types within the
user_outputmodule. Following project conventions, they will be co-located with their code using#[cfg(test)]modules within each file. This improves discoverability and maintainability.Implementation Plan
Phase 1: Create Folder Structure and Core Modules (1-2 hours)
src/presentation/user_output/directorymod.rswith module documentation and structure outlineThemetotheme.rswith tests in#[cfg(test)]moduleVerbosityLevelandVerbosityFiltertoverbosity.rswith tests in#[cfg(test)]moduleChanneltochannel.rswith tests in#[cfg(test)]modulemod.rswith re-exports for backward compatibilityPhase 2: Extract Traits and Core Logic (1-2 hours)
OutputMessage,FormatterOverride,OutputSinktotraits.rsUserOutputstruct and methods tocore.rsmod.rswith re-exportsPhase 3: Organize Message Types (2-3 hours)
messages/subdirectory#[cfg(test)]modules:progress.rs-ProgressMessagewith testssuccess.rs-SuccessMessagewith testswarning.rs-WarningMessagewith testserror.rs-ErrorMessagewith testsresult.rs-ResultMessagewith testssteps.rs-StepsMessage,StepsMessageBuilder, and testsinfo_block.rs-InfoBlockMessage,InfoBlockMessageBuilder, and testsmessages/mod.rswith re-exportsmod.rswith message re-exportsPhase 4: Organize Sink Implementations (1-2 hours)
sinks/subdirectoryStdoutWriterandStderrWritertowriters.rswith tests in#[cfg(test)]modulestandard.rs-StandardSinkwith testscomposite.rs-CompositeSinkwith testsfile.rs-FileSinkwith teststelemetry.rs-TelemetrySinkwith testssinks/mod.rswith re-exportsmod.rswith sink re-exportsPhase 5: Organize Formatters (30 minutes)
formatters/subdirectoryJsonFormattertojson.rswith tests in#[cfg(test)]moduleformatters/mod.rswith re-exportsmod.rswith formatter re-exportsPhase 6: Organize Test Infrastructure (30 minutes)
test_supportmodule totest_support.rstest_supportis accessible for testing in other modulesPhase 7: Documentation and Cleanup (30 minutes)
mod.rsmod.rsfor clarityuser_output.rsfilecargo doc --no-depsPhase 8: Final Verification (30 minutes)
./scripts/pre-commit.shcargo macheteAcceptance Criteria
Quality Checks:
./scripts/pre-commit.shcargo testcargo doc --no-depscargo macheteStructural Criteria:
user_output.rsis converted touser_output/foldermod.rsserves as the public API entry point#[cfg(test)]modulesBackward Compatibility:
UserOutputCode Quality:
Testing:
#[cfg(test)]modules per filetest_support) easily accessibleRelated Documentation
Estimated Time
8-10 hours total for complete refactoring with testing and documentation