# anthdm/distributedfilesystemgo architecture

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

- Interactive diagram: https://gitdiagram.com/anthdm/distributedfilesystemgo
- Repository: https://github.com/anthdm/distributedfilesystemgo

## Overview

#### Purpose and entry points
This is a Go peer-to-peer storage application: a server combines local persistence, cryptographic protection, and a TCP-based P2P transport. Process startup is in `main.go`; server orchestration is centered in `server.go`.

#### Runtime composition
The binary runs on the Go runtime and uses direct TCP networking rather than an HTTP/web runtime. The module boundary and third-party Go dependencies are defined by `go.mod` and `go.sum`. No managed cloud service, database server, or external API integration is evident from the repository tree.

#### Server orchestration
`server.go` is the primary application control plane. It likely owns peer lifecycle, message handling, storage operations, and coordination between the P2P transport and local store. `main.go` constructs/configures this server and starts the long-running node process.

#### P2P transport layer
The `p2p` package isolates network concerns from application storage logic.
- `p2p/transport.go` defines the transport-facing abstraction used by higher layers.
- `p2p/tcp_transport.go` implements peer connectivity and message movement over TCP.
- `p2p/handshake.go` establishes a newly connected peer before normal application traffic.

This boundary allows server code to consume peers/messages without being tightly coupled to socket details.

#### Protocol framing and peer messages
Wire-format responsibility is separated inside `p2p`.
- `p2p/message.go` represents protocol messages exchanged between nodes.
- `p2p/encoding.go` serializes and deserializes those messages.
- `p2p/handshake.go` handles connection-establishment traffic.

Primary flow: TCP connection → handshake → encode/decode framed messages → deliver to server-level handlers.

#### Storage and cryptography pipeline
`store.go` provides the local persistence boundary for stored data. `crypto.go` provides cryptographic operations used to protect stored or transferred content. The expected application flow is: server receives a storage/retrieval request or peer message, applies cryptographic processing as required, then writes to or reads from the local store; network payloads are exchanged through the P2P layer.

#### Key architectural boundaries
- Application lifecycle and policy: `main.go`, `server.go`
- Local durable-data access: `store.go`
- Cryptographic transformation: `crypto.go`
- Network transport/protocol: `p2p/transport.go`, `p2p/tcp_transport.go`, `p2p/message.go`

Tests adjacent to these boundaries (`store_test.go`, `crypto_test.go`, and `p2p/tcp_transport_test.go`) indicate storage, encryption, and TCP transport are independently verifiable components.

Main entry points: [`p2p/tcp_transport.go`](https://github.com/anthdm/distributedfilesystemgo/blob/master/p2p/tcp_transport.go) (TCP transport), [`server.go`](https://github.com/anthdm/distributedfilesystemgo/blob/master/server.go) (Server), [`main.go`](https://github.com/anthdm/distributedfilesystemgo/blob/master/main.go) (Process entry), [`p2p/transport.go`](https://github.com/anthdm/distributedfilesystemgo/blob/master/p2p/transport.go) (Transport interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_main["Process entry<br/>entrypoint<br/>[main.go]"]
  node_server["Server<br/>orchestrator<br/>[server.go]"]
end

subgraph group_p2p["P2P Network"]
  node_transport["Transport interface<br/>network abstraction<br/>[transport.go]"]
  node_tcp_transport["TCP transport<br/>transport implementation<br/>[tcp_transport.go]"]
  node_handshake["Peer handshake<br/>connection protocol<br/>[handshake.go]"]
  node_messages["Peer messages<br/>wire model<br/>[message.go]"]
  node_encoding["Message encoding<br/>protocol codec<br/>[encoding.go]"]
  node_tcp_peers(("Remote peers<br/>external nodes"))
end

subgraph group_data["Data Protection"]
  node_crypto["Cryptography<br/>data protection<br/>[crypto.go]"]
  node_store[("Local store<br/>persistence<br/>[store.go]")]
end

node_go_runtime(("Go runtime"))
node_module["Go module<br/>[go.mod]"]

node_go_runtime -->|"runs"| node_main
node_module -.->|"defines dependencies"| node_go_runtime
node_main -->|"constructs and starts"| node_server
node_server -->|"uses"| node_transport
node_transport -->|"implemented by"| node_tcp_transport
node_tcp_transport -->|"TCP connections"| node_tcp_peers
node_tcp_transport -->|"establishes peers"| node_handshake
node_tcp_transport -->|"frames traffic"| node_encoding
node_encoding -->|"encodes and decodes"| node_messages
node_tcp_transport -->|"delivers peer messages"| node_server
node_server -->|"protects content"| node_crypto
node_crypto -->|"transforms data for"| node_store
node_server -->|"reads and writes"| node_store

click node_module "https://github.com/anthdm/distributedfilesystemgo/blob/master/go.mod"
click node_main "https://github.com/anthdm/distributedfilesystemgo/blob/master/main.go"
click node_server "https://github.com/anthdm/distributedfilesystemgo/blob/master/server.go"
click node_transport "https://github.com/anthdm/distributedfilesystemgo/blob/master/p2p/transport.go"
click node_tcp_transport "https://github.com/anthdm/distributedfilesystemgo/blob/master/p2p/tcp_transport.go"
click node_handshake "https://github.com/anthdm/distributedfilesystemgo/blob/master/p2p/handshake.go"
click node_messages "https://github.com/anthdm/distributedfilesystemgo/blob/master/p2p/message.go"
click node_encoding "https://github.com/anthdm/distributedfilesystemgo/blob/master/p2p/encoding.go"
click node_crypto "https://github.com/anthdm/distributedfilesystemgo/blob/master/crypto.go"
click node_store "https://github.com/anthdm/distributedfilesystemgo/blob/master/store.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_server toneBlue
class node_transport,node_tcp_transport,node_handshake,node_messages,node_encoding,node_tcp_peers toneAmber
class node_crypto,node_store toneMint
class node_go_runtime,node_module toneNeutral
```

## Components

### Application

- [Process entry](https://github.com/anthdm/distributedfilesystemgo/blob/master/main.go): entrypoint · Constructs and starts the node server. · `main.go`
- [Server](https://github.com/anthdm/distributedfilesystemgo/blob/master/server.go): orchestrator · Coordinates peer lifecycle, storage, and message handling. · `server.go`

### P2P Network

- [Transport interface](https://github.com/anthdm/distributedfilesystemgo/blob/master/p2p/transport.go): network abstraction · `p2p/transport.go`
- [TCP transport](https://github.com/anthdm/distributedfilesystemgo/blob/master/p2p/tcp_transport.go): transport implementation · Manages peer connectivity and TCP message movement. · `p2p/tcp_transport.go`
- [Peer handshake](https://github.com/anthdm/distributedfilesystemgo/blob/master/p2p/handshake.go): connection protocol · Establishes peers before application traffic. · `p2p/handshake.go`
- [Peer messages](https://github.com/anthdm/distributedfilesystemgo/blob/master/p2p/message.go): wire model · `p2p/message.go`
- [Message encoding](https://github.com/anthdm/distributedfilesystemgo/blob/master/p2p/encoding.go): protocol codec · Serializes and deserializes framed peer messages. · `p2p/encoding.go`
- **Remote peers**: external nodes · Other nodes reached over direct TCP.

### Data Protection

- [Cryptography](https://github.com/anthdm/distributedfilesystemgo/blob/master/crypto.go): data protection · Protects content for storage or transfer. · `crypto.go`
- [Local store](https://github.com/anthdm/distributedfilesystemgo/blob/master/store.go): persistence · Local durable-data boundary. · `store.go`

### Other components

- **Go runtime**: runtime
- [Go module](https://github.com/anthdm/distributedfilesystemgo/blob/master/go.mod): module · Dependency and module boundary. · `go.mod`

## Connections

- Go runtime → Process entry: runs
- Go module → Go runtime: defines dependencies
- Process entry → Server: constructs and starts
- Server → Transport interface: uses
- Transport interface → TCP transport: implemented by
- TCP transport → Remote peers: TCP connections
- TCP transport → Peer handshake: establishes peers
- TCP transport → Message encoding: frames traffic
- Message encoding → Peer messages: encodes and decodes
- TCP transport → Server: delivers peer messages
- Server → Cryptography: protects content
- Cryptography → Local store: transforms data for
- Server → Local store: reads and writes
