# libinfaby/transitnet architecture

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

- Interactive diagram: https://gitdiagram.com/libinfaby/transitnet
- Repository: https://github.com/libinfaby/transitnet

## Overview

##### Project type and purpose
- TransitNet is a standalone desktop application built with WPF (.NET 8) that enables peer-to-peer file sharing, chat, and transfer monitoring over a LAN without a central server.
- It targets Windows 10/11 machines communicating via UDP (discovery/chat) and TCP (file transfer).

##### File structure
- Top-level files:
- App.xaml / App.xaml.cs – application entry point and resource/schema definitions
- MainWindow.xaml / MainWindow.xaml.cs – main UI shell with tabbed layout
- TransitNet.csproj / .slnx – .NET project and solution definitions
- Directories:
- Dialogs – XAML windows for settings, file sharing, etc.
- Models – POCOs for ChatMessage, FileTransfer, Peer
- Services – core network/service modules:
– PeerDiscoveryService (UDP broadcast)
– FileTransferService (TCP transfer + progress)
– ChatService (UDP chat)
– NetworkService (IP management)
– ThemeService (UI theming)
- No centralized database; storage is local file system (Documents/Downloads).

##### README for additional insights
- Clearly outlines network ports (8888 UDP for discovery, 8889 TCP for transfers, 8890 UDP for chat).
- Highlights modular architecture: four major services plus a UI orchestration layer.
- Mentions configuration and troubleshooting (firewall, custom paths).

1. Presentation/UI Layer (WPF)
– MainWindow, Dialogs
– Binds to Models and calls Services
2. Service Layer
– PeerDiscoveryService
– ChatService
– FileTransferService
– NetworkService
– ThemeService
3. Network Layer
– UDP Broadcast (ports 8888, 8890)
– TCP Socket (port 8889)
4. Local Storage
– File system (Downloads folder)
5. External Peers
– Other TransitNet instances on LAN
b. Relationships and interactions:
– UI Layer → Service Layer: user actions (Send File, Chat) invoke service APIs.
– PeerDiscoveryService ↔ Network Layer (UDP broadcasts/inbound responses) → updates Models → UI.
– ChatService ↔ Network Layer (UDP chat packets) ↔ other peers → ChatMessage models → UI.
– FileTransferService ↔ Network Layer (TCP streams) ↔ other peers → writes to Local Storage; updates FileTransfer models → UI.
– NetworkService provides helper functions (IP enumeration, port selection) to the other services.
c. Architectural patterns and principles:
– Modular service-oriented design: each concern (discovery, chat, transfer) is encapsulated in its own service.
– MVVM-inspired layering: XAML UI binds to Models and orchestrates Services (though code-behind is used).
– Event-driven updates: services raise events or callbacks to update UI in real time.
– Direct peer-to-peer communication: no central server, purely LAN broadcast/point-to-point.
d. Key technologies/frameworks:
– WPF (.NET 8) for UI
– C# async/await + Sockets (System.Net.Sockets)
– UDPClient / TcpListener / TcpClient
– .NET Dependency Injection (if used via Startup), otherwise manual service instantiation
– Local file I/O (System.IO)

## Diagram (Mermaid)

```mermaid
graph TD
    %% Presentation/UI Layer
    subgraph "Presentation/UI Layer"
        direction TB
        AppX["App.xaml"]:::ui
        AppCS["App.xaml.cs"]:::ui
        MainX["MainWindow.xaml"]:::ui
        MainCS["MainWindow.xaml.cs"]:::ui
        FileDlgX["FileShareDialog.xaml"]:::ui
        FileDlgCS["FileShareDialog.xaml.cs"]:::ui
        SettingsX["SettingsDialog.xaml"]:::ui
        SettingsCS["SettingsDialog.xaml.cs"]:::ui
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        PeerDisc["PeerDiscoveryService"]:::service
        ChatSvc["ChatService"]:::service
        FileTx["FileTransferService"]:::service
        NetSvc["NetworkService"]:::service
        ThemeSvc["ThemeService"]:::service
    end

    %% Network Layer
    subgraph "Network Layer"
        direction TB
        UDPDisc["UDP Broadcast\n(port 8888)"]:::network
        UDPChat["UDP Chat\n(port 8890)"]:::network
        TCPTx["TCP Transfer\n(port 8889)"]:::network
    end

    %% Storage
    Storage["Local File System\n(Downloads)"]:::storage

    %% External Peers
    Peers["External Peers\n(TransitNet Instances)"]:::peer

    %% Connections: UI to Services
    MainCS -->|"Invoke Discovery"| PeerDisc
    MainCS -->|"Invoke Chat"| ChatSvc
    MainCS -->|"Invoke File Transfer"| FileTx
    MainCS -->|"Apply Theme"| ThemeSvc

    %% Services to Network
    PeerDisc -->|"UDP Broadcast: discovery"| UDPDisc
    UDPDisc -->|"Discovery Response"| PeerDisc
    ChatSvc -->|"UDP Chat Packet"| UDPChat
    UDPChat -->|"Received Chat"| ChatSvc
    FileTx -->|"TCP Stream"| TCPTx
    TCPTx -->|"Incoming File"| FileTx

    %% File service to storage
    FileTx -->|"Write File"| Storage

    %% Services to UI updates
    PeerDisc -->|"Peer List Update"| MainX
    ChatSvc -->|"New Message"| MainX
    FileTx -->|"Progress/Complete"| MainX

    %% Network interactions with peers
    UDPDisc -->|"Broadcast"| Peers
    UDPChat -->|"Chat"| Peers
    TCPTx -->|"File Stream"| Peers

    %% NetworkService support
    NetSvc -.-> PeerDisc
    NetSvc -.-> ChatSvc
    NetSvc -.-> FileTx
    NetSvc -.-> ThemeSvc

    %% Click Events
    click AppX "https://github.com/libinfaby/transitnet/blob/main/App.xaml"
    click AppCS "https://github.com/libinfaby/transitnet/blob/main/App.xaml.cs"
    click MainX "https://github.com/libinfaby/transitnet/blob/main/MainWindow.xaml"
    click MainCS "https://github.com/libinfaby/transitnet/blob/main/MainWindow.xaml.cs"
    click FileDlgX "https://github.com/libinfaby/transitnet/blob/main/Dialogs/FileShareDialog.xaml"
    click FileDlgCS "https://github.com/libinfaby/transitnet/blob/main/Dialogs/FileShareDialog.xaml.cs"
    click SettingsX "https://github.com/libinfaby/transitnet/blob/main/Dialogs/SettingsDialog.xaml"
    click SettingsCS "https://github.com/libinfaby/transitnet/blob/main/Dialogs/SettingsDialog.xaml.cs"
    click PeerDisc "https://github.com/libinfaby/transitnet/blob/main/Services/PeerDiscoveryService.cs"
    click ChatSvc "https://github.com/libinfaby/transitnet/blob/main/Services/ChatService.cs"
    click FileTx "https://github.com/libinfaby/transitnet/blob/main/Services/FileTransferService.cs"
    click NetSvc "https://github.com/libinfaby/transitnet/blob/main/Services/NetworkService.cs"
    click ThemeSvc "https://github.com/libinfaby/transitnet/blob/main/Services/ThemeService.cs"
    click Storage "https://github.com/libinfaby/transitnet/blob/main/TransitNet.csproj"
    click Peers "https://github.com/libinfaby/transitnet/blob/main/TransitNet.slnx"

    %% Styles
    classDef ui fill:#D6E4FF,stroke:#5B8FF9,color:#000
    classDef service fill:#D9F7BE,stroke:#52C41A,color:#000
    classDef network fill:#FFE58F,stroke:#FAAD14,color:#000
    classDef storage fill:#F0F0F0,stroke:#8C8C8C,color:#000
    classDef peer fill:#FFCCC7,stroke:#F5222D,color:#000
```
