How aethelflaed/prefix-by-date works
Project type and purpose
• This is a Rust-based CLI utility (with an optional GUI mode) that prefixes filenames by date (and time) according to user options and configurable matchers. It loads configuration from TOML, inspects file metadata, and applies rename operations, logging or notifying the user of changes.
High-level component breakdown
a. Entry & Argument Parsing (application layer)
• src/main.rs
• src/application/cli.rs + arguments.rs + error.rs
b. User Interaction / UI layer
• Text mode: uses cli output in application
• Interactive TEXT or GUI: src/ui/… (gui.rs, window, processing, actions, state, text.rs)
c. Core Processing Engine
• src/processing/… (matcher.rs, log_reporter.rs, notif_reporter.rs, error.rs)
• Delegates to the Matcher submodule
d. Matching & Replacement Logic
• src/matcher/… (pattern.rs, metadata.rs, predetermined_date.rs)
• src/replacement.rs
e. Configuration & File I/O
• files/config.toml and files/prefix-by-date.desktop
• uses standard Rust fs APIs
Relationships & data flows
1. User invokes main → application::cli parses arguments (config dir, mode, verbosity, matcher options, paths).
2. CLI chooses operation mode:
– Batch (just run, print logs to stdout/stderr)
– Interactive text (ui::text + application services)
– GUI (ui::gui modules)
3. Application layer builds a ProcessingRequest and hands it to processing::matcher or processing::log_reporter/notif_reporter.
4. The Processing Engine loads the config (TOML parser), instantiates the correct Matcher(s) from matcher::pattern, matcher::metadata, etc.
5. For each file path:
a. Matcher tests the file (metadata, date patterns)
b. Replacement logic constructs the new file name (prefix-by-date)
c. Reporter modules either log the action or send a desktop notification
d. Actual file rename is executed via the fs layer
6. Results/status bubble back to UI or CLI output, respecting verbosity and error handling.
Architectural patterns & design principles
• Layered architecture separating concerns:
• “application” for argument parsing & program flow
• “ui” for presentation
• “processing” for orchestration
• “matcher” for business logic
• “replacement” as a pure function layer
• Dependency injection by passing config and options structs down the layers
• Error handling with custom error types (error.rs in each module)
• Test harness under src/test and tests/ for unit, integration, and fixture-based tests
Final advice
• Every logical component even if it’s just one file (e.g., replacement.rs).
• To distinguish between the “batch CLI” path and the “interactive” paths.
• Keep labels concise but descriptive; highlight configuration injection at startup.