# spectre10/fs-cli architecture

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

- Interactive diagram: https://gitdiagram.com/spectre10/fs-cli
- Repository: https://github.com/spectre10/fs-cli

## Overview

##### Main Components
- CLI Interface: Represented by the files in the “cmd” directory –
- send, receive, and findip commands.
- Core Libraries: The “lib” directory holds utility files (encdec, file, ip, stats) which encapsulate the core file processing, encryption/decryption, IP handling, and statistics gathering logic.
- Session Management: The “session” directory is split into “send” and “receive” subdirectories. These handle the session establishment, communication, and WebRTC Data-Channel management with internal files for methods, handlers, and session logic.
- External Services: Although no server is present (peer-to-peer model is employed), include Google’s STUN server as an external dependency that is critical for NAT traversal, as well as underlying WebRTC libraries (e.g., pion/webrtc).

##### Out Relationships and Interactions
- The CLI commands trigger the application’s main logic by calling functions in the “lib” layer and establishing sessions via “session/send” or “session/receive”.
- In a “send” scenario:
- The CLI “send” component calls into the session module (session/send) to establish a connection.
- The session functions interact with the lib utilities (such as file handling from lib/file.go and encoding/decoding via lib/encdec.go) to process multiple files.
- Each file gets a dedicated Data-Channel in the established WebRTC Peer Connection.
- In a “receive” scenario:
- The CLI “receive” invokes the session/receive module.
- Similar to sending, the receiver utilizes the lib components to manage file integrity and tracking statistics.
- The findip command uses the ip.go from lib to retrieve public IP data via WebRTC.

##### Architectural Patterns and Design Principles
- Modularity: There’s a clean separation between command parsing (cmd), core file and utility functions (lib), and communication/session logic (session).
- Concurrent Data Handling: The design supports multi-threaded file transfers by setting up multiple Data-Channels for concurrent transfers.
- Peer-to-Peer Networking: Emphasis on direct P2P communication with external STUN for establishing connections.

##### Technologies and Frameworks
- Golang as the primary platform.
- The pion/webrtc library for WebRTC functionality.
- Use of Google’s STUN server for NAT discovery.
- Standard Golang toolchain (e.g., go.mod for dependency management).

##### Elements
- Clear labels for each component:

##### Final Touches
- Every module, including session submodules (send and receive), and utility libraries (such as file handling and IP retrieval) are clearly delineated.
- Do not shy away from over-segmenting if needed — the more detailed, the better; include even minor components if they represent logical boundaries.
- Annotating elements with key design notes (for example, highlighting concurrent data streams over multiple Data-Channels or marking the reliance on a peer-to-peer communication pattern).

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% CLI Layer
    subgraph "CLI Layer"
        CLI_send["send command"]:::cli
        CLI_receive["receive command"]:::cli
        CLI_findip["findip command"]:::cli
    end

    %% Session Management
    subgraph "Session Management"
        subgraph "Send Session"
            SS["Session Send"]:::session
            SH["Send Handlers"]:::session
            SM["Send Methods"]:::session
        end
        subgraph "Receive Session"
            RS["Session Receive"]:::session
            RH["Receive Handlers"]:::session
            RM["Receive Methods"]:::session
        end
    end

    %% Core Utilities
    subgraph "Core Utilities"
        ENCD["EncDec Utility"]:::core
        FILE["File Utility"]:::core
        IPUTIL["IP Utility"]:::core
        STATS["Stats Utility"]:::core
    end

    %% External Services
    subgraph "External Services"
        STUN["Google STUN Server"]:::external
        WEBRTC["pion/webrtc Library"]:::external
    end

    %% Connections from CLI to Session Management and Core Utilities
    CLI_send -->|"start_session"| SS
    CLI_send -->|"establish_connection"| SM
    CLI_receive -->|"initiate_session"| RS
    CLI_receive -->|"establish_connection"| RM
    CLI_findip -->|"get_public_IP"| IPUTIL

    %% Session Management interactions with Core Utilities
    SS -->|"process_files"| FILE
    SS -->|"encode_decode"| ENCD
    SM -->|"process_files"| FILE

    RS -->|"process_files"| FILE
    RS -->|"gather_stats"| STATS
    RM -->|"process_files"| FILE

    %% Session Management interactions with External Services
    SS -->|"use_WebRTC"| WEBRTC
    RS -->|"use_WebRTC"| WEBRTC
    WEBRTC -->|"NAT_traversal"| STUN

    %% Internal Session submodule interactions
    SS --> SH
    SS --> SM
    RS --> RH
    RS --> RM

    %% Click Events for CLI Interface
    click CLI_send "https://github.com/spectre10/fs-cli/blob/main/cmd/send.go"
    click CLI_receive "https://github.com/spectre10/fs-cli/blob/main/cmd/receive.go"
    click CLI_findip "https://github.com/spectre10/fs-cli/blob/main/cmd/findip.go"

    %% Click Events for Core Library
    click ENCD "https://github.com/spectre10/fs-cli/blob/main/lib/encdec.go"
    click FILE "https://github.com/spectre10/fs-cli/blob/main/lib/file.go"
    click IPUTIL "https://github.com/spectre10/fs-cli/blob/main/lib/ip.go"
    click STATS "https://github.com/spectre10/fs-cli/blob/main/lib/stats.go"

    %% Click Events for Session Management - Send
    click SS "https://github.com/spectre10/fs-cli/blob/main/session/send/session.go"
    click SH "https://github.com/spectre10/fs-cli/blob/main/session/send/handlers.go"
    click SM "https://github.com/spectre10/fs-cli/blob/main/session/send/methods.go"

    %% Click Events for Session Management - Receive
    click RS "https://github.com/spectre10/fs-cli/blob/main/session/receive/session.go"
    click RH "https://github.com/spectre10/fs-cli/blob/main/session/receive/handlers.go"
    click RM "https://github.com/spectre10/fs-cli/blob/main/session/receive/methods.go"

    %% Styles
    classDef cli fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef core fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef session fill:#f3722c,stroke:#333,stroke-width:2px;
    classDef external fill:#577590,stroke:#333,stroke-width:2px;
```
