# tony-rafanomezantsoa/trivial-file-transfer-protocol architecture

> Architecture diagram of the GitHub repository tony-rafanomezantsoa/trivial-file-transfer-protocol, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tony-rafanomezantsoa/trivial-file-transfer-protocol
- Repository: https://github.com/tony-rafanomezantsoa/trivial-file-transfer-protocol

## Overview

##### Project Overview
- The project is an implementation of the Trivial File Transfer Protocol (TFTP) as described by RFC 1350.
- It follows a client-server model over UDP, with explicit support for read (RRQ) and write (WRQ) operations.
- Three major components are visible as separate Rust crates: the TFTP client (tftpclient), the TFTP server (tftpserver), and the TFTP packet library (tftppacket) handling packet creation and parsing.

##### Main Components
a. TFTP Client:
- Represented by the “tftpclient” directory; contains its own main.rs along with supporting utilities.
- This component is responsible for issuing file transfer requests (both reading and writing) and handling the corresponding UDP communication with the server.

b. TFTP Server:
- Shown in the “tftpserver” directory; also includes its main program.
- It listens for incoming TFTP requests over UDP, processes them, and sends back appropriate responses along with error codes when necessary.

c. TFTP Packet Library:
- Found under “tftppacket”; provided as a library (lib.rs) to encapsulate the creation, parsing, and handling of the TFTP packet structure.
- Both the client and server depend on this module to serialize, deserialize, and validate TFTP data according to the protocol.

##### Relationships and Interactions
- Response path from the TFTP server back to the client.
- Optionally, include a “UDP Layer” or “Network” component that underlies both the client and server, showing that the communication is encapsulated over UDP.

##### Architectural Patterns and Design Principles
- Modular Design: The separation of the TFTP packet handling (tftppacket crate) from both the client and server indicates a clear separation of concerns.
- Reusability: The tftppacket library acts as a common utility to ensure that both client and server adhere to the same packet format.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "TFTP Client Application"
        TC["TFTP Client"]:::app
        UT["Client Utilities"]:::utils
        TC -->|"uses"| UT
    end

    TC -->|"sendsRRQWRQ"| UDP["UDP/Network Layer"]:::network
    UDP -->|"forwardsRequest"| TS["TFTP Server"]:::app
    TS -->|"sendsResponse"| UDP
    UDP -->|"forwardsResponse"| TC

    TC -->|"uses"| PL["TFTP Packet Library"]:::lib
    TS -->|"uses"| PL

    Note["AdheresToRFC1350:<br>StandardTFTPProtocol"]:::note

    style Note fill:#ffffcc,stroke:#cccc00,stroke-width:2px

    click TC "https://github.com/tony-rafanomezantsoa/trivial-file-transfer-protocol/blob/main/tftpclient/src/main.rs"
    click UT "https://github.com/tony-rafanomezantsoa/trivial-file-transfer-protocol/tree/main/tftpclient/src/utils"
    click TS "https://github.com/tony-rafanomezantsoa/trivial-file-transfer-protocol/blob/main/tftpserver/src/main.rs"
    click PL "https://github.com/tony-rafanomezantsoa/trivial-file-transfer-protocol/blob/main/tftppacket/src/lib.rs"

    classDef app fill:#a1d99b,stroke:#31a354,stroke-width:2px;
    classDef utils fill:#9ecae1,stroke:#3182bd,stroke-width:2px;
    classDef network fill:#fdae6b,stroke:#e6550d,stroke-width:2px;
    classDef lib fill:#fdd0a2,stroke:#ff7f0e,stroke-width:2px;
    classDef note fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
```
