# lightningpixel/modly architecture

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

- Interactive diagram: https://gitdiagram.com/lightningpixel/modly
- Repository: https://github.com/lightningpixel/modly

## Overview

#### Purpose and Runtime Topology
Modly is a local, GPU-backed desktop application that converts images into 3D meshes using installable open-source model extensions. It combines an Electron desktop shell, React renderer, and Python/FastAPI compute backend; no cloud inference service is required. Primary desktop entry points are `electron/main/index.ts`, `src/main.tsx`, and `api/main.py`.

#### Desktop Shell and Native Boundary
Electron owns application lifecycle, persistent settings, OS integration, embedded-Python setup, backend process launching, downloads, updates, and artifact registration. Renderer access is mediated through the preload/IPC boundary rather than direct Node access. Key paths: `electron/main/ipc-handlers.ts`, `electron/main/python-bridge.ts`, `electron/preload/electron-api.ts`.

#### Renderer Application
The React/Vite UI routes among setup, generation, models/extensions, settings, and workflow editing. Shared stores coordinate application, agent, extension, navigation, and workflow state. The generation area presents image input, model/workflow controls, progress, asset library, and 3D/splat viewers. Key paths: `src/App.tsx`, `src/shared/router/Router.tsx`, `src/areas/generate/GeneratePage.tsx`.

#### API and Generation Orchestration
FastAPI exposes the backend contract consumed by Electron/renderer and automation clients. Routers separate generation, model management, extensions, optimization/export, settings/status, agent endpoints, and workflow-run lifecycle. Generator implementations are selected through a registry; the backend runner executes generation work. Key paths: `api/main.py`, `api/routers/workflow_runs.py`, `api/services/generator_registry.py`, `api/runner.py`.

#### Extension and Model Boundary
Models and processing capabilities are external extensions, generally acquired from GitHub and described by `manifest.json`. Electron performs installation/path validation and lifecycle work; Python launches or coordinates extension processes. This isolates arbitrary model runtime dependencies from the core application and allows model variants/downloads. Key paths: `electron/main/extension-install-utils.ts`, `electron/main/extension-path-guard.ts`, `api/services/extension_process.py`.

#### Workflow Execution and Mesh Processing
Users compose validated node graphs, then run them from the Generate page. Nodes cover inputs, image/text, extension execution, loops/waits, mesh loading, preview, and scene insertion; built-in processing extensions provide export, optimization, remeshing, repair, and smoothing. Invalid wiring is preflighted before execution and should preserve the current scene. Key paths: `src/areas/workflows/WorkflowsPage.tsx`, `src/areas/workflows/preflight.ts`, `src/areas/workflows/workflowRunStore.ts`, `src/areas/workflows/nodes/mesh-optimizer/processor.ts`.

#### Native Geometry Pipeline and Automation
The Python backend includes compiled native modules for UV unwrapping and texture baking, with C++ plus CUDA/Metal platform implementations—important GPU/platform boundaries. A stdlib-only CLI automates a running desktop app through canonical API concepts, especially workflow-run polling and final artifact export. Key paths: `api/uv_unwrapper/uv_unwrapper/unwrap.py`, `api/texture_baker/texture_baker/baker.py`, `tools/modly-cli/agent.py`.

Main entry points: [`api/runner.py`](https://github.com/lightningpixel/modly/blob/main/api/runner.py) (Generation runner), [`api/main.py`](https://github.com/lightningpixel/modly/blob/main/api/main.py) (FastAPI service), [`electron/main/index.ts`](https://github.com/lightningpixel/modly/blob/main/electron/main/index.ts) (Electron main), [`src/shared/router/Router.tsx`](https://github.com/lightningpixel/modly/blob/main/src/shared/router/Router.tsx) (UI routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop runtime"]
  node_electron_main["Electron main<br/>desktop shell<br/>[index.ts]"]
  node_ipc["IPC handlers<br/>IPC boundary<br/>[ipc-handlers.ts]"]
  node_preload["Preload API<br/>renderer bridge<br/>[electron-api.ts]"]
  node_python_bridge["Python bridge<br/>backend launcher<br/>[python-bridge.ts]"]
  node_extension_install["Extension installer<br/>extension lifecycle"]
end

subgraph group_renderer["Renderer UI"]
  node_app["React application<br/>renderer entry<br/>[main.tsx]"]
  node_router["UI routes<br/>navigation<br/>[Router.tsx]"]
  node_generate["Generate page<br/>generation UI<br/>[GeneratePage.tsx]"]
  node_workflow_editor["Workflow editor<br/>graph authoring<br/>[WorkflowsPage.tsx]"]
  node_preflight["Workflow preflight<br/>graph validation<br/>[preflight.ts]"]
  node_workflow_store["Workflow run store<br/>run state"]
end

subgraph group_backend["Python backend"]
  node_fastapi["FastAPI service<br/>backend API<br/>[main.py]"]
  node_workflow_runs["Workflow-run API<br/>run lifecycle router<br/>[workflow_runs.py]"]
  node_generator_registry["Generator registry<br/>generator selection"]
  node_runner["Generation runner<br/>compute orchestration<br/>[runner.py]"]
  node_uv_unwrapper["UV unwrapper<br/>native geometry binding<br/>[unwrap.py]"]
  node_texture_baker["Texture baker<br/>native geometry binding<br/>[baker.py]"]
end

subgraph group_extensions["Extensions &amp; processing"]
  node_extension_process["Extension process manager<br/>extension runtime"]
  node_mesh_processor["Mesh optimizer processor<br/>built-in processing<br/>[processor.ts]"]
end

node_cli["Modly CLI<br/>automation client<br/>[agent.py]"]

node_electron_main -->|"registers"| node_ipc
node_electron_main -->|"launches"| node_python_bridge
node_electron_main -->|"manages"| node_extension_install
node_app -->|"renders"| node_router
node_router -->|"routes to"| node_generate
node_router -->|"routes to"| node_workflow_editor
node_workflow_editor -->|"validates graph"| node_preflight
node_preflight -->|"permits run"| node_workflow_store
node_generate -->|"starts and observes"| node_workflow_store
node_app -->|"uses"| node_preload
node_preload -->|"invokes"| node_ipc
node_python_bridge -->|"starts"| node_fastapi
node_ipc -->|"proxies backend calls"| node_fastapi
node_workflow_store -->|"creates and polls"| node_workflow_runs
node_fastapi -->|"mounts"| node_workflow_runs
node_workflow_runs -->|"dispatches"| node_runner
node_runner -->|"selects generator"| node_generator_registry
node_runner -->|"coordinates models"| node_extension_process
node_extension_install -->|"installs runtimes for"| node_extension_process
node_runner -->|"unwraps UVs"| node_uv_unwrapper
node_runner -->|"bakes textures"| node_texture_baker
node_workflow_editor -->|"uses processing node"| node_mesh_processor
node_cli -->|"automates canonical API"| node_fastapi

click node_electron_main "https://github.com/lightningpixel/modly/blob/main/electron/main/index.ts"
click node_ipc "https://github.com/lightningpixel/modly/blob/main/electron/main/ipc-handlers.ts"
click node_preload "https://github.com/lightningpixel/modly/blob/main/electron/preload/electron-api.ts"
click node_python_bridge "https://github.com/lightningpixel/modly/blob/main/electron/main/python-bridge.ts"
click node_extension_install "https://github.com/lightningpixel/modly/blob/main/electron/main/extension-install-utils.ts"
click node_app "https://github.com/lightningpixel/modly/blob/main/src/main.tsx"
click node_router "https://github.com/lightningpixel/modly/blob/main/src/shared/router/Router.tsx"
click node_generate "https://github.com/lightningpixel/modly/blob/main/src/areas/generate/GeneratePage.tsx"
click node_workflow_editor "https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/WorkflowsPage.tsx"
click node_preflight "https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/preflight.ts"
click node_workflow_store "https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/workflowRunStore.ts"
click node_fastapi "https://github.com/lightningpixel/modly/blob/main/api/main.py"
click node_workflow_runs "https://github.com/lightningpixel/modly/blob/main/api/routers/workflow_runs.py"
click node_generator_registry "https://github.com/lightningpixel/modly/blob/main/api/services/generator_registry.py"
click node_runner "https://github.com/lightningpixel/modly/blob/main/api/runner.py"
click node_extension_process "https://github.com/lightningpixel/modly/blob/main/api/services/extension_process.py"
click node_mesh_processor "https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/nodes/mesh-optimizer/processor.ts"
click node_uv_unwrapper "https://github.com/lightningpixel/modly/blob/main/api/uv_unwrapper/uv_unwrapper/unwrap.py"
click node_texture_baker "https://github.com/lightningpixel/modly/blob/main/api/texture_baker/texture_baker/baker.py"
click node_cli "https://github.com/lightningpixel/modly/blob/main/tools/modly-cli/agent.py"

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_electron_main,node_ipc,node_preload,node_python_bridge,node_extension_install toneBlue
class node_app,node_router,node_generate,node_workflow_editor,node_preflight,node_workflow_store toneAmber
class node_fastapi,node_workflow_runs,node_generator_registry,node_runner,node_uv_unwrapper,node_texture_baker toneMint
class node_extension_process,node_mesh_processor toneRose
class node_cli toneNeutral
```

## Components

### Desktop runtime

- [Electron main](https://github.com/lightningpixel/modly/blob/main/electron/main/index.ts): desktop shell · Owns lifecycle, native integration, backend launch, and artifacts. · `electron/main/index.ts`
- [IPC handlers](https://github.com/lightningpixel/modly/blob/main/electron/main/ipc-handlers.ts): IPC boundary · `electron/main/ipc-handlers.ts`
- [Preload API](https://github.com/lightningpixel/modly/blob/main/electron/preload/electron-api.ts): renderer bridge · Mediates renderer access to Electron capabilities. · `electron/preload/electron-api.ts`
- [Python bridge](https://github.com/lightningpixel/modly/blob/main/electron/main/python-bridge.ts): backend launcher · `electron/main/python-bridge.ts`
- [Extension installer](https://github.com/lightningpixel/modly/blob/main/electron/main/extension-install-utils.ts): extension lifecycle · Installs extensions and validates their paths. · `electron/main/extension-install-utils.ts`

### Renderer UI

- [React application](https://github.com/lightningpixel/modly/blob/main/src/main.tsx): renderer entry · `src/main.tsx`
- [UI routes](https://github.com/lightningpixel/modly/blob/main/src/shared/router/Router.tsx): navigation · Routes setup, generation, models, settings, and workflows. · `src/shared/router/Router.tsx`
- [Generate page](https://github.com/lightningpixel/modly/blob/main/src/areas/generate/GeneratePage.tsx): generation UI · Collects inputs and presents progress, assets, and 3D viewers. · `src/areas/generate/GeneratePage.tsx`
- [Workflow editor](https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/WorkflowsPage.tsx): graph authoring · `src/areas/workflows/WorkflowsPage.tsx`
- [Workflow preflight](https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/preflight.ts): graph validation · Rejects invalid wiring before execution. · `src/areas/workflows/preflight.ts`
- [Workflow run store](https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/workflowRunStore.ts): run state · `src/areas/workflows/workflowRunStore.ts`

### Python backend

- [FastAPI service](https://github.com/lightningpixel/modly/blob/main/api/main.py): backend API · Serves generation, models, extensions, settings, agent, and workflows. · `api/main.py`
- [Workflow-run API](https://github.com/lightningpixel/modly/blob/main/api/routers/workflow_runs.py): run lifecycle router · `api/routers/workflow_runs.py`
- [Generator registry](https://github.com/lightningpixel/modly/blob/main/api/services/generator_registry.py): generator selection · `api/services/generator_registry.py`
- [Generation runner](https://github.com/lightningpixel/modly/blob/main/api/runner.py): compute orchestration · Executes selected generation work. · `api/runner.py`
- [UV unwrapper](https://github.com/lightningpixel/modly/blob/main/api/uv_unwrapper/uv_unwrapper/unwrap.py): native geometry binding · Uses compiled C++ and CUDA/Metal implementations. · `api/uv_unwrapper/uv_unwrapper/unwrap.py`
- [Texture baker](https://github.com/lightningpixel/modly/blob/main/api/texture_baker/texture_baker/baker.py): native geometry binding · Uses compiled GPU/platform implementations. · `api/texture_baker/texture_baker/baker.py`

### Extensions & processing

- [Extension process manager](https://github.com/lightningpixel/modly/blob/main/api/services/extension_process.py): extension runtime · Launches or coordinates isolated model processes. · `api/services/extension_process.py`
- [Mesh optimizer processor](https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/nodes/mesh-optimizer/processor.ts): built-in processing · Provides optimization and related mesh operations. · `src/areas/workflows/nodes/mesh-optimizer/processor.ts`

### Other components

- [Modly CLI](https://github.com/lightningpixel/modly/blob/main/tools/modly-cli/agent.py): automation client · Automates workflow runs, polling, and artifact export. · `tools/modly-cli/agent.py`

## Connections

- Electron main → IPC handlers: registers
- Electron main → Python bridge: launches
- Electron main → Extension installer: manages
- React application → UI routes: renders
- UI routes → Generate page: routes to
- UI routes → Workflow editor: routes to
- Workflow editor → Workflow preflight: validates graph
- Workflow preflight → Workflow run store: permits run
- Generate page → Workflow run store: starts and observes
- React application → Preload API: uses
- Preload API → IPC handlers: invokes
- Python bridge → FastAPI service: starts
- IPC handlers → FastAPI service: proxies backend calls
- Workflow run store → Workflow-run API: creates and polls
- FastAPI service → Workflow-run API: mounts
- Workflow-run API → Generation runner: dispatches
- Generation runner → Generator registry: selects generator
- Generation runner → Extension process manager: coordinates models
- Extension installer → Extension process manager: installs runtimes for
- Generation runner → UV unwrapper: unwraps UVs
- Generation runner → Texture baker: bakes textures
- Workflow editor → Mesh optimizer processor: uses processing node
- Modly CLI → FastAPI service: automates canonical API
