# giovaneps/arquivos-distribuidos architecture

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

## Overview

##### The daemon
- Located in the “daemon” directory, this is the server component responsible for receiving files, managing concurrent transfers, applying transfer rate limits, and handling partial file transfers (using the .part extension as described).
- It likely uses Berkeley Sockets for network communication and manages incoming connections from multiple clients.

##### The remcp tool
- Found in the “remcp” directory, this client component is used to send and receive files. It prepares the network request, handles file transfers (including checking for partial transfers and resuming as needed), and interacts with the server daemon.
- The “utils” subdirectory suggests that common helper functions are implemented for file operations or network handling.

Additionally, the “relatorio” directory contains report files (PDF, LaTeX) that document the system and probably provide further context for the implemented design, while “INE5645_trabalho2.pdf” and README serve as project documentation.

##### Main Components
- Client (remcp):
- Command-line interface (CLI) entry point for file transfer actions.
- File handling module to check local files, create or update temporary “.part” files.
- Network module that establishes a connection to the remote daemon using Berkeley Sockets.
- Server (daemon):
- Network listener that accepts incoming file transfer requests.
- Transfer management system that supports multiple simultaneous clients and enforces a configurable transfer rate limit.
- File receiver that handles incoming data, saves to temporary “.part” files, and renames them once transfer is complete.
- Network Infrastructure:
- Underlying communication using Berkeley Sockets.
- Directional data flows between client and server.

##### Relationships and Interactions
- The remcp client initiates a connection to the server daemon over the network.
- Data flows inbound from the client to the daemon when sending files, and vice versa when receiving.
- The client checks for and handles partial file transfers by verifying the existence of “.part” files, then sends only the remaining data.
- The server concurrently manages multiple connections by allocating specific portions of the overall rate limit to each client.

##### Architectural Patterns and Design Principles
- Modularity: The project cleanly separates the client and server functionalities into different directories (remcp and daemon), which suggests a layered architecture.
- Concurrency: The daemon is designed to handle multiple clients concurrently, so consider showing a “connection manager” or “thread pool” abstraction.
- Resilience: The use of temporary “.part” files to handle interruptions and resume transfers indicates the importance of fault tolerance.
- Network abstraction: Leveraging Berkeley Sockets as the base for distributed, socket-based communication.

##### Relevant Technologies and Frameworks
- The programming language is Go (as shown by the *.go files and go.mod), so you may wish to note Go’s routines for concurrency and network libraries.
- Mention that the system is designed to work with Unix-based file paths and environments.

## Diagram (Mermaid)

```mermaid
graph TD
  subgraph "Client Side (remcp)"
    clientMain["remcp Client"]:::client
    clientCLI["CLI Entry Point"]:::client
    clientFile["File Handling Manager (.part)"]:::client
    clientNet["Network Module (Berkeley Sockets)"]:::client
    clientMain --> clientCLI
    clientCLI --> clientFile
    clientFile --> clientNet
  end

  subgraph "Network Layer"
    net["Berkeley Sockets Communication"]:::network
  end

  subgraph "Server Side (Daemon)"
    serverMain["Daemon Server"]:::server
    serverNL["Network Listener"]:::server
    serverTM["Transfer Manager (Concurrency&RateLimit)"]:::server
    serverFR["File Receiver (.part)"]:::server
    serverMain --> serverNL
    serverNL --> serverTM
    serverTM --> serverFR
  end

  subgraph "Documentation"
    docPDF["Report (PDF)"]:::docs
    docTEX["Report (LaTeX)"]:::docs
    docREADME["README"]:::docs
    docOverview["Overview (PDF)"]:::docs
  end

  %% Data flow connections
  clientNet -->|"transferRequest"| net
  net -->|"incomingData"| serverNL
  serverFR -->|"acknowledgment"| net
  net -->|"responseData"| clientNet

  %% Additional links to documentation
  clientMain ---|"docLink"| docREADME
  serverMain ---|"docLink"| docOverview

  %% Click Events
  click clientMain "https://github.com/giovaneps/arquivos-distribuidos/blob/master/remcp/remcp.go"
  click clientFile "https://github.com/giovaneps/arquivos-distribuidos/blob/master/remcp/utils/utils.go"
  click serverMain "https://github.com/giovaneps/arquivos-distribuidos/blob/master/daemon/daemon.go"
  click docPDF "https://github.com/giovaneps/arquivos-distribuidos/blob/master/relatorio/relatorio.pdf"
  click docTEX "https://github.com/giovaneps/arquivos-distribuidos/blob/master/relatorio/relatorio.tex"
  click docREADME "https://github.com/giovaneps/arquivos-distribuidos/blob/master/README.md"
  click docOverview "https://github.com/giovaneps/arquivos-distribuidos/blob/master/INE5645_trabalho2.pdf"

  %% Styles
  classDef client fill:#aec6cf,stroke:#333,stroke-width:2px;
  classDef server fill:#77dd77,stroke:#333,stroke-width:2px;
  classDef network fill:#ffb347,stroke:#333,stroke-width:2px;
  classDef docs fill:#cfcfcf,stroke:#333,stroke-width:2px;
```
