Module commands

Module commands 

Source
Expand description

§Application Commands

This module implements the Command pattern as part of the CQRS (Command Query Responsibility Segregation) architecture. Commands represent operations that change system state and are designed to be immutable, self-contained instructions that can be validated, logged, and executed.

§Overview

Application commands provide:

  • State Modification: Commands represent operations that change system state
  • Validation: Commands can be validated before execution
  • Auditability: Commands provide a clear audit trail of operations
  • Testability: Commands can be easily unit tested in isolation
  • Serialization: Commands can be serialized for queuing or persistence

§CQRS Architecture

§Command Characteristics

Commands in this system have the following characteristics:

  • Immutable: Once created, commands cannot be modified
  • Self-Contained: Commands contain all information needed for execution
  • Validated: Commands are validated before execution
  • Auditable: Commands provide clear operation tracking
  • Asynchronous: Commands can be executed asynchronously

§Command Lifecycle

The typical command lifecycle follows these steps:

  1. Creation: Command is created with required parameters
  2. Validation: Command is validated for correctness
  3. Authorization: User permissions are checked
  4. Execution: Command is executed by appropriate handler
  5. Result: Command execution result is returned
  6. Audit: Command execution is logged for audit trail

§Command Types

§File Restoration Commands

Commands related to restoring files from the pipeline format:

  • RestoreFileCommand: Restore a file from .adapipe format
  • Future commands for batch restoration, selective restoration, etc.

§Usage Patterns

§Basic Command Creation and Execution

§Command Validation

§Command Builder Pattern

§Asynchronous Command Processing

§Best Practices

§Command Design

  • Immutability: Commands should be immutable after creation
  • Self-Validation: Commands should validate their own parameters
  • Rich Information: Include all necessary context in the command
  • Clear Intent: Command names should clearly indicate their purpose

§Error Handling

  • Validation Errors: Catch validation errors before execution
  • Execution Errors: Handle execution failures gracefully
  • Rollback: Design commands to support rollback when possible
  • Audit Trail: Log all command executions for debugging

§Performance

  • Async Execution: Use async patterns for I/O-bound operations
  • Batch Processing: Group related commands for efficiency
  • Resource Management: Properly manage resources during execution
  • Timeout Handling: Implement appropriate timeouts for long operations

§Testing Strategies

§Unit Testing Commands

§Integration Testing

Test commands with real handlers and infrastructure:

Structs§

RestoreFileCommand
Command to restore a file from .adapipe format.
RestoreFileResult
Result of file restoration command