# frozsgy/ceng435-hw architecture

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

- Interactive diagram: https://gitdiagram.com/frozsgy/ceng435-hw
- Repository: https://github.com/frozsgy/ceng435-hw

## Overview

##### Project Type and Purpose
- This is a client/server file‐transfer application written in Python, implementing a reliable data transfer (RDT) protocol (similar to RDT 3.0) on top of UDP and also supporting TCP.
- Purpose: transfer arbitrary files reliably over an unreliable network channel by exchanging packets with checksums and acknowledgments.

##### File Structure
- Top-level scripts:
- client.py – the client executable
- server.py – the server executable
- Shared modules:
- packet.py – defines packet structure, serialization, checksum logic
- util.py – helper methods (e.g., file I/O, timeout logic, argument parsing)
- simulator/ – (optional) code for running or testing simulated networks
- No separate “frontend” or “backend” directories; the architecture is a two-node network system.

##### Key Components
a. Client Application
– “Command‐Line Interface” (parses args)
– “File I/O Module” (reads input file, writes received data)
– “RDT Layer” (maintains send buffer, sequence numbers, ACK list)
– “Packet Module” (builds packets: data, id, checksum)
– “Transport Layer” (selects UDP or TCP socket)
b. Server Application
– “Transport Layer” (listens on UDP/TCP ports)
– “Packet Module” (parses incoming packets, validates checksum)
– “RDT Layer” (tracks received packet IDs, generates ACKs)
– “File I/O Module” (writes complete file to disk)
c. Network Channel
– “UDP Unreliable Channel”
– “TCP Reliable Channel”
– (Optionally) a simulated network behavior from simulator/
d. External Environment
– Underlying OS socket API
– File system

##### Relationships and Data Flows
- Client → (open socket) → Network Transport
- Network Transport → (segment or datagram) → Server
- Server → (ACK packet) → Client
- Within each node, data flows top-down: CLI → File I/O → RDT → Packet → Transport
- RDT sits logically between application logic (file I/O) and transport (UDP/TCP)

##### Architectural Patterns and Principles
- Layered architecture:
1. Application Layer (file operations, user interface)
2. RDT Layer (reliability, sequence numbers, ACKs)
3. Transport Layer (sockets over UDP/TCP)
- Single responsibility per module: packet.py handles packet concerns, util.py handles helpers.

##### Critical Elements
- Application logic
- Reliability layer
- Transport layer
- File system
- Call out Python’s socket API as the underlying mechanism

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Common library
    subgraph "Common Library"
        Common_Packet["Packet Module\n(packet.py)"]:::common
        Common_Util["Utility Helpers\n(util.py)"]:::common
    end

    %% Client Node
    subgraph "Client Node" 
        direction TB
        Client_CLI["Command-Line Interface"]:::app
        Client_FileIO["File I/O Module"]:::fs
        Client_RDT["RDT Layer"]:::rdt
        Client_Packet["Packet Module"]:::common
        Client_Transport["Transport Layer\n(UDP/TCP socket)"]:::transport
    end

    %% Server Node
    subgraph "Server Node"
        direction TB
        Server_CLI["Command-Line Interface"]:::app
        Server_FileIO["File I/O Module"]:::fs
        Server_RDT["RDT Layer"]:::rdt
        Server_Packet["Packet Module"]:::common
        Server_Transport["Transport Layer\n(UDP/TCP socket)"]:::transport
    end

    %% Network Channels
    subgraph "Network"
        direction TB
        Network_UDP["UDP Unreliable Channel"]:::network
        Network_TCP["TCP Reliable Channel"]:::network
    end

    %% Simulator
    Simulator["Simulator/Test Harness"]:::sim

    %% Data flow within client
    Client_CLI --> Client_FileIO
    Client_FileIO --> Client_RDT
    Client_RDT --> Client_Packet
    Client_Packet --> Client_Transport

    %% Data flow within server
    Server_CLI --> Server_FileIO
    Server_FileIO --> Server_RDT
    Server_RDT --> Server_Packet
    Server_Packet --> Server_Transport

    %% Network interactions
    Client_Transport -->|"Data Packets"| Network_UDP
    Client_Transport -->|"Data Stream"| Network_TCP
    Network_UDP -->|"Data Packets"| Server_Transport
    Network_TCP -->|"Data Stream"| Server_Transport

    Server_Transport -->|"ACK Packets"| Network_UDP
    Network_UDP -->|"ACK Packets"| Client_Transport

    %% Simulator interaction
    Simulator --> Network_UDP

    %% Click Events
    click Client_CLI "https://github.com/frozsgy/ceng435-hw/blob/main/client.py"
    click Client_FileIO "https://github.com/frozsgy/ceng435-hw/blob/main/util.py"
    click Client_RDT "https://github.com/frozsgy/ceng435-hw/blob/main/client.py"
    click Client_Packet "https://github.com/frozsgy/ceng435-hw/blob/main/packet.py"
    click Client_Transport "https://github.com/frozsgy/ceng435-hw/blob/main/client.py"
    click Server_CLI "https://github.com/frozsgy/ceng435-hw/blob/main/server.py"
    click Server_FileIO "https://github.com/frozsgy/ceng435-hw/blob/main/util.py"
    click Server_RDT "https://github.com/frozsgy/ceng435-hw/blob/main/server.py"
    click Server_Packet "https://github.com/frozsgy/ceng435-hw/blob/main/packet.py"
    click Server_Transport "https://github.com/frozsgy/ceng435-hw/blob/main/server.py"
    click Common_Util "https://github.com/frozsgy/ceng435-hw/blob/main/util.py"
    click Common_Packet "https://github.com/frozsgy/ceng435-hw/blob/main/packet.py"
    click Simulator "https://github.com/frozsgy/ceng435-hw/tree/main/simulator/"

    %% Styles
    classDef app fill:#FFD580,stroke:#333,stroke-width:1px
    classDef fs fill:#B3E5FC,stroke:#333,stroke-width:1px
    classDef rdt fill:#FFCCCB,stroke:#333,stroke-width:1px
    classDef transport fill:#C8E6C9,stroke:#333,stroke-width:1px
    classDef common fill:#E1BEE7,stroke:#333,stroke-width:1px
    classDef network fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef sim fill:#CFD8DC,stroke:#333,stroke-width:1px
```
