# eldrago12/distributedfilesystem architecture

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

- Interactive diagram: https://gitdiagram.com/eldrago12/distributedfilesystem
- Repository: https://github.com/eldrago12/distributedfilesystem

## Overview

##### Core Components
- DistributedFS Node: At the heart of the system are the nodes that run this service. Each node may include a server component, a client interface, and background services for maintaining network state.
- Client Module: Found in the “client” directory (client/client.go), this module likely handles operations from the user’s perspective, interfacing with the service APIs.
- Server Module: Located in the “server” directory (server/service.go), this handles incoming requests, file storage operations, and coordination with other nodes.
- TCP Connection Module: The “tcpconn” package (tcpconn/tcp.go) encapsulates the custom peer-to-peer TCP communication logic.
- Gossip Module: In the “gossip” directory (gossip/gossip.go), this module is responsible for disseminating state information (such as node membership and file storage metadata) across the distributed network.
- API/Communication Contracts: The “proto” directory contains the protocol buffers definitions (dfs.proto) and the generated Go files, indicating that parts of the system might be accessible via gRPC or other protobuf-based mechanisms.
- Main Entry Point: The “cmd/main.go” illustrates where the node or service is bootstrapped, initializing all these components.
- Dockerfile: Indicates containerization, so deployment aspects are also part of the overall architecture.

##### Relationships and Interactions
- The Client interacts with the Server through defined service APIs (most likely via gRPC or custom TCP APIs using the protocol buffers definitions).
- The Server processes client requests and concurrently communicates with other nodes through the custom TCP connection (through the tcpconn module).
- The Gossip service periodically exchanges state and health information with peer nodes to manage distributed consistency and membership.
- The protocol buffers (proto folder) serve as an inter-service contract not only between client and server, but also for internal messaging between nodes.
- Docker encapsulation manages the deployment and environment consistency for the overall distributed system.

##### Architectural Patterns & Technologies
- Distributed Systems: The overall design is decentralized with peer-to-peer communication.
- Microservices/Modular Structure: Each component (client, server, gossip, tcp connection) is independently implemented, suggesting modularity.
- Custom Networking: The tcpconn package implies a tailored TCP communication mechanism differs from standard libraries.
- Protobuf/gRPC: The system uses protocol buffers which might also imply gRPC interfaces, ensuring structured, language-agnostic communication.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User/Client Layer
    subgraph "User/Client Layer"
        ClientModule["Client Module"]:::client
    end

    %% Application/Service Layer
    subgraph "Application/Service Layer"
        MainEntryPoint["DistributedFS Node (Main Entry Point)"]:::service
        ServerModule["Server / Service"]:::service
        MainEntryPoint -->|"initializes"| ServerModule
    end

    %% Communication Layer
    subgraph "Communication Layer"
        TCPConnection["TCP Connection Module"]:::network
        GossipModule["Gossip Module"]:::network
    end

    %% API Contract Layer
    subgraph "API Contract Layer"
        APIProto["dfs.proto"]:::contract
        APIPB["dfs.pb.go"]:::contract
        APIGRPC["dfs_grpc.pb.go"]:::contract
    end

    %% Infrastructure/Deployment Layer
    subgraph "Infrastructure/Deployment Layer"
        DockerDeployment["Docker Deployment"]:::deployment
    end

    %% Relationships
    ClientModule -->|"sends_request"| ServerModule
    ClientModule -->|"uses_API"| APIProto
    ServerModule -->|"implements_API"| APIProto
    ServerModule -->|"p2p_comm"| TCPConnection
    MainEntryPoint -->|"updates_state"| GossipModule
    GossipModule -->|"reports_state"| MainEntryPoint
    DockerDeployment -->|"containerizes"| MainEntryPoint

    %% Styles
    classDef client fill:#a8e6cf,stroke:#333,stroke-width:2px;
    classDef service fill:#81d4fa,stroke:#333,stroke-width:2px;
    classDef network fill:#ffd3b6,stroke:#333,stroke-width:2px;
    classDef contract fill:#fff59d,stroke:#333,stroke-width:2px;
    classDef deployment fill:#f48fb1,stroke:#333,stroke-width:2px;

    %% Click Events
    click ClientModule "https://github.com/eldrago12/distributedfilesystem/blob/main/client/client.go"
    click MainEntryPoint "https://github.com/eldrago12/distributedfilesystem/blob/main/cmd/main.go"
    click ServerModule "https://github.com/eldrago12/distributedfilesystem/blob/main/server/service.go"
    click TCPConnection "https://github.com/eldrago12/distributedfilesystem/blob/main/tcpconn/tcp.go"
    click GossipModule "https://github.com/eldrago12/distributedfilesystem/blob/main/gossip/gossip.go"
    click APIProto "https://github.com/eldrago12/distributedfilesystem/blob/main/proto/dfs.proto"
    click APIPB "https://github.com/eldrago12/distributedfilesystem/blob/main/proto/dfs.pb.go"
    click APIGRPC "https://github.com/eldrago12/distributedfilesystem/blob/main/proto/dfs_grpc.pb.go"
    click DockerDeployment "https://github.com/eldrago12/distributedfilesystem/tree/main/Dockerfile"
```
