# abrasic/blendpresence architecture

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

- Interactive diagram: https://gitdiagram.com/abrasic/blendpresence
- Repository: https://github.com/abrasic/blendpresence

## Overview

##### Project type and purpose
- This is a Blender add-on (written in Python) that integrates with Discord via Rich Presence.
- Its purpose is to capture Blender context (mode, scene name, render stats, etc.) and push updates to a user’s Discord status.

##### File structure
- Top-level:
- BlendPresence/             ← the Blender add-on package
- LICENSE, README.md         ← documentation and license
- Inside BlendPresence/
- __init__.py                ← Blender add-on registration (bl_info) and entry points
- pypresence/                ← vendored Discord RPC client library
– baseclient.py
– client.py
– exceptions.py
– payloads.py
– presence.py
– utils.py
- No separate “frontend/backend”—this is a single plugin running inside Blender’s Python environment.

##### README for additional insights
- Configuration surface: add-on preferences in Blender’s UI.
- Dependencies: Blender 2.93+, Discord desktop client (for IPC), pypresence (vendored).

##### Main components & interactions
a. Components
1. Blender Host
- UI Panel & Preferences (Blender’s addon settings)
- Event hooks & timers (frame change, render start/stop)
2. Data Collector
- Reads bpy.context for version, mode, scene, object counts, render progress
- Reads user preferences (buttons, update interval, custom text)
3. Payload Builder
- Assembles JSON payloads (using payloads.py, presence.py)
4. RPC Client (pypresence)
- client.py handles high-level commands (connect, update_presence, close)
- baseclient.py handles low-level IPC socket framing
5. External Service
- Discord Desktop App listening on IPC socket
- Discord GUI displaying the Rich Presence
b. Relationships/Data Flow
- User updates settings in Blender UI → Preferences stored in Blender
- On timer or event, Data Collector polls Blender context → passes to Payload Builder
- Payload Builder invokes RPC Client → serializes & sends over IPC → Discord
- Discord processes JSON, updates user status → Friends see updated presence
c. Architectural patterns
- Plugin/extension pattern (hosted inside Blender)
- Event-driven updates via Blender handlers
- Adapter pattern wrapping pypresence into Blender’s API
- Separation of concerns: UI vs context-gathering vs communication
d. Key technologies
- Blender Python API (bpy)
- pypresence library (vendored)
- Discord IPC protocol (local UNIX/Windows socket)
- JSON payloads conforming to Discord Rich Presence schema

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host Layer
    subgraph "Host Layer"
        direction TB
        Host["Blender Host\n(UI Panel & Preferences,\nEvent Hooks)"]:::host
    end

    %% Logic Layer
    subgraph "Logic Layer"
        direction TB
        Collector["Data Collector\n(gather bpy.context,\nuser preferences)"]:::logic
        Builder["Payload Builder\n(construct JSON payloads)"]:::logic
    end

    %% Communication Layer
    subgraph "Communication Layer"
        direction TB
        RPCClient["RPC Client\n(connect, update_presence,\nclose)"]:::comm
        RPCBase["Base Client\n(IPC socket framing)"]:::comm
        RPCUtils["Exceptions & Utils"]:::comm
    end

    %% External Layer
    subgraph "External Layer"
        direction TB
        DiscordApp["Discord Desktop App\n(IPC Socket Listener)"]:::external
        DiscordGUI["Discord GUI\n(Displays Rich Presence)"]:::external
    end

    %% Connections
    Host -->|"on event/timer"| Collector
    Collector -->|"build context data"| Builder
    Builder -->|"invoke update_presence()"| RPCClient
    RPCClient -->|"uses framing"| RPCBase
    RPCClient -->|"handles errors"| RPCUtils
    RPCClient -->|"send JSON over IPC"| DiscordApp
    DiscordApp -->|"renders status"| DiscordGUI

    %% Click Events
    click Host "https://github.com/abrasic/blendpresence/blob/main/BlendPresence/__init__.py"
    click Collector "https://github.com/abrasic/blendpresence/blob/main/BlendPresence/__init__.py"
    click Builder "https://github.com/abrasic/blendpresence/blob/main/BlendPresence/pypresence/payloads.py"
    click Builder "https://github.com/abrasic/blendpresence/blob/main/BlendPresence/pypresence/presence.py"
    click RPCClient "https://github.com/abrasic/blendpresence/blob/main/BlendPresence/pypresence/client.py"
    click RPCBase "https://github.com/abrasic/blendpresence/blob/main/BlendPresence/pypresence/baseclient.py"
    click RPCUtils "https://github.com/abrasic/blendpresence/blob/main/BlendPresence/pypresence/exceptions.py"
    click RPCUtils "https://github.com/abrasic/blendpresence/blob/main/BlendPresence/pypresence/utils.py"

    %% Styles
    classDef host fill:#aed6f1,stroke:#3498db,color:#1b2631;
    classDef logic fill:#abebc6,stroke:#27ae60,color:#1b2631;
    classDef comm fill:#f9e79f,stroke:#f1c40f,color:#1b2631;
    classDef external fill:#fadbd8,stroke:#e74c3c,color:#1b2631;
```
