# logicreinc/logicreinc.blendfarm architecture

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

- Interactive diagram: https://gitdiagram.com/logicreinc/logicreinc.blendfarm
- Repository: https://github.com/logicreinc/logicreinc.blendfarm

## Overview

##### Project Type and Purpose
- BlendFarm is a distributed network‐rendering system for Blender, composed of a headless render “server” (render node) and a cross-platform GUI “client,” sharing a common messaging library.
- Purpose: coordinate multiple machines over the LAN to split and accelerate Blender renders.

##### File Structure
- Top-level solution (LogicReinc.BlendFarm.sln)
- LogicReinc.BlendFarm.Client – GUI front-end (Avalonia + .NET Core)
- LogicReinc.BlendFarm.Server – headless render node (console app + Python helper scripts)
- LogicReinc.BlendFarm.Shared – common DTOs, protocol, binary parser, exceptions
- LogicReinc.BlendFarm – the packaged desktop app and UI logic
- LogicReinc.BlendFarm.Tests – unit and integration tests
- .data, .resources – static assets (announcements, example media)
- build scripts (build-osx-arm.sh, build-server.sh)
- Notice configuration files (nuget.config), automation scripts (extract_dependencies.py, peek.py, render.py).

##### Readme Insights
- Architecture: custom TCP protocol for commands & file sync; UDP broadcasts for auto-discovery.
- Technologies: C# / .NET Core 3.0, Avalonia UI, Python for Blender orchestration.
- Features: split/chunked rendering strategies, auto-download Blender versions, live re-render on save.

##### Main Components
a. Client GUI (LogicReinc.BlendFarm.Client & LogicReinc.BlendFarm)
b. Render Server (LogicReinc.BlendFarm.Server)
c. Shared Library (LogicReinc.BlendFarm.Shared)
d. External Blender Engine (spawned processes; versions in BlenderData)
e. Networking segments (UDP discovery, TCP command & data channel)
f. Local file storage (.blend files, assets) and optional announcements service

##### Relationships & Data Flows
- UDP Broadcast: Client → Network → Server (auto-discovery)
- TCP Connection: Client ⇄ Server (handshake, version check, sync, task dispatch)
- File Sync: Client pushes updated .blend and dependencies via TCP (FileUpload messages)
- Task Dispatch: Client sends RenderBatchRequest / RenderRequest
- Blender Process Lifecycle: Server spawns Blender child process → renders chunks → streams RenderInfoResponse / image data back
- Performance Feedback: Server reports timings; Client uses shared library to adjust chunk distribution

##### Architectural Patterns & Principles
- MVVM (Client UI layer separated from logic/controllers)
- Layered Architecture:
- Presentation (Avalonia UI)
- Application (Client/Server logic)
- Shared Domain (Messaging, Models)
- Infrastructure (TCP/UDP transport, Blender process management)
- Single Responsibility: each assembly focuses on one concern (UI vs. server vs. shared protocol)
- Modular Extensibility: new rendering strategies (Split, Chunked) implemented via strategy pattern in Tasks/

##### Key Technologies & Libraries
- C# .NET Core 3.0
- Avalonia UI (cross-platform GUI)
- Custom TCP protocol & UDP broadcasts
- Python scripts for Blender scripting (render.py, peek.py)
- JSON files for announcements and configuration

##### What to Emphasize
- The split between front‐end and back‐end, with a shared contract in BlendFarm.Shared
- Networking flows (UDP auto-discovery, TCP tasks & file sync)
- Lifecycle of a render job (upload, dispatch, spawn Blender, chunked render, aggregation)
- How Blender versions are managed (download to BlenderData, spawn as subprocess)
- Extensibility points: adding new strategies under Tasks/ on the client and server

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Network Layer
    subgraph "Network Layer" 
        direction TB
        UDP["UDP Broadcast\n(Port 16342)"]:::network
        TCP["TCP Channel\n(Port 15000)"]:::network
    end

    %% GUI Client
    subgraph "GUI Client" 
        direction TB
        BFManager["BlendFarmManager"]:::frontend
        RenderClient["RenderClient"]:::frontend
        TasksClient["Tasks/ (AnimationTask, ChunkedTask)"]:::frontend
        AppAxaml["App.axaml / App.axaml.cs"]:::frontend
        ClientProgram["Program.cs"]:::frontend
    end

    %% Shared Library
    subgraph "Shared Library" 
        direction TB
        BinaryParser["BinaryParser.cs"]:::shared
        CommDir["Communication/ (Messages, RenderNode)"]:::shared
        TcpClient["TcpRenderClient.cs"]:::shared
        Exceptions["Exceptions/"]:::shared
        Models["Models/"]:::shared
    end

    %% Render Server
    subgraph "Render Server" 
        direction TB
        ServerProgram["Program.cs"]:::backend
        RenderServerCore["RenderServer.cs\nRenderServerClientTcp.cs"]:::backend
        BlenderMgr["BlenderManager.cs\nBlenderProcess.cs\nBlenderRenderSettings.cs"]:::backend
        PythonScripts["render.py\nextract_dependencies.py\npeek.py"]:::backend
    end

    %% External Blender Engine
    BlenderProcess["Blender Process\n(spawned)"]:::external

    %% Data Storage
    subgraph "Data Storage"
        direction TB
        Announcements[".data/announcements.json"]:::datastore
        TempData[".data/temp/"]:::datastore
    end

    %% Connections
    BFManager -->|"\u21E8 UDP Discovery"| UDP
    UDP -->|"\u21E8 Auto-discovery"| RenderServerCore

    BFManager -->|"\u21E8 TCP Handshake"| TCP
    TCP -->|"\u21E8 TCP Handshake"| ServerProgram

    BFManager -->|"\u21E8 FileUpload"| ServerProgram
    BFManager -->|"\u21E8 RenderBatchRequest"| ServerProgram

    ServerProgram -->|"\u21E8 Spawn"| BlenderProcess
    BlenderProcess -->|"\u21E8 RenderInfoResponse"| BFManager

    ServerProgram -->|"\u21E8 PerformanceFeedback"| BFManager

    %% Shared Library Usage
    BFManager -->|uses| BinaryParser
    ServerProgram -->|uses| CommDir
    BFManager -->|uses| CommDir
    ServerProgram -->|uses| TcpClient

    %% Data Flow to Storage
    BFManager -->|reads| Announcements
    ServerProgram -->|writes| TempData

    %% Click Events - GUI Client
    click BFManager "https://github.com/logicreinc/logicreinc.blendfarm/blob/main/LogicReinc.BlendFarm.Client/BlendFarmManager.cs"
    click RenderClient "https://github.com/logicreinc/logicreinc.blendfarm/blob/main/LogicReinc.BlendFarm.Client/RenderClient.cs"
    click TasksClient "https://github.com/logicreinc/logicreinc.blendfarm/tree/main/LogicReinc.BlendFarm.Client/Tasks/"
    click AppAxaml "https://github.com/logicreinc/logicreinc.blendfarm/blob/main/LogicReinc.BlendFarm/App.axaml"
    click ClientProgram "https://github.com/logicreinc/logicreinc.blendfarm/blob/main/LogicReinc.BlendFarm/Program.cs"

    %% Click Events - Render Server
    click ServerProgram "https://github.com/logicreinc/logicreinc.blendfarm/blob/main/LogicReinc.BlendFarm.Server/Program.cs"
    click RenderServerCore "https://github.com/logicreinc/logicreinc.blendfarm/blob/main/LogicReinc.BlendFarm.Server/RenderServer.cs"
    click BlenderMgr "https://github.com/logicreinc/logicreinc.blendfarm/blob/main/LogicReinc.BlendFarm.Server/BlenderManager.cs"
    click PythonScripts "https://github.com/logicreinc/logicreinc.blendfarm/blob/main/LogicReinc.BlendFarm.Server/render.py"

    %% Click Events - Shared Library
    click BinaryParser "https://github.com/logicreinc/logicreinc.blendfarm/blob/main/LogicReinc.BlendFarm.Shared/BinaryParser.cs"
    click CommDir "https://github.com/logicreinc/logicreinc.blendfarm/tree/main/LogicReinc.BlendFarm.Shared/Communication/"
    click TcpClient "https://github.com/logicreinc/logicreinc.blendfarm/blob/main/LogicReinc.BlendFarm.Shared/TcpRenderClient.cs"
    click Exceptions "https://github.com/logicreinc/logicreinc.blendfarm/tree/main/LogicReinc.BlendFarm.Shared/Exceptions/"
    click Models "https://github.com/logicreinc/logicreinc.blendfarm/tree/main/LogicReinc.BlendFarm.Shared/Models/"

    %% Click Events - Data Storage
    click Announcements "https://github.com/logicreinc/logicreinc.blendfarm/blob/main/.data/announcements.json"
    click TempData "https://github.com/logicreinc/logicreinc.blendfarm/tree/main/.data/temp/"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#000;font-weight:bold
    classDef backend fill:#E8F5E9,stroke:#1B5E20,color:#000;font-weight:bold
    classDef shared fill:#ECEFF1,stroke:#455A64,color:#000,font-weight:bold
    classDef external fill:#FFF3E0,stroke:#E65100,color:#000;font-weight:bold
    classDef network fill:#F3E5F5,stroke:#4A148C,color:#000,font-weight:bold
    classDef datastore fill:#FFF8E1,stroke:#FF6F00,color:#000,font-weight:bold
```
