# aethelflaed/prefix-by-date architecture

> Architecture diagram of the GitHub repository aethelflaed/prefix-by-date, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aethelflaed/prefix-by-date
- Repository: https://github.com/aethelflaed/prefix-by-date

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry & Argument Parsing
    subgraph "Entry & Argument Parsing"
        Main["main.rs"]:::application
        Cli["cli.rs"]:::application
        Args["arguments.rs"]:::application
        AppError["error.rs"]:::application
        AppMod["mod.rs"]:::application
    end

    %% User Interaction / UI
    subgraph "User Interaction / UI"
        subgraph "Text UI"
            TextUI["text.rs"]:::ui
            UIActions["actions.rs"]:::ui
            UIState["state.rs"]:::ui
            UIMod["mod.rs"]:::ui
        end
        subgraph "GUI UI"
            GUI["gui.rs"]:::ui
            GUIWindow["window.rs"]:::ui
            GUIProc["processing.rs"]:::ui
            UIState
            UIMod
        end
    end

    %% Core Processing Engine
    subgraph "Core Processing Engine"
        ProcMod["mod.rs"]:::processing
        ProcError["error.rs"]:::processing
        ProcMatcher["matcher.rs"]:::processing
        ProcLog["log_reporter.rs"]:::processing
        ProcNotif["notif_reporter.rs"]:::processing
    end

    %% Matcher & Replacement Logic
    subgraph "Matcher & Replacement Logic"
        MatcherMod["mod.rs"]:::matcher
        Pattern["pattern.rs"]:::matcher
        Metadata["metadata.rs"]:::matcher
        PredDate["predetermined_date.rs"]:::matcher
        Replacement["replacement.rs"]:::matcher
    end

    %% Configuration & File I/O
    ConfigTOML["config.toml"]:::config
    DesktopFile["prefix-by-date.desktop"]:::config
    FS["File System"]:::external
    NotifDaemon["Notification Daemon"]:::external

    %% Connections
    Main -->|"start"| Cli
    Cli -->|"ProcessingRequest"| ProcMod
    Cli -->|"batch mode"| ProcLog
    Cli -->|"interactive text"| TextUI
    Cli -->|"GUI mode"| GUI

    TextUI -->|"user input"| ProcMod
    GUI -->|"user input"| ProcMod

    ProcMod -->|"load config"| ConfigTOML
    ProcMod -->|"orchestrate"| ProcMatcher
    ProcMod -->|"log result"| ProcLog
    ProcMod -->|"notify result"| ProcNotif

    ProcMatcher -->|"invoke Matcher"| MatcherMod
    MatcherMod -->|"pattern match"| Pattern
    MatcherMod -->|"inspect metadata"| Metadata
    MatcherMod -->|"use date"| PredDate
    MatcherMod -->|"produce MatcherResult"| Replacement

    Replacement -->|"new filename"| FS
    Replacement -->|"rename file"| FS

    ProcLog -->|"stdout/stderr"| Cli
    ProcNotif -->|"send notification"| NotifDaemon

    %% Error flows
    ProcError -.->|"error"| Cli
    AppError -.->|"error"| Cli

    %% Click Events
    click Main "https://github.com/aethelflaed/prefix-by-date/blob/main/src/main.rs"
    click Cli "https://github.com/aethelflaed/prefix-by-date/blob/main/src/application/cli.rs"
    click Args "https://github.com/aethelflaed/prefix-by-date/blob/main/src/application/arguments.rs"
    click AppError "https://github.com/aethelflaed/prefix-by-date/blob/main/src/application/error.rs"
    click AppMod "https://github.com/aethelflaed/prefix-by-date/blob/main/src/application/mod.rs"
    click TextUI "https://github.com/aethelflaed/prefix-by-date/blob/main/src/ui/text.rs"
    click UIActions "https://github.com/aethelflaed/prefix-by-date/blob/main/src/ui/actions.rs"
    click UIState "https://github.com/aethelflaed/prefix-by-date/blob/main/src/ui/state.rs"
    click UIMod "https://github.com/aethelflaed/prefix-by-date/blob/main/src/ui/mod.rs"
    click GUI "https://github.com/aethelflaed/prefix-by-date/blob/main/src/ui/gui.rs"
    click GUIWindow "https://github.com/aethelflaed/prefix-by-date/blob/main/src/ui/gui/window.rs"
    click GUIProc "https://github.com/aethelflaed/prefix-by-date/blob/main/src/ui/gui/processing.rs"
    click ProcMod "https://github.com/aethelflaed/prefix-by-date/blob/main/src/processing/mod.rs"
    click ProcError "https://github.com/aethelflaed/prefix-by-date/blob/main/src/processing/error.rs"
    click ProcMatcher "https://github.com/aethelflaed/prefix-by-date/blob/main/src/processing/matcher.rs"
    click ProcLog "https://github.com/aethelflaed/prefix-by-date/blob/main/src/processing/log_reporter.rs"
    click ProcNotif "https://github.com/aethelflaed/prefix-by-date/blob/main/src/processing/notif_reporter.rs"
    click MatcherMod "https://github.com/aethelflaed/prefix-by-date/blob/main/src/matcher/mod.rs"
    click Pattern "https://github.com/aethelflaed/prefix-by-date/blob/main/src/matcher/pattern.rs"
    click Metadata "https://github.com/aethelflaed/prefix-by-date/blob/main/src/matcher/metadata.rs"
    click PredDate "https://github.com/aethelflaed/prefix-by-date/blob/main/src/matcher/predetermined_date.rs"
    click Replacement "https://github.com/aethelflaed/prefix-by-date/blob/main/src/replacement.rs"

    %% Styles
    classDef application fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef processing fill:#d4edda,stroke:#333,stroke-width:1px
    classDef matcher fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef ui fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef config fill:#e2e3e5,stroke:#333,stroke-width:1px
    classDef external fill:#f0f0f0,stroke:#333,stroke-width:1px
```
