# fardays90/filezone architecture

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

- Interactive diagram: https://gitdiagram.com/fardays90/filezone
- Repository: https://github.com/fardays90/filezone

## Overview

1. **Overall shape**
   - FileZone is a two-part system: a **Go signaling server** and a **React/WebRTC client**.
   - The important architectural boundary is that the backend is **not a file store**; it only helps peers find each other and establish connections. File payloads move **directly between browsers**.

2. **Backend role**
   - The repository root contains `main.go` plus `go.mod/go.sum`, which indicates a small Go service.
   - From the README, this server provides **WebSocket signaling** and room coordination.
   - Its responsibility is to manage room membership and exchange connection setup messages, not to relay or persist user files.

3. **Frontend application**
   - The client lives in `client/FileZone` and is a **React + TypeScript + Vite** app styled with **Tailwind**.
   - `src/main.tsx` bootstraps the app, while `src/App.tsx` and `src/Home.tsx` likely separate the entry experience from the active room experience.
   - This client is the main orchestration layer for both signaling and WebRTC transfer.

4. **Room-based interaction model**
   - The app is organized around a **room** concept, reflected by `src/Room.tsx`.
   - Users first join or create a room, then the app connects them to the other peers currently in that room.
   - This room boundary is the point where signaling, peer discovery, text messages, and file transfer all come together.

5. **State management boundaries**
   - The `hooks` directory contains domain-specific stores:
     - `useSocketStore.ts` for signaling/WebSocket state,
     - `usePeerStore.ts` for connected peer state,
     - `useFileStore.ts` for file transfer state,
     - `useTextStore.ts` for chat/text message state.
   - This suggests the client separates transport state from UI state, which is useful for a diagram: each store is a distinct subsystem feeding the room UI.

6. **WebSocket signaling path**
   - `useSocketStore.ts` is the likely client-side entry point to the Go server.
   - The data flow here is control-plane only: join room, announce presence, exchange WebRTC offers/answers/ICE candidates, and coordinate peer lifecycle.
   - Once the WebRTC connection is established, the Go server is no longer involved in file delivery.

7. **Peer-to-peer transfer path**
   - `utils/peerManager.ts` is the core WebRTC subsystem on the client.
   - It likely creates and manages `RTCPeerConnection` instances and DataChannels for each remote peer.
   - This is the actual data plane: files and other room messages move directly from sender browser to receiver browser over WebRTC.

8. **File handling and browser storage**
   - `useFileStore.ts` and `utils/opfsWriter.ts` indicate that received files are written to the browser using the **Origin Private File System (OPFS)** or a similar browser-managed storage layer.
   - This means incoming file data is assembled and persisted locally on the recipient side, rather than uploaded to any central backend.
   - For the diagram, this is a local sink on the receiving client, not a server-side storage tier.

9. **Text and file UI components**
   - `src/TextInput.tsx`, `IncomingBubble.tsx`, `OutgoingBubble.tsx`, `UploadedFile.tsx`, and `ReceivedFIle.tsx` form the presentation layer for room activity.
   - These components render the status of messages and transfers, separating sender/receiver views and likely reflecting progress/completion states.
   - They sit on top of the store layer and do not appear to own transport logic themselves.

10. **Client runtime and offline support**
    - `public/serviceWorker.js` suggests the client may register a service worker for caching/offline behavior or improved load reliability.
    - `src/index.css`, `src/App.css`, and `tailwind.config.js` show the UI is styled with Tailwind plus app-specific CSS.
    - These are supporting concerns, not core architecture, but they affect how the browser app is delivered and cached.

11. **Primary end-to-end flow**
    - User opens the client, joins a room, and the client connects to the Go WebSocket server.
    - The server coordinates signaling so peers can establish WebRTC connections.
    - After the peer mesh is formed, text and files flow directly over DataChannels.
    - Received files are written locally in the browser, and the UI updates through the Zustand stores.

12. **What to emphasize in an architecture diagram**
    - Draw three main boundaries: **browser UI/state**, **Go signaling server**, and **direct peer-to-peer WebRTC links**.
    - Show the server only on the signaling path, not the file path.
    - Show the client split into transport/state management, peer connection management, and UI/rendering, with local browser storage as the final destination for received files.

Main entry points: [`client/FileZone/src/Room.tsx`](https://github.com/fardays90/filezone/blob/main/client/FileZone/src/Room.tsx) (Room view), [`client/FileZone/utils/peerManager.ts`](https://github.com/fardays90/filezone/blob/main/client/FileZone/utils/peerManager.ts) (Peer manager), [`client/FileZone/hooks/useSocketStore.ts`](https://github.com/fardays90/filezone/blob/main/client/FileZone/hooks/useSocketStore.ts) (Socket store), [`client/FileZone/src/App.tsx`](https://github.com/fardays90/filezone/blob/main/client/FileZone/src/App.tsx) (App shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Go signaling"]
  node_go_server["Signaling server<br/>Go/WebSocket server<br/>[main.go]"]
end

subgraph group_client["Browser client"]
  node_socket_store["Socket store<br/>client socket state<br/>[useSocketStore.ts]"]
  node_peer_store["Peer store<br/>client peer state<br/>[usePeerStore.ts]"]
  node_file_store["File store<br/>client transfer state<br/>[useFileStore.ts]"]
  node_text_store["Text store<br/>client chat state<br/>[useTextStore.ts]"]
  node_peer_manager["Peer manager<br/>WebRTC engine<br/>[peerManager.ts]"]
  node_opfs_writer[("OPFS writer<br/>browser storage<br/>[opfsWriter.ts]")]
  node_main_entry["Main entry<br/>React bootstrap<br/>[main.tsx]"]
  node_app_shell["App shell<br/>React shell<br/>[App.tsx]"]
  node_home_screen["Home screen<br/>join/create UI<br/>[Home.tsx]"]
  node_room_view["Room view<br/>room UI<br/>[Room.tsx]"]
  node_text_input["Text input<br/>composer UI<br/>[TextInput.tsx]"]
  node_incoming_bubble["Incoming bubble<br/>message UI<br/>[IncomingBubble.tsx]"]
  node_outgoing_bubble["Outgoing bubble<br/>message UI<br/>[OutgoingBubble.tsx]"]
  node_uploaded_file["Uploaded file<br/>file UI<br/>[UploadedFile.tsx]"]
  node_received_file["Received file<br/>file UI<br/>[ReceivedFIle.tsx]"]
  node_service_worker["Service worker<br/>browser support<br/>[serviceWorker.js]"]
end

node_main_entry -->|"starts"| node_app_shell
node_app_shell -->|"shows"| node_home_screen
node_app_shell -->|"navigates to"| node_room_view
node_room_view -->|"uses"| node_socket_store
node_room_view -->|"uses"| node_peer_store
node_room_view -->|"uses"| node_file_store
node_room_view -->|"uses"| node_text_store
node_room_view -->|"contains"| node_text_input
node_room_view -->|"contains"| node_incoming_bubble
node_room_view -->|"contains"| node_outgoing_bubble
node_room_view -->|"contains"| node_uploaded_file
node_room_view -->|"contains"| node_received_file
node_socket_store -->|"signaling"| node_go_server
node_socket_store -->|"feeds"| node_peer_manager
node_peer_manager -->|"updates"| node_peer_store
node_peer_manager -->|"streams"| node_file_store
node_peer_manager -->|"streams"| node_text_store
node_file_store -->|"persists"| node_opfs_writer
node_service_worker -.->|"supports"| node_main_entry

click node_go_server "https://github.com/fardays90/filezone/blob/main/main.go"
click node_socket_store "https://github.com/fardays90/filezone/blob/main/client/FileZone/hooks/useSocketStore.ts"
click node_peer_store "https://github.com/fardays90/filezone/blob/main/client/FileZone/hooks/usePeerStore.ts"
click node_file_store "https://github.com/fardays90/filezone/blob/main/client/FileZone/hooks/useFileStore.ts"
click node_text_store "https://github.com/fardays90/filezone/blob/main/client/FileZone/hooks/useTextStore.ts"
click node_peer_manager "https://github.com/fardays90/filezone/blob/main/client/FileZone/utils/peerManager.ts"
click node_opfs_writer "https://github.com/fardays90/filezone/blob/main/client/FileZone/utils/opfsWriter.ts"
click node_main_entry "https://github.com/fardays90/filezone/blob/main/client/FileZone/src/main.tsx"
click node_app_shell "https://github.com/fardays90/filezone/blob/main/client/FileZone/src/App.tsx"
click node_home_screen "https://github.com/fardays90/filezone/blob/main/client/FileZone/src/Home.tsx"
click node_room_view "https://github.com/fardays90/filezone/blob/main/client/FileZone/src/Room.tsx"
click node_text_input "https://github.com/fardays90/filezone/blob/main/client/FileZone/src/TextInput.tsx"
click node_incoming_bubble "https://github.com/fardays90/filezone/blob/main/client/FileZone/src/IncomingBubble.tsx"
click node_outgoing_bubble "https://github.com/fardays90/filezone/blob/main/client/FileZone/src/OutgoingBubble.tsx"
click node_uploaded_file "https://github.com/fardays90/filezone/blob/main/client/FileZone/src/UploadedFile.tsx"
click node_received_file "https://github.com/fardays90/filezone/blob/main/client/FileZone/src/ReceivedFIle.tsx"
click node_service_worker "https://github.com/fardays90/filezone/blob/main/client/FileZone/public/serviceWorker.js"

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_go_server toneBlue
class node_socket_store,node_peer_store,node_file_store,node_text_store,node_peer_manager,node_opfs_writer,node_main_entry,node_app_shell,node_home_screen,node_room_view,node_text_input,node_incoming_bubble,node_outgoing_bubble,node_uploaded_file,node_received_file,node_service_worker toneAmber
```

## Components

### Go signaling

Room coordination and WebSocket signaling only

- [Signaling server](https://github.com/fardays90/filezone/blob/main/main.go): Go/WebSocket server · Coordinates rooms and exchanges connection setup messages · `main.go`

### Browser client

React app, state, WebRTC peers, and local file handling

- [Socket store](https://github.com/fardays90/filezone/blob/main/client/FileZone/hooks/useSocketStore.ts): client socket state · Holds WebSocket connection and signaling events · `client/FileZone/hooks/useSocketStore.ts`
- [Peer store](https://github.com/fardays90/filezone/blob/main/client/FileZone/hooks/usePeerStore.ts): client peer state · Tracks connected peers and connection lifecycle · `client/FileZone/hooks/usePeerStore.ts`
- [File store](https://github.com/fardays90/filezone/blob/main/client/FileZone/hooks/useFileStore.ts): client transfer state · Tracks file transfer progress and received payloads · `client/FileZone/hooks/useFileStore.ts`
- [Text store](https://github.com/fardays90/filezone/blob/main/client/FileZone/hooks/useTextStore.ts): client chat state · Tracks room text messages and message state · `client/FileZone/hooks/useTextStore.ts`
- [Peer manager](https://github.com/fardays90/filezone/blob/main/client/FileZone/utils/peerManager.ts): WebRTC engine · Creates and manages peer connections and data channels · `client/FileZone/utils/peerManager.ts`
- [OPFS writer](https://github.com/fardays90/filezone/blob/main/client/FileZone/utils/opfsWriter.ts): browser storage · Writes received files into local browser storage · `client/FileZone/utils/opfsWriter.ts`
- [Main entry](https://github.com/fardays90/filezone/blob/main/client/FileZone/src/main.tsx): React bootstrap · Bootstraps the browser app · `client/FileZone/src/main.tsx`
- [App shell](https://github.com/fardays90/filezone/blob/main/client/FileZone/src/App.tsx): React shell · Top-level app composition and routing · `client/FileZone/src/App.tsx`
- [Home screen](https://github.com/fardays90/filezone/blob/main/client/FileZone/src/Home.tsx): join/create UI · Entry experience for joining or creating a room · `client/FileZone/src/Home.tsx`
- [Room view](https://github.com/fardays90/filezone/blob/main/client/FileZone/src/Room.tsx): room UI · Main room workspace where peers, chat, and files meet · `client/FileZone/src/Room.tsx`
- [Text input](https://github.com/fardays90/filezone/blob/main/client/FileZone/src/TextInput.tsx): composer UI · Lets users send room messages · `client/FileZone/src/TextInput.tsx`
- [Incoming bubble](https://github.com/fardays90/filezone/blob/main/client/FileZone/src/IncomingBubble.tsx): message UI · Renders received chat or transfer status · `client/FileZone/src/IncomingBubble.tsx`
- [Outgoing bubble](https://github.com/fardays90/filezone/blob/main/client/FileZone/src/OutgoingBubble.tsx): message UI · Renders sent chat or transfer status · `client/FileZone/src/OutgoingBubble.tsx`
- [Uploaded file](https://github.com/fardays90/filezone/blob/main/client/FileZone/src/UploadedFile.tsx): file UI · Shows outbound file items and transfer state · `client/FileZone/src/UploadedFile.tsx`
- [Received file](https://github.com/fardays90/filezone/blob/main/client/FileZone/src/ReceivedFIle.tsx): file UI · Shows inbound files and local availability · `client/FileZone/src/ReceivedFIle.tsx`
- [Service worker](https://github.com/fardays90/filezone/blob/main/client/FileZone/public/serviceWorker.js): browser support · Provides caching or offline support for the client · `client/FileZone/public/serviceWorker.js`

## Connections

- Main entry → App shell: starts · Bootstraps the top-level app
- App shell → Home screen: shows · Entry flow for room access
- App shell → Room view: navigates to · Main collaborative room experience
- Room view → Socket store: uses · Connects to signaling and room membership
- Room view → Peer store: uses · Displays and manages connected peers
- Room view → File store: uses · Reflects transfer progress and received files
- Room view → Text store: uses · Renders and sends room chat
- Room view → Text input: contains · Message composer inside room
- Room view → Incoming bubble: contains · Inbound message rendering
- Room view → Outgoing bubble: contains · Outbound message rendering
- Room view → Uploaded file: contains · Outbound file rendering
- Room view → Received file: contains · Inbound file rendering
- Socket store → Signaling server: signaling · Joins rooms and exchanges WebRTC setup messages
- Socket store → Peer manager: feeds · Hands off signaling events needed for peer setup
- Peer manager → Peer store: updates · Publishes peer lifecycle and connection state
- Peer manager → File store: streams · Delivers file data over DataChannels
- Peer manager → Text store: streams · Delivers chat and room messages directly peer-to-peer
- File store → OPFS writer: persists · Writes received payloads locally in the browser
- Service worker → Main entry: supports · Client-side load and caching support
