# arthurbrussee/brush architecture

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

- Interactive diagram: https://gitdiagram.com/arthurbrussee/brush
- Repository: https://github.com/arthurbrussee/brush

## Overview

##### Project Type and Purpose
- The project is a 3D reconstruction engine (“Brush”) that uses machine learning alongside real-time GPU rendering (utilizing WebGPU) to perform reconstruction via Gaussian splatting.
- It is designed for a range of environments – desktop (macOS/windows/linux), Android, and browsers – and provides interfaces as a CLI, a web demo (using Trunk), and even rerun integration for visualization while training.
- The README emphasizes support for both training (including on mobile/browser) and viewing, with performance benchmarks and a focus on efficient and dependency-free deliverables.

##### Analyzing the File Structure
- The workspace is organized into multiple “crates” (each one in its own folder under the crates/ directory) such as brush-app (which likely is the web viewer), brush-android (for Android builds), brush-cli (providing the command-line interface), brush-train (for training logic), brush-render (managing rendering operations), and several others (brush-dataset, brush-process, brush-kernel, brush-ui, brush-wgsl, etc).
- Many crates include subdirectories for sources, tests, and even shader files – indicating that GPU code (wgsl shaders) is an important part of the architecture.
- The existence of directories like .github/workflows, Trunk.toml, and examples/ further indicates CI/CD integration, web packaging (via trunk), and example usage.

##### Components and Their Relationships
a. Main Components/Subsystems:
- Core Libraries: These include the low-level modules that handle GPU kernels (brush-kernel, brush-wgsl), sorting (brush-sort), prefix-sum computations (brush-prefix-sum), and process loops (brush-process).
- Training Module: Crates like brush-train and possibly parts of brush-process and brush-dataset handle the training pipeline from dataset ingestion (supporting COLMAP and Nerfstudio formats) to the running of training loops.
- Rendering & Viewer: brush-render and brush-ui (plus the web-oriented brush-app) form the rendering engine that takes the trained data and displays it using WebGPU. There is also mention of a CLI mode that can launch the viewer.
- Command-Line Interface: brush-cli provides the CLI interface to invoke training, rendering, or debugging sessions. The integration with rerun is another layer here that supports real-time visualization.
- Platform-Specific Frontends: brush-android for Android-specific builds, and the web build using Trunk (configured via Trunk.toml and assets in brush-app) for browser-based demo.

b. Data Flow & Interactions:
- The training component ingests input data (images, COLMAP or Nerfstudio datasets, possibly with masks) and passes it to the training engine, which uses GPU-accelerated kernels (via burn and wgpu) for optimizing the scene representation.
- Once the training is in progress (or complete), rendering components take the gaussian splat data and pass it to the viewer/UI. In the web and CLI versions, this is displayed through interactive controls (orbit, flythrough).
- The CLI and platform-specific apps (Android, Web) use the same underlying libraries but provide tailored frontends using either native widgets or web assets.
- External tools and integrations such as rerun add another visualization stream to the training process.

c. Architectural Patterns & Technologies:
- Modularity: Each key functional area (training, rendering, dataset management) is separated into its own crate, making the system modular and extensible.
- Cross-Platform Abstraction: By abstracting over WebGPU (via wgpu) and using the Burn ML framework, the project achieves portability across different hardware and operating systems.
- Separation of concerns: With clear boundaries in the file tree (e.g., separate folders for Android, CLI, App), the design emphasizes that the core functionality is decoupled from the platform-specific presentation.

##### Elements
- Clear labels for each component block (e.g., “Brush-Train (Training Logic)”, “Brush-Render (Rendering Pipeline)”, “Brush-App (Web Viewer)”, “Brush-Android (Android UI)”, “Brush-CLI (Command-line Interface)”).
- Input data (images, datasets) flowing into the training module.
- Processed scene representations flowing into the rendering module.
- Viewer inputs (orbit controls, flythrough commands) affecting interactive components.
- Rectangles for core processing modules.
- Parallelograms for interfaces (CLI, Web, Android).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependencies
    subgraph "External Dependencies"
        E1("Burn")
        E2("wgpu")
        E3("Trunk")
        E4("Gradle")
        E5("Rerun")
    end

    %% Core GPU/Shading Libraries
    subgraph "Core GPU/Shading Libraries"
        A("brush-kernel (GPU Kernels)")
        B("brush-wgsl (WGSL Utilities)")
        C("brush-prefix-sum (Prefix-Sum)")
        D("brush-sort (Sorting)")
    end

    %% Training Pipeline Module
    subgraph "Training Pipeline Module"
        E("brush-train (Training Logic)")
        F("brush-dataset (Dataset Ingestion)")
        G("brush-process (Process Loops)")
    end

    %% Rendering Engine
    subgraph "Rendering Engine"
        H("brush-render (Rendering Pipeline)")
        I("brush-ui (Rendering UI)")
    end

    %% Command-Line Interface
    subgraph "Command-Line Interface"
        J("brush-cli (CLI & Rerun)")
    end

    %% Platform-Specific Frontends
    subgraph "Platform-Specific Frontends"
        K("brush-app (Web Viewer)")
        L("brush-android (Android UI)")
    end

    %% Integration/Visualization
    subgraph "Integration/Visualization"
        M("brush-rerun (Rerun Integration)")
    end

    %% Connections from External Dependencies to Core/Modules
    E1 -->|"supports"| E
    E2 -->|"supports"| H
    E3 -->|"bundles"| K
    E4 -->|"builds"| L
    E5 -->|"integrates"| J

    %% Connections from Core GPU/Shading Libraries to Training and Rendering
    A -->|"accelerates"| E
    C -->|"accelerates"| E
    B -->|"accelerates"| H
    D -->|"accelerates"| H

    %% Internal Training Pipeline Connections
    F -->|"supplies"| E
    G -->|"feeds"| E

    %% Training and Rendering Relationship
    E -->|"outputs"| H
    E -->|"updates"| M

    %% Rendering Engine Internal Flow
    H -->|"renders"| I

    %% CLI and Integration Flow
    H -->|"triggers"| J
    J -->|"forwards"| M

    %% Interaction between Rendering UI and Training (viewer control)
    I <-->|"viewercontrol"| E

    %% Platform-Specific Frontends Connections
    I -->|"displays"| K
    I -->|"displays"| L

    %% Class Definitions for Coloring
    classDef external fill:#e3f2fd,stroke:#0d47a1,stroke-width:2px;
    classDef core fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef train fill:#ffccbc,stroke:#bf360c,stroke-width:2px;
    classDef render fill:#d1c4e9,stroke:#4a148c,stroke-width:2px;
    classDef cli fill:#fff9c4,stroke:#f57f17,stroke-width:2px;
    classDef platform fill:#b3e5fc,stroke:#01579b,stroke-width:2px;
    classDef integration fill:#ffe0b2,stroke:#e65100,stroke-width:2px;

    %% Assigning Classes
    class E1,E2,E3,E4,E5 external;
    class A,B,C,D core;
    class E,F,G train;
    class H,I render;
    class J cli;
    class K,L platform;
    class M integration;

    %% Click Events for Component Mapping
    click A "https://github.com/arthurbrussee/brush/tree/main/crates/brush-kernel"
    click B "https://github.com/arthurbrussee/brush/tree/main/crates/brush-wgsl"
    click C "https://github.com/arthurbrussee/brush/tree/main/crates/brush-prefix-sum"
    click D "https://github.com/arthurbrussee/brush/tree/main/crates/brush-sort"
    click E "https://github.com/arthurbrussee/brush/tree/main/crates/brush-train"
    click F "https://github.com/arthurbrussee/brush/tree/main/crates/brush-dataset"
    click G "https://github.com/arthurbrussee/brush/tree/main/crates/brush-process"
    click H "https://github.com/arthurbrussee/brush/tree/main/crates/brush-render"
    click I "https://github.com/arthurbrussee/brush/tree/main/crates/brush-ui"
    click J "https://github.com/arthurbrussee/brush/tree/main/crates/brush-cli"
    click K "https://github.com/arthurbrussee/brush/tree/main/crates/brush-app"
    click L "https://github.com/arthurbrussee/brush/tree/main/crates/brush-android"
    click M "https://github.com/arthurbrussee/brush/tree/main/crates/brush-rerun"
```
