# trytriplex/triplex architecture

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

- Interactive diagram: https://gitdiagram.com/trytriplex/triplex
- Repository: https://github.com/trytriplex/triplex

## Overview

##### Project type and purpose
- Triplex is a monorepo providing:
– A VS Code extension and standalone app (visual workspace)
– A CLI scaffolder (`create-triplex-project`)
– A core rendering engine (`packages/renderer`) built on React Three Fiber + Three.js
– A UI-controls library (`packages/ux`)
– Supporting libraries (`packages/api`, `packages/lib`, `packages/bridge`, etc.)
– Documentation site (`apps/docs`) and multiple example projects (`examples/*`).

##### File structure
- Top-level “packages/…” are NPM workspaces for modular features.
- “apps/docs” is a Next.js/Nextra site for documentation.
- “examples/…” are individual Vite or Deno sample apps consuming the core packages.
- CI/CD pipelines in `.github/workflows` build, test, and publish packages to NPM or Winget.

##### README insights
- Triplex exposes a visual scene builder in VS Code or standalone, powered by React + Three.js.
- Key technologies: TypeScript, React, React Three Fiber, Vite, Next.js, Node.js.

##### Main components & interactions

[External Host Environments]
- VS Code Extension Host
- Electron (Standalone)
- Web Browser (Docs / Examples)
↕
[Bridge Layer] (`packages/bridge`)
- Abstracts host messaging (VS Code Webview or Electron WebContents → React)
↕
[Core Renderer] (`packages/renderer`)
- React Three Fiber + Three.js scene graph
- Features: camera controls, scene loader, WebXR, selection, screenshot, etc.
↕
[UI Controls] (`packages/ux`)
- Dialogs, inputs, menus, telemetry
↕
[Application Logic / API] (`packages/api`, `packages/lib`)
- ECS helpers (Koota), utility functions, themes, templates
↑
[CLI Scaffolder] (`packages/create-triplex-project`)
- Reads templates → generates new Triplex projects (`.triplex/config.json`, starter code)
↑
[Consumers]
- Documentation site (`apps/docs`) – built with Next.js/Nextra
- Example apps (`examples/*`) – Vite/Deno projects consuming the same packages

##### Architectural patterns & design principles
- Monorepo & NPM workspace modularization
- Clear separation of concerns:
– Host integration (Bridge)
– Rendering engine (Renderer)
– UI controls (UX)
– Business logic / utilities (API, Lib)
– CLI scaffolding (Create)
- Plugin-style features inside `packages/renderer/src/features`
- CI/CD via GitHub Actions—build/test/publish

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Host & External"
    VSCode["VS Code Extension Host"]:::external
    Electron["Electron (Standalone)"]:::external
    Browser["Web Browser (Docs / Examples)"]:::external
  end

  subgraph "Bridge Layer"
    BridgeLayer["Bridge Layer"]:::bridge
  end

  subgraph "Core Renderer"
    Renderer["Core Renderer"]:::renderer
  end

  subgraph "UI Controls"
    UX["UI Controls"]:::ux
  end

  subgraph "Application Logic & Utilities"
    API["Application Logic / API"]:::app
    Lib["Utility Library"]:::app
  end

  subgraph "CLI Scaffolder"
    CLI["CLI Scaffolder"]:::app
  end

  subgraph "Consumers"
    Docs["Documentation Site"]:::cons
    Examples["Example Projects"]:::cons
  end

  subgraph "CI/CD & Registry"
    CICD["GitHub Actions"]:::ci
    Registry["NPM / Winget / VS Code Marketplace"]:::ci
  end

  VSCode -->|JSON-RPC| BridgeLayer
  Electron -->|WebContents| BridgeLayer
  Browser -->|postMessage| BridgeLayer

  BridgeLayer -->|"React Messaging"| Renderer
  Renderer -->|"props & events"| UX

  UX -->|"calls"| API
  UX -->|"calls"| Lib

  CLI -->|"reads templates"| API
  CLI -->|"reads templates"| Lib

  Docs -->|"consumes"| API
  Docs -->|"consumes"| UX
  Docs -->|"consumes"| Renderer

  Examples -->|"consumes"| API
  Examples -->|"consumes"| UX
  Examples -->|"consumes"| Renderer

  CICD -->|"publishes"| Registry

  click BridgeLayer "https://github.com/trytriplex/triplex/tree/main/packages/bridge"
  click Renderer "https://github.com/trytriplex/triplex/tree/main/packages/renderer"
  click UX "https://github.com/trytriplex/triplex/tree/main/packages/ux"
  click API "https://github.com/trytriplex/triplex/tree/main/packages/api"
  click Lib "https://github.com/trytriplex/triplex/tree/main/packages/lib"
  click CLI "https://github.com/trytriplex/triplex/tree/main/packages/create-triplex-project"
  click Docs "https://github.com/trytriplex/triplex/tree/main/apps/docs"
  click Examples "https://github.com/trytriplex/triplex/tree/main/examples"
  click CICD "https://github.com/trytriplex/triplex/tree/main/.github/workflows"
  click Root1 "https://github.com/trytriplex/triplex/blob/main/package.json"
  click Root2 "https://github.com/trytriplex/triplex/blob/main/tsconfig/base.json"
  click Root3 "https://github.com/trytriplex/triplex/blob/main/.eslintrc.json"
  click Root4 "https://github.com/trytriplex/triplex/blob/main/.prettierrc"
  click VSCode "https://github.com/trytriplex/triplex/blob/main/scripts/force-react-18.js"
  click VSCode "https://github.com/trytriplex/triplex/blob/main/scripts/ensure-clean-git.js"
  click VSCode "https://github.com/trytriplex/triplex/blob/main/.vscode"

  classDef external fill:#dddddd,stroke:#888;
  classDef bridge fill:#ffa500,stroke:#e69500;
  classDef renderer fill:#87cefa,stroke:#4682b4;
  classDef ux fill:#90ee90,stroke:#2e8b57;
  classDef app fill:#ffff99,stroke:#cccc00;
  classDef cons fill:#dda0dd,stroke:#ba55d3;
  classDef ci fill:#f0f8ff,stroke:#a9a9a9;
```
