# mxway/filerecovery architecture

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

- Interactive diagram: https://gitdiagram.com/mxway/filerecovery
- Repository: https://github.com/mxway/filerecovery

## Overview

##### Project Type and Purpose
- The project is a file recovery utility for Windows systems.
- It specifically targets recovery from FAT32 and NTFS file systems, as indicated by the README (“windows系统下fat32及ntfs删除文件恢复”) and the presence of separate modules for FAT32 and NTFS.
- The application likely uses a modular approach to abstract file system-specific recovery logic (for example, through the use of a FileSystemFactory).

##### Analyzing the File Structure
- Top-Level Files/Directories:
- LICENSE and README.md indicate standard project documentation.
- The “doc” directory contains implementation notes (in Chinese) that likely explain the recovery process.
- The “example” directory includes a demo project (with Visual Studio project files such as Demo.vcxproj and associated source files) meant to showcase or test the recovery functionality.
- The “source” directory contains the core source files including main.cpp, modules for FAT32 (fat32.cpp/fat32.h) and NTFS (ntfs.cpp/ntfs.h), and various utility files (commutil, StringUtil, etc.).
- Architectural Patterns:
- The existence of FileSystemFactory (FileSystemFactory.cpp/h) implies the use of the Factory design pattern for abstracting file system differences.
- The separation of FAT32 and NTFS modules indicates a strategy where file system–specific behaviors are encapsulated in separate components.

##### Core Components
a. User/Demo Interface:
- “example” module (Demo.aps, Demo.cpp, etc.) as the front-facing layer or UI used to interact with the file recovery functionality.
b. Main Application Core:
- The entry point is main.cpp which sets up and orchestrates the recovery process.
c. File System Abstraction Layer:
- A “FileSystemFactory” component that decides (based on the underlying storage media) whether to use the FAT32 module or the NTFS module.
d. Utility/Helper Modules:
- Common utility functions/modules (commutil.cpp/h, StringUtil.cpp/h) as separate service components that support various operations.
e. Additional File Handling Modules:
- “File.cpp/h”, “FileSystem.cpp/h”, and “reader.cpp/h” represent components responsible for low-level file I/O and reading file system metadata.

##### Relationships and Data Flow
- The main application (main.cpp) interacts with the FileSystemFactory to obtain an instance of a file system-specific recovery module.
- The chosen module (either FAT32 or NTFS) processes the disk/file structure to recover deleted files.
- Utility modules (string and common utilities) are used by both the recovery modules and possibly the UI/demo for data processing.
- The demo interface component (from the “example” directory) interacts with the main core to trigger file recovery and then displays results.
- From main application to FileSystemFactory.
- From FileSystemFactory to either FAT32 or NTFS recovery components.
- From both recovery modules to utility functions.
- From the demo/UI layer to main application, indicating user interaction and control flow.

##### Architectural Patterns and Technologies
- Use of the Factory Design Pattern for file system selection.
- That the project is built for Windows (using Visual Studio, as seen from .vcxproj and related files).
- Mention that the architecture is modular; separating core recovery logic from the UI/demo ensures that the file recovery engine is reusable and testable in different contexts.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Level Components
    DemoUI["Demo UI (example)"]:::demo
    MainApp["Main Application (main.cpp)"]:::main
    FileSystemFactory["FileSystemFactory"]:::factory

    %% Recovery Modules Subgraph
    subgraph "Recovery Modules"
        FAT32["FAT32 Recovery Module"]:::recovery
        NTFS["NTFS Recovery Module"]:::recovery
    end

    %% Utility Modules Subgraph
    subgraph "Utility Modules"
        CommUtil["Common Utilities"]:::utility
        StringUtil["String Utilities"]:::utility
    end

    %% File Handling Modules Subgraph
    subgraph "File Handling Modules"
        FileIO["File I/O Operations"]:::fileHandling
        FileSystemRep["File System Representation"]:::fileHandling
        Reader["File System Reading"]:::fileHandling
    end

    %% Relationships and Data Flow
    DemoUI -->|"triggers"| MainApp
    MainApp -->|"creates"| FileSystemFactory
    FileSystemFactory -->|"selects"| FAT32
    FileSystemFactory -->|"selects"| NTFS

    %% Recovery Modules using Utility Modules
    FAT32 -->|"uses"| CommUtil
    FAT32 -->|"uses"| StringUtil
    NTFS -->|"uses"| CommUtil
    NTFS -->|"uses"| StringUtil

    %% Recovery Modules using File Handling Modules
    FAT32 -->|"uses"| FileIO
    FAT32 -->|"uses"| FileSystemRep
    FAT32 -->|"uses"| Reader
    NTFS -->|"uses"| FileIO
    NTFS -->|"uses"| FileSystemRep
    NTFS -->|"uses"| Reader

    %% Click Events
    click DemoUI "https://github.com/mxway/filerecovery/tree/master/example/"
    click MainApp "https://github.com/mxway/filerecovery/blob/master/source/main.cpp"
    click FileSystemFactory "https://github.com/mxway/filerecovery/blob/master/source/FileSystemFactory.cpp"
    click FAT32 "https://github.com/mxway/filerecovery/blob/master/source/fat32.cpp"
    click NTFS "https://github.com/mxway/filerecovery/blob/master/source/ntfs.cpp"
    click CommUtil "https://github.com/mxway/filerecovery/blob/master/source/commutil.cpp"
    click StringUtil "https://github.com/mxway/filerecovery/blob/master/source/StringUtil.cpp"
    click FileIO "https://github.com/mxway/filerecovery/blob/master/source/File.cpp"
    click FileSystemRep "https://github.com/mxway/filerecovery/blob/master/source/FileSystem.cpp"
    click Reader "https://github.com/mxway/filerecovery/blob/master/source/reader.cpp"

    %% Styles
    classDef demo fill:#f2d7d5,stroke:#ad4d3a,stroke-width:2px;
    classDef main fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef factory fill:#d6eaf8,stroke:#3498db,stroke-width:2px;
    classDef recovery fill:#f9e79f,stroke:#f1c40f,stroke-width:2px;
    classDef utility fill:#fad7a0,stroke:#e67e22,stroke-width:2px;
    classDef fileHandling fill:#e8daef,stroke:#8e44ad,stroke-width:2px;
```
