# libfuse/sshfs architecture

> Architecture diagram of the GitHub repository libfuse/sshfs, 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/libfuse/sshfs
- Repository: https://github.com/libfuse/sshfs

## Overview

##### Main Components Identification

a. Core Components:
- SSHFS Client (sshfs.c)
- Cache System (cache.c/cache.h)
- FUSE Interface
- SSH/SFTP Protocol Layer
- Remote SSH Server
- Remote Filesystem

b. Supporting Components:
- Compatibility Layer (compat directory)
- Platform-specific Adaptations (darwin_compat)
- FUSE Options Handler (fuse_opt)

**[User Space]**
- ↓
**[SSHFS Client Layer]**
- ↓
**[Cache Layer]**
- ↓
**[FUSE Interface]**
- ↓
**[SSH/SFTP Protocol]**
- ↓
**[Network Layer]**
- ↓
**[Remote SSH Server]**
- ↓
**[Remote Filesystem]**

##### Specific Elements

a. Client Side:
- User space interface
- SSHFS main process
- Cache mechanism
- FUSE binding
- Platform compatibility layer

b. Network Layer:
- SSH connection
- SFTP protocol
- Authentication flow

c. Server Side:
- SSH daemon
- SFTP subsystem
- Remote filesystem

##### Important Details to Highlight

- Cache system's interaction with the main SSHFS process
- How FUSE operations are translated to SFTP commands
- Demonstrate the role of compatibility layers
- Error handling and retry mechanisms
- Authentication flow

##### Technical Notes

- The non-invasive nature of the system (no server-side installation required)
- The user-space implementation
- The dependency on libfuse and GLib
- The caching mechanism's role in performance optimization

##### Implementation Details

- Rectangles: Main components
- Diamonds: Decision points
- Rounded rectangles: External interfaces

Remember to include build and deployment requirements (Meson, Ninja) in a separate section if needed for completeness.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph User_Space
        User[User Space Application]
    end

    subgraph SSHFS_Client_Layer
        SSHFS[SSHFS Client]:::core
        FuseOpt[FUSE Options Handler]:::support
        click SSHFS "https://github.com/libfuse/sshfs/blob/master/sshfs.c"
        click FuseOpt "https://github.com/libfuse/sshfs/blob/master/compat/fuse_opt.c"
    end

    subgraph Cache_Layer
        Cache[Cache System]:::cache
        click Cache "https://github.com/libfuse/sshfs/blob/master/cache.c"
    end

    subgraph Compatibility_Layer
        Compat[Compatibility Layer]:::support
        Darwin[Platform Adaptations]:::support
        click Compat "https://github.com/libfuse/sshfs/tree/master/compat/"
        click Darwin "https://github.com/libfuse/sshfs/blob/master/compat/darwin_compat.c"
    end

    subgraph FUSE_Layer
        FUSE[FUSE Interface]:::external
    end

    subgraph Protocol_Layer
        SSH[SSH Protocol]:::external
        SFTP[SFTP Subsystem]:::external
    end

    subgraph Remote_Layer
        SSHd[SSH Server]:::server
        RemoteFS[Remote Filesystem]:::storage
    end

    %% Connections
    User --> SSHFS
    SSHFS --> Cache
    SSHFS --> FuseOpt
    Cache --> FUSE
    FUSE --> Compat
    Compat --> Darwin
    Compat --> SSH
    SSH --> SFTP
    SFTP --> SSHd
    SSHd --> RemoteFS

    %% Build and Test
    Build[Build System]:::build
    Test[Testing Framework]:::test
    click Build "https://github.com/libfuse/sshfs/blob/master/meson.build"
    click Test "https://github.com/libfuse/sshfs/blob/master/test/test_sshfs.py"

    %% Documentation
    Doc[Documentation]:::doc
    click Doc "https://github.com/libfuse/sshfs/blob/master/README.md"

    %% Styles
    classDef core fill:#2374ab
    classDef cache fill:#ffd700
    classDef support fill:#95a5a6
    classDef external fill:#27ae60
    classDef server fill:#8e44ad
    classDef storage fill:#e67e22
    classDef build fill:#7f8c8d
    classDef test fill:#16a085
    classDef doc fill:#bdc3c7

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Cache System]:::cache
        L3[Support Components]:::support
        L4[External Interfaces]:::external
        L5[Server Components]:::server
        L6[Storage]:::storage
        L7[Build & Test]:::build
        L8[Documentation]:::doc
    end
```
