# phatina/simple-mtpfs architecture

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

- Interactive diagram: https://gitdiagram.com/phatina/simple-mtpfs
- Repository: https://github.com/phatina/simple-mtpfs

## Overview

##### Main Components

a. Core Components:
- FUSE Interface Layer
- MTP Communication Layer
- File System Operations Layer
- Temporary File Management System

b. External Dependencies:
- FUSE Kernel Module
- libmtp Library
- USB-connected MTP Device
- Host Operating System

##### Component Relationships

Use the following connection types:
- Double lines for API boundaries

##### Specific Implementation Details

- File type handlers (Directory, File, TmpFile)
- SHA1 verification system
- Logging system
- Utility functions

##### Detailed Component Breakdown

FUSE Interface:
**User Space Operations**
- ↓
**FUSE Implementation (simple-mtpfs-fuse.*)**
- ↓
**File/Directory Operations Handler**

MTP Layer:
**MTP Device Manager (simple-mtpfs-mtp-device.*)**
- ↓
**libmtp Interface (simple-mtpfs-libmtp.*)**
- ↓
**Physical MTP Device**

File Management:
**Type Handlers**
- Directory (simple-mtpfs-type-dir.*)
- File (simple-mtpfs-type-file.*)
- TmpFile (simple-mtpfs-type-tmp-file.*)

## Diagram (Mermaid)

```mermaid
sequenceDiagram
    participant User
    participant FUSE
    participant FileOps
    participant TypeHandlers
    participant TmpPool
    participant MTPDevice
    participant USBDevice

    User->>FUSE: File Operation Request
    activate FUSE
    FUSE->>FileOps: Handle Operation
    activate FileOps

    alt is write operation
        FileOps->>TypeHandlers: Create File Handler
        activate TypeHandlers
        TypeHandlers->>TmpPool: Store in Temp Pool
        activate TmpPool
        TmpPool-->>TypeHandlers: File Stored
        deactivate TmpPool
        TypeHandlers-->>FileOps: Handler Created
        deactivate TypeHandlers
        FileOps->>MTPDevice: Send File
        activate MTPDevice
        MTPDevice->>USBDevice: Transfer to Device
        USBDevice-->>MTPDevice: Transfer Complete
        MTPDevice-->>FileOps: Send Complete
        deactivate MTPDevice
    else is read operation
        FileOps->>MTPDevice: Request File
        activate MTPDevice
        MTPDevice->>USBDevice: Fetch from Device
        USBDevice-->>MTPDevice: File Data
        MTPDevice->>TmpPool: Store in Temp Pool
        activate TmpPool
        TmpPool-->>MTPDevice: Storage Complete
        deactivate TmpPool
        MTPDevice-->>FileOps: File Ready
        deactivate MTPDevice
    end

    FileOps-->>FUSE: Operation Complete
    deactivate FileOps
    FUSE-->>User: Operation Result
    deactivate FUSE
```
