# lbg2002/ai-file-sorter architecture

> Architecture diagram of the GitHub repository lbg2002/ai-file-sorter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lbg2002/ai-file-sorter
- Repository: https://github.com/lbg2002/ai-file-sorter

## Overview

FileSort Guard is a Qt file-organization application whose central workflow scans a selected folder, proposes categories in AI or deterministic rule mode, validates the plan against the scan, and presents it for approval before changes are applied. The graph also preserves prompt editing, document/image analysis, storage-provider support, and undo/history. The README documents the main workflow; sampled source confirms selected storage, local-LLM, and headless-apply responsibilities, but not every runtime connection.

Main entry points: [`app/lib/AnalysisCoordinator.cpp`](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/AnalysisCoordinator.cpp) (Analysis coordinator), [`app/lib/CategorizationService.cpp`](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/CategorizationService.cpp) (AI categorization), [`app/lib/HeadlessReviewApplyService.cpp`](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/HeadlessReviewApplyService.cpp) (Apply changes), [`app/include/StorageProvider.hpp`](https://github.com/lbg2002/ai-file-sorter/blob/main/app/include/StorageProvider.hpp) (Storage provider)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Organization workflow"]
  node_coordinator["Analysis coordinator"]
  node_scanner["Filesystem scan<br/>[FileScanner.cpp]"]
  node_apply["Apply changes"]
end

subgraph group_analysis["Analysis and prompts"]
  node_categorizer["AI categorization"]
  node_rules["Rule mode<br/>[RuleEngine.cpp]"]
  node_prompt["Prompt editor"]
  node_promptstore["Prompt templates"]
  node_llm["LLM clients<br/>[LLMClient.cpp]"]
  node_local["Local LLM runtime<br/>[LocalLLMClient.cpp]"]
  node_document["Document analysis"]
  node_image["Image analysis"]
end

subgraph group_review["Review and state"]
  node_validator["Plan integrity check"]
  node_review["Review and approval"]
  node_undo["Undo history<br/>[UndoManager.cpp]"]
  node_history[("Review history")]
  node_database[("Categorization cache")]
end

subgraph group_storage["Storage integrations"]
  node_provider["Storage provider"]
  node_onedrive["OneDrive provider"]
  node_plugins["Storage plugin manager"]
end

subgraph group_application["Application interface"]
  node_app["Qt application<br/>[main.cpp]"]
  node_ui["Main window<br/>[MainApp.cpp]"]
end

node_user(("User"))

node_user -->|"starts"| node_app
node_app -.->|"opens"| node_ui
node_ui -.->|"starts analysis"| node_coordinator
node_coordinator -->|"scans"| node_scanner
node_coordinator -->|"requests AI plan"| node_categorizer
node_coordinator -->|"selects rule mode"| node_rules
node_categorizer -.->|"categorizes"| node_llm
node_llm -.->|"uses local backend"| node_local
node_prompt -->|"edits templates"| node_promptstore
node_promptstore -->|"provides override"| node_categorizer
node_categorizer -.->|"analyzes documents"| node_document
node_categorizer -.->|"analyzes images"| node_image
node_coordinator -->|"validates plan"| node_validator
node_validator -->|"flags anomalies"| node_review
node_review -->|"approves changes"| node_apply
node_apply -->|"moves files"| node_provider
node_apply -->|"updates cache"| node_database
node_apply -->|"records moves"| node_history
node_undo -.->|"uses history"| node_history
node_onedrive -->|"implements provider"| node_provider
node_plugins -.->|"loads providers"| node_provider

click node_app "https://github.com/lbg2002/ai-file-sorter/blob/main/app/main.cpp"
click node_ui "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/MainApp.cpp"
click node_coordinator "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/AnalysisCoordinator.cpp"
click node_scanner "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/FileScanner.cpp"
click node_categorizer "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/CategorizationService.cpp"
click node_rules "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/RuleEngine.cpp"
click node_prompt "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/PromptEditorDialog.cpp"
click node_promptstore "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/PromptTemplateStore.cpp"
click node_llm "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/LLMClient.cpp"
click node_local "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/LocalLLMClient.cpp"
click node_document "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/DocumentTextAnalyzer.cpp"
click node_image "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/ImageAnalyzerFactory.cpp"
click node_validator "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/ResultIntegrityValidator.cpp"
click node_review "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/ResultsCoordinator.cpp"
click node_apply "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/HeadlessReviewApplyService.cpp"
click node_undo "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/UndoManager.cpp"
click node_history "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/ReviewHistoryStore.cpp"
click node_provider "https://github.com/lbg2002/ai-file-sorter/blob/main/app/include/StorageProvider.hpp"
click node_onedrive "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/OneDriveStorageProvider.cpp"
click node_plugins "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/StoragePluginManager.cpp"
click node_database "https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/DatabaseManager.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_coordinator,node_scanner,node_apply,node_user toneBlue
class node_categorizer,node_rules,node_prompt,node_promptstore,node_llm,node_local,node_document,node_image toneAmber
class node_validator,node_review,node_undo,node_history,node_database toneMint
class node_provider,node_onedrive,node_plugins toneRose
class node_app,node_ui toneIndigo
```

## Components

### Organization workflow

- [Analysis coordinator](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/AnalysisCoordinator.cpp): `app/lib/AnalysisCoordinator.cpp`
- [Filesystem scan](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/FileScanner.cpp): `app/lib/FileScanner.cpp`
- [Apply changes](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/HeadlessReviewApplyService.cpp): `app/lib/HeadlessReviewApplyService.cpp`

### Analysis and prompts

- [AI categorization](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/CategorizationService.cpp): `app/lib/CategorizationService.cpp`
- [Rule mode](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/RuleEngine.cpp): `app/lib/RuleEngine.cpp`
- [Prompt editor](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/PromptEditorDialog.cpp): `app/lib/PromptEditorDialog.cpp`
- [Prompt templates](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/PromptTemplateStore.cpp): `app/lib/PromptTemplateStore.cpp`
- [LLM clients](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/LLMClient.cpp): `app/lib/LLMClient.cpp`
- [Local LLM runtime](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/LocalLLMClient.cpp): `app/lib/LocalLLMClient.cpp`
- [Document analysis](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/DocumentTextAnalyzer.cpp): `app/lib/DocumentTextAnalyzer.cpp`
- [Image analysis](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/ImageAnalyzerFactory.cpp): `app/lib/ImageAnalyzerFactory.cpp`

### Review and state

- [Plan integrity check](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/ResultIntegrityValidator.cpp): `app/lib/ResultIntegrityValidator.cpp`
- [Review and approval](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/ResultsCoordinator.cpp): `app/lib/ResultsCoordinator.cpp`
- [Undo history](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/UndoManager.cpp): `app/lib/UndoManager.cpp`
- [Review history](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/ReviewHistoryStore.cpp): `app/lib/ReviewHistoryStore.cpp`
- [Categorization cache](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/DatabaseManager.cpp): `app/lib/DatabaseManager.cpp`

### Storage integrations

- [Storage provider](https://github.com/lbg2002/ai-file-sorter/blob/main/app/include/StorageProvider.hpp): `app/include/StorageProvider.hpp`
- [OneDrive provider](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/OneDriveStorageProvider.cpp): `app/lib/OneDriveStorageProvider.cpp`
- [Storage plugin manager](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/StoragePluginManager.cpp): `app/lib/StoragePluginManager.cpp`

### Application interface

- [Qt application](https://github.com/lbg2002/ai-file-sorter/blob/main/app/main.cpp): `app/main.cpp`
- [Main window](https://github.com/lbg2002/ai-file-sorter/blob/main/app/lib/MainApp.cpp): `app/lib/MainApp.cpp`

### Other components

- **User**

## Connections

- User → Qt application: starts (evidence: `app/main.cpp`)
- Qt application → Main window: opens
- Main window → Analysis coordinator: starts analysis
- Analysis coordinator → Filesystem scan: scans
- Analysis coordinator → AI categorization: requests AI plan
- Analysis coordinator → Rule mode: selects rule mode
- AI categorization → LLM clients: categorizes
- LLM clients → Local LLM runtime: uses local backend
- Prompt editor → Prompt templates: edits templates
- Prompt templates → AI categorization: provides override
- AI categorization → Document analysis: analyzes documents
- AI categorization → Image analysis: analyzes images
- Analysis coordinator → Plan integrity check: validates plan
- Plan integrity check → Review and approval: flags anomalies
- Review and approval → Apply changes: approves changes
- Apply changes → Storage provider: moves files (evidence: `app/lib/HeadlessReviewApplyService.cpp`)
- Apply changes → Categorization cache: updates cache (evidence: `app/lib/HeadlessReviewApplyService.cpp`)
- Apply changes → Review history: records moves (evidence: `app/lib/HeadlessReviewApplyService.cpp`)
- Undo history → Review history: uses history
- OneDrive provider → Storage provider: implements provider
- Storage plugin manager → Storage provider: loads providers
