# sri-aurobindo/filearchiver architecture

> Architecture diagram of the GitHub repository sri-aurobindo/filearchiver, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sri-aurobindo/filearchiver
- Repository: https://github.com/sri-aurobindo/filearchiver

## Overview

**Type:** Windows desktop application — **.NET Framework 4.8 WPF** app using **MVVM** and “Clean Architecture”-style layering.
**Purpose:** User configures a set of target folders, supplies a timestamp, and the app **scans files**, **filters them using a temporal strategy**, then **creates a ZIP archive** in the executable directory. It supports **async execution**, **progress reporting**, and **cancellation**.

- WPF UI composition (View ↔ ViewModel)
- Orchestration path from UI action → service workflow → strategy + command → file system + zip output
- Persistence boundary (settings.json via repository)
- Cross-cutting concerns: cancellation, progress, error handling

- **Views/**
- `MainWindow.xaml` (+ code-behind) → WPF UI
- **ViewModels/**
- `MainViewModel.cs` → UI state + command bindings
- `RelayCommand.cs` → ICommand plumbing
- **Models/**
- `TargetFolder.cs`, `FileMetadata.cs` → domain entities / DTOs
- **Services/**
- `FileArchiveService.cs` → orchestration: scanning → filtering → archiving
- **Strategies/**
- `IFileFilterStrategy.cs`, `TemporalFilterStrategy.cs` → filtering algorithm plug-in
- **Commands/**
- `IArchiveCommand.cs`, `CreateArchiveCommand.cs` → archiving operation plug-in (ZIP)
- **Infrastructure/**
- `IConfigRepository.cs`, `ConfigRepository.cs` → settings.json persistence
- App / composition root:
- External world (important in this project):
- **Windows File System** (input folders; file metadata)
- **settings.json** (config store)
- **ZIP output file** (archive artifact)

##### What the README implies architecturally (relationships & flows to show)

- **MVVM**: View binds to ViewModel; ViewModel exposes commands/properties
- **Repository**: ViewModel or Service depends on `IConfigRepository` (not `ConfigRepository`)
- **Strategy**: Service depends on `IFileFilterStrategy` and can swap implementations
- **Command pattern**: Service (or ViewModel) triggers `IArchiveCommand.ExecuteAsync(...)`
- **Service layer**: `FileArchiveService` coordinates scanning/filtering/archiving
- **Async + CancellationToken + IProgress**: show these as control-flow “channels” from UI to long-running work

##### MainViewModel (MVVM ViewModel)

**Application / Domain**
##### CreateArchiveCommand (ZIP) (implementation)

**Infrastructure**
##### ConfigRepository (JSON) (implementation)

**External / system boundaries**
##### ZIP archive output (artifact in exe directory)

**Composition root**

##### Architectural principles visually
- «View», «ViewModel», «Service», «Repository», «Strategy», «Command», «Model», «External»
And show **interfaces as separate nodes** with implementations pointing to them:
- `ConfigRepository` → implements → `IConfigRepository`
- `TemporalFilterStrategy` → implements → `IFileFilterStrategy`
- `CreateArchiveCommand` → implements → `IArchiveCommand`
- `MainViewModel` → `IConfigRepository`
- `FileArchiveService` → `IFileFilterStrategy`, `IArchiveCommand`

- View → ViewModel → Service → (Strategy + Command + Repository) → externals
- Interfaces and implementations called out

##### Cancel flow triggers cleanup + partial zip deletion

- App.xaml.cs («Composition Root / DI»)
- MainWindow.xaml («View»)
- MainViewModel («ViewModel»)
- RelayCommand («MVVM Command Helper»)
- FileArchiveService («Service / Orchestrator»)
- TargetFolder, FileMetadata («Models»)
- IConfigRepository («Repository Interface»)
- ConfigRepository («JSON Repository»)
- IFileFilterStrategy («Strategy Interface»)
- TemporalFilterStrategy («Temporal Strategy»)
- IArchiveCommand («Command Interface»)
- CreateArchiveCommand («ZIP Command»)
- settings.json («External Config File»)
- Windows File System («External Input Folders»)
- HH-mm-ss.zip («External Output Artifact»)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% =========================
    %% Diagram 1 — Static architecture (components & dependencies)
    %% =========================
    subgraph D1["Diagram 1: Static architecture (C4 L2/3 hybrid)"]
        direction TB

        subgraph UI["UI Thread (Presentation / MVVM)"]
            direction TB
            AppXaml["App.xaml"]:::composition
            AppRoot["App.xaml.cs\n«Composition Root / DI»"]:::composition

            View["MainWindow.xaml\n«View»"]:::presentation
            ViewCodeBehind["MainWindow.xaml.cs\n«View code-behind»"]:::presentation

            VM["MainViewModel\n«ViewModel»"]:::presentation
            RC["RelayCommand\n«ICommand helper»"]:::presentation
        end

        subgraph BG["Background / Async Operations (Application + Domain)"]
            direction TB
            Svc["FileArchiveService\n«Service / Orchestrator»"]:::application

            subgraph Models["Domain Models"]
                direction TB
                TargetFolder["TargetFolder\n«Model»"]:::model
                FileMetadata["FileMetadata\n«Model/DTO»"]:::model
            end

            subgraph Patterns["Strategy + Command (pluggable behaviors)"]
                direction TB
                IFilter["IFileFilterStrategy\n«Strategy interface»"]:::pattern_if
                Temporal["TemporalFilterStrategy\n«Strategy impl»"]:::pattern_impl

                ICmd["IArchiveCommand\n«Command interface»"]:::pattern_if
                ZipCmd["CreateArchiveCommand\n«ZIP command impl»"]:::pattern_impl
            end
        end

        subgraph INFRA["Infrastructure (Persistence)"]
            direction TB
            IRepo["IConfigRepository\n«Repository interface»"]:::infrastructure_if
            Repo["ConfigRepository\n«JSON repository»"]:::infrastructure
        end

        subgraph IO["I/O Boundary (External resources)"]
            direction TB
            FS["Windows File System\n«External: target folders»"]:::external
            Settings["settings.json (exe directory)\n«External: config store»"]:::external
            ZipOut["Archive: HH-mm-ss.zip (exe directory)\n«External: output artifact»"]:::external
        end

        %% --- MVVM binding / UI wiring
        AppXaml -->|"startup"| AppRoot
        AppRoot -->|"wire ViewModel + services"| VM
        AppRoot -->|"create View"| View

        View -.->|"data binding (TwoWay)"| VM
        ViewCodeBehind -.->|"events / UI hosting"| View
        VM -->|"bind commands"| RC

        %% --- Configuration
        VM -->|"LoadConfiguration() / SaveConfiguration()"| IRepo
        Repo -.->|"implements"| IRepo
        Repo -->|"read/write"| Settings

        %% --- Execution orchestration
        VM -->|"RunAsync(timestamp, cancellationToken, progress)"| Svc
        Svc -->|"Scan files"| FS
        Svc -->|"build list of"| FileMetadata
        Svc -->|"uses"| TargetFolder

        %% --- Strategy + Command usage via interfaces
        Svc -->|"Filter(allFiles, timestamp)"| IFilter
        Temporal -.->|"implements"| IFilter

        Svc -->|"ExecuteAsync(cancellationToken, progress)"| ICmd
        ZipCmd -.->|"implements"| ICmd
        ZipCmd -->|"write ZIP"| ZipOut

        %% --- Cross-cutting channels
        VM -->|"pass CancellationToken"| Svc
        Svc -->|"pass CancellationToken"| ICmd

        Svc -->|"report progress (IProgress)"| VM
        ZipCmd -->|"report progress (IProgress)"| VM
        VM -->|"update status/progress"| View

        %% --- Error propagation
        IRepo -->|"exceptions/results"| VM
        Svc -->|"exceptions/results"| VM
        ZipCmd -->|"exceptions/results"| Svc
        VM -->|"show errors"| View
    end

    %% =========================
    %% Diagram 2 — Runtime sequence (Execute Archive use case)
    %% (Rendered as a flowchart to keep a single valid Mermaid diagram)
    %% =========================
    subgraph D2["Diagram 2: Runtime sequence (Execute Archive use case)"]
        direction TB

        User["User"]:::external
        View2["MainWindow.xaml\n«View»"]:::presentation
        VM2["MainViewModel\n«ViewModel»"]:::presentation
        Svc2["FileArchiveService\n«Service»"]:::application
        Strat["IFileFilterStrategy\n«Strategy»"]:::pattern_if
        Cmd["IArchiveCommand\n«Command»"]:::pattern_if
        Repo2["IConfigRepository\n«Repository»"]:::infrastructure_if
        FS2["Windows File System\n«External»"]:::external
        ZIP["HH-mm-ss.zip\n«External»"]:::external
        CFG["settings.json\n«External»"]:::external

        User -->|"1. Click Execute"| View2
        View2 -->|"2. Invoke bound RelayCommand"| VM2
        VM2 -->|"3. Create CancellationTokenSource"| VM2
        VM2 -->|"4. LoadConfiguration()"| Repo2
        Repo2 -->|"5. Read settings.json"| CFG
        CFG -->|"6. Config JSON"| Repo2
        Repo2 -->|"7. TargetFolders + options"| VM2

        VM2 -->|"8. RunAsync(timestamp, cancellationToken, progress)"| Svc2
        Svc2 -->|"9. Scan enabled TargetFolders"| FS2
        FS2 -->|"10. File list + metadata"| Svc2
        Svc2 -->|"11. Report progress (scan status)"| VM2

        Svc2 -->|"12. Filter(allFiles, timestamp)"| Strat
        Strat -->|"13. Filtered files"| Svc2
        Svc2 -->|"14. Report progress (filter status)"| VM2

        Svc2 -->|"15. ExecuteAsync(files, cancellationToken, progress)"| Cmd
        Cmd -->|"16. Create/write ZIP in exe directory"| ZIP
        Cmd -->|"17. Result / completion"| Svc2
        Svc2 -->|"18. Report progress (archive status)"| VM2
        VM2 -->|"19. Update UI status/progress"| View2

        subgraph CancelAlt["alt User cancels"]
            direction TB
            User -->|"C1. Click Cancel"| View2
            View2 -->|"C2. Invoke cancel command"| VM2
            VM2 -->|"C3. Cancel via CancellationToken"| Svc2
            Svc2 -->|"C4. Observe cancellationToken"| Cmd
            Cmd -->|"C5. OperationCanceledException / canceled result"| Svc2
            Svc2 -->|"C6. Cleanup partial ZIP (delete if needed)"| ZIP
            Svc2 -->|"C7. Canceled + final status"| VM2
            VM2 -->|"C8. Show Canceled"| View2
        end

        subgraph ErrorAlt["alt Error occurs"]
            direction TB
            Cmd -->|"E1. Exception"| Svc2
            Svc2 -->|"E2. Error result/exception"| VM2
            VM2 -->|"E3. Show error dialog / log"| View2
        end
    end

    %% =========================
    %% Click Events (from component_mapping)
    %% =========================
    click View "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/Views/MainWindow.xaml"
    click ViewCodeBehind "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/Views/MainWindow.xaml.cs"
    click VM "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/ViewModels/MainViewModel.cs"
    click RC "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/ViewModels/RelayCommand.cs"
    click Svc "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/Services/FileArchiveService.cs"
    click TargetFolder "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/Models/TargetFolder.cs"
    click FileMetadata "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/Models/FileMetadata.cs"
    click IFilter "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/Strategies/IFileFilterStrategy.cs"
    click Temporal "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/Strategies/TemporalFilterStrategy.cs"
    click ICmd "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/Commands/IArchiveCommand.cs"
    click ZipCmd "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/Commands/CreateArchiveCommand.cs"
    click IRepo "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/Infrastructure/IConfigRepository.cs"
    click Repo "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/Infrastructure/ConfigRepository.cs"
    click AppXaml "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/App.xaml"
    click AppRoot "https://github.com/sri-aurobindo/filearchiver/blob/main/FileArchiver/App.xaml.cs"

    %% =========================
    %% Styles
    %% =========================
    classDef presentation fill:#1f77b4,stroke:#0b3d91,color:#ffffff,stroke-width:1px
    classDef composition fill:#0d47a1,stroke:#082f6b,color:#ffffff,stroke-width:2px
    classDef application fill:#2e7d32,stroke:#1b5e20,color:#ffffff,stroke-width:1px
    classDef model fill:#43a047,stroke:#1b5e20,color:#ffffff,stroke-width:1px
    classDef pattern_if fill:#ffb300,stroke:#e65100,color:#111111,stroke-width:1px
    classDef pattern_impl fill:#fb8c00,stroke:#e65100,color:#111111,stroke-width:1px
    classDef infrastructure_if fill:#90a4ae,stroke:#546e7a,color:#111111,stroke-width:1px
    classDef infrastructure fill:#78909c,stroke:#455a64,color:#ffffff,stroke-width:1px
    classDef external fill:#ffffff,stroke:#111111,color:#111111,stroke-width:2px,stroke-dasharray: 6 4
```
