# antelm-dev/shader-studio architecture

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

- Interactive diagram: https://gitdiagram.com/antelm-dev/shader-studio
- Repository: https://github.com/antelm-dev/shader-studio

## Overview

#### Purpose and deployable entry points
Shader Studio is a self-hosted shader workspace for authoring multi-pass WebGL/GLSL projects, live tuning uniforms, storing presets/assets, and importing/exporting portable bundles. It has three runtime hosts:
- Angular browser/SSR: `apps/web/src/main.ts`, `apps/web/src/main.server.ts`
- Express API + SSR host and migration CLI: `apps/server/src/index.ts`, `apps/server/src/cli.ts`
- Electron desktop main process and sandboxed preload: `apps/desktop/main/src/main.ts`, `apps/desktop/preload/src/preload.ts`

#### Shared domain contracts
`libs/shared` is the runtime-neutral core: shader/project records, control schemas, render settings, GLSL transformations, validation, capture planning, session/surface protocols, and MCP protocol types. Browser, server, desktop, and MCP tooling should depend on these contracts rather than each other.
- `libs/shared/src/model/index.ts`
- `libs/shared/src/project/types.ts`
- `libs/shared/src/validate/index.ts`

#### Persistence and shader-library boundary
Node-only `libs/backend` centralizes domain operations in `ShaderLibrary` above a `ShaderRepository` abstraction. Repository implementations select PostgreSQL for the web server when `DATABASE_URL` exists, otherwise SQLite for desktop/dev. Migrations run before API/IPC exposure; writes are transactional and support per-shader revision conflict detection. Legacy filesystem storage is import-only.
- `apps/server/src/create-library.ts`
- `libs/backend/src/library/shader-library.ts`
- `libs/backend/src/persistence/shader-repository.ts`

PostgreSQL is the Docker/web production store; SQLite is the Electron local store. Docker Compose provisions the application and internal PostgreSQL service: `docker-compose.yml`.

#### Server API and SSR boundary
The Express server maps HTTP requests to the library and normalizes failures into the public API error envelope. It also hosts Angular SSR, where server rendering fetches through same-origin API configuration. Browser code never receives database credentials or direct repository access.
- `apps/server/src/api/api.controller.ts`
- `apps/server/src/api/api.module.ts`
- `apps/web/src/app/app.config.server.ts`

Primary web flow: request → Express SSR/API → `ShaderLibrary` → selected SQL repository → response/TransferState → hydrated Angular client.

#### Angular workspace state and editing
The Angular app owns saved-record, editable-draft, and live-parameter state separately. Startup/routing selects a shader; compilation, persistence, recovery, presets, textures, and UI panels operate through this workspace layer. API transport is replaceable: HTTP for web and typed desktop IPC for Electron.
- `apps/web/src/app/workspace/shader-store.ts`
- `apps/web/src/app/workspace/startup-coordinator.ts`
- `apps/web/src/app/api/shader-api.ts`

Monaco editing and GLSL-specific formatting/snippets are isolated from storage and rendering: `apps/web/src/app/editor/code-editor.ts`.

#### WebGL render and capture pipeline
The renderer compiles candidate passes offscreen before replacing the live material, preserving the last valid output and returning driver diagnostics. It supports Image/Common/Buffer passes, channel textures, uniforms generated from control schemas, post-processing, thumbnails, captures, video/sequence writing, and Wallpaper Engine export.
- `apps/web/src/app/rendering/shader-engine.ts`
- `apps/web/src/app/rendering/engine/pass-compiler.ts`
- `apps/web/src/app/rendering/frame-render.ts`

Control flow is workspace draft/params → compilation and uniform binding → WebGL pass graph → preview/output surface or capture/export.

#### Desktop windows, IPC, and MCP control
Electron keeps filesystem/database access in its main process. The preload exposes a restricted typed bridge; IPC handlers invoke the same backend library used by the server. Surface-window management supports independent output windows. Separately, the MCP package speaks stdio to AI clients and bridges to a locally open app tab through authenticated localhost messaging.
- `apps/desktop/main/src/ipc/shader.ipc.ts`
- `apps/desktop/main/src/windows/surface-window-manager.ts`
- `tools/mcp/src/server.ts`

Main entry points: [`apps/web/src/app/workspace/shader-store.ts`](https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/workspace/shader-store.ts) (Shader workspace state), [`libs/backend/src/library/shader-library.ts`](https://github.com/antelm-dev/shader-studio/blob/master/libs/backend/src/library/shader-library.ts) (ShaderLibrary), [`apps/web/src/app/api/shader-api.ts`](https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/api/shader-api.ts) (Replaceable shader API), [`apps/desktop/main/src/ipc/shader.ipc.ts`](https://github.com/antelm-dev/shader-studio/blob/master/apps/desktop/main/src/ipc/shader.ipc.ts) (Shader IPC handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web workspace"]
  node_web_browser["Angular browser app<br/>browser runtime<br/>[main.ts]"]
  node_web_ssr["Angular SSR entry<br/>SSR runtime<br/>[main.server.ts]"]
  node_workspace["Shader workspace state<br/>state layer<br/>[shader-store.ts]"]
  node_startup["Startup coordinator<br/>routing startup"]
  node_shader_api["Replaceable shader API<br/>transport port<br/>[shader-api.ts]"]
  node_editor["Monaco GLSL editor<br/>editor layer<br/>[code-editor.ts]"]
  node_renderer["Shader engine<br/>WebGL renderer<br/>[shader-engine.ts]"]
  node_pass_compiler["Offscreen pass compiler<br/>render stage<br/>[pass-compiler.ts]"]
  node_frame_render["Frame render pipeline<br/>render stage<br/>[frame-render.ts]"]
end

subgraph group_server["Server runtime"]
  node_express["Express API and SSR host<br/>server runtime<br/>[index.ts]"]
  node_api_controller["API controller<br/>HTTP boundary<br/>[api.controller.ts]"]
  node_server_library_factory["Library factory<br/>composition root<br/>[create-library.ts]"]
end

subgraph group_desktop["Desktop runtime"]
  node_electron_main["Electron main process<br/>desktop runtime<br/>[main.ts]"]
  node_preload["Sandboxed preload bridge<br/>IPC boundary<br/>[preload.ts]"]
  node_ipc_handlers["Shader IPC handlers<br/>IPC adapter<br/>[shader.ipc.ts]"]
  node_surface_windows["Surface window manager<br/>desktop output"]
end

subgraph group_core["Domain and storage"]
  node_shared_contracts["Shared domain contracts<br/>runtime-neutral core<br/>[index.ts]"]
  node_shader_library["ShaderLibrary<br/>domain service<br/>[shader-library.ts]"]
  node_repository[("ShaderRepository<br/>persistence port")]
  node_sql_stores[("PostgreSQL / SQLite<br/>SQL stores<br/>[docker-compose.yml]")]
end

subgraph group_tools["AI tooling"]
  node_mcp{{"MCP stdio server<br/>AI control bridge<br/>[server.ts]"}}
end

node_web_ssr -->|"hosted by"| node_express
node_web_browser -->|"starts"| node_startup
node_startup -->|"selects shader"| node_workspace
node_workspace -->|"loads and saves"| node_shader_api
node_workspace -->|"edits draft"| node_editor
node_workspace -->|"draft and params"| node_renderer
node_renderer -->|"compiles candidates"| node_pass_compiler
node_pass_compiler -->|"valid pass graph"| node_frame_render
node_shader_api -->|"HTTP &#40;web&#41;"| node_api_controller
node_api_controller -->|"domain calls"| node_shader_library
node_express -->|"initializes"| node_server_library_factory
node_server_library_factory -->|"provides"| node_shader_library
node_shader_library -->|"persists through"| node_repository
node_repository -->|"PostgreSQL or SQLite"| node_sql_stores
node_preload -->|"restricted typed IPC"| node_ipc_handlers
node_ipc_handlers -->|"domain calls"| node_shader_library
node_electron_main -->|"registers"| node_ipc_handlers
node_electron_main -->|"manages"| node_surface_windows
node_shader_api -.->|"desktop transport"| node_preload
node_workspace -.->|"uses contracts"| node_shared_contracts
node_shader_library -.->|"uses contracts"| node_shared_contracts
node_mcp -.->|"authenticated localhost control"| node_web_browser

click node_web_browser "https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/main.ts"
click node_web_ssr "https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/main.server.ts"
click node_workspace "https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/workspace/shader-store.ts"
click node_startup "https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/workspace/startup-coordinator.ts"
click node_shader_api "https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/api/shader-api.ts"
click node_editor "https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/editor/code-editor.ts"
click node_renderer "https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/rendering/shader-engine.ts"
click node_pass_compiler "https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/rendering/engine/pass-compiler.ts"
click node_frame_render "https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/rendering/frame-render.ts"
click node_express "https://github.com/antelm-dev/shader-studio/blob/master/apps/server/src/index.ts"
click node_api_controller "https://github.com/antelm-dev/shader-studio/blob/master/apps/server/src/api/api.controller.ts"
click node_server_library_factory "https://github.com/antelm-dev/shader-studio/blob/master/apps/server/src/create-library.ts"
click node_electron_main "https://github.com/antelm-dev/shader-studio/blob/master/apps/desktop/main/src/main.ts"
click node_preload "https://github.com/antelm-dev/shader-studio/blob/master/apps/desktop/preload/src/preload.ts"
click node_ipc_handlers "https://github.com/antelm-dev/shader-studio/blob/master/apps/desktop/main/src/ipc/shader.ipc.ts"
click node_surface_windows "https://github.com/antelm-dev/shader-studio/blob/master/apps/desktop/main/src/windows/surface-window-manager.ts"
click node_shared_contracts "https://github.com/antelm-dev/shader-studio/blob/master/libs/shared/src/model/index.ts"
click node_shader_library "https://github.com/antelm-dev/shader-studio/blob/master/libs/backend/src/library/shader-library.ts"
click node_repository "https://github.com/antelm-dev/shader-studio/blob/master/libs/backend/src/persistence/shader-repository.ts"
click node_sql_stores "https://github.com/antelm-dev/shader-studio/blob/master/docker-compose.yml"
click node_mcp "https://github.com/antelm-dev/shader-studio/blob/master/tools/mcp/src/server.ts"

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_web_browser,node_web_ssr,node_workspace,node_startup,node_shader_api,node_editor,node_renderer,node_pass_compiler,node_frame_render toneBlue
class node_express,node_api_controller,node_server_library_factory toneAmber
class node_electron_main,node_preload,node_ipc_handlers,node_surface_windows toneMint
class node_shared_contracts,node_shader_library,node_repository,node_sql_stores toneRose
class node_mcp toneIndigo
```

## Components

### Web workspace

- [Angular browser app](https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/main.ts): browser runtime · Hydrates SSR output and runs the shader workspace. · `apps/web/src/main.ts`
- [Angular SSR entry](https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/main.server.ts): SSR runtime · `apps/web/src/main.server.ts`
- [Shader workspace state](https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/workspace/shader-store.ts): state layer · Separates saved records, editable drafts, and live parameters. · `apps/web/src/app/workspace/shader-store.ts`
- [Startup coordinator](https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/workspace/startup-coordinator.ts): routing startup · Selects the active shader at application startup. · `apps/web/src/app/workspace/startup-coordinator.ts`
- [Replaceable shader API](https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/api/shader-api.ts): transport port · Uses HTTP on web and typed IPC on desktop. · `apps/web/src/app/api/shader-api.ts`
- [Monaco GLSL editor](https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/editor/code-editor.ts): editor layer · Keeps GLSL formatting and snippets separate from storage and rendering. · `apps/web/src/app/editor/code-editor.ts`
- [Shader engine](https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/rendering/shader-engine.ts): WebGL renderer · Maintains the live pass graph, preview, capture, and export outputs. · `apps/web/src/app/rendering/shader-engine.ts`
- [Offscreen pass compiler](https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/rendering/engine/pass-compiler.ts): render stage · Validates candidate passes before replacing the last valid material. · `apps/web/src/app/rendering/engine/pass-compiler.ts`
- [Frame render pipeline](https://github.com/antelm-dev/shader-studio/blob/master/apps/web/src/app/rendering/frame-render.ts): render stage · Binds controls and textures across Image, Common, and Buffer passes. · `apps/web/src/app/rendering/frame-render.ts`

### Server runtime

- [Express API and SSR host](https://github.com/antelm-dev/shader-studio/blob/master/apps/server/src/index.ts): server runtime · Serves public API requests and Angular SSR. · `apps/server/src/index.ts`
- [API controller](https://github.com/antelm-dev/shader-studio/blob/master/apps/server/src/api/api.controller.ts): HTTP boundary · Maps requests to domain operations and returns the public error envelope. · `apps/server/src/api/api.controller.ts`
- [Library factory](https://github.com/antelm-dev/shader-studio/blob/master/apps/server/src/create-library.ts): composition root · Selects and initializes persistence before API exposure. · `apps/server/src/create-library.ts`

### Desktop runtime

- [Electron main process](https://github.com/antelm-dev/shader-studio/blob/master/apps/desktop/main/src/main.ts): desktop runtime · Owns local filesystem and database access. · `apps/desktop/main/src/main.ts`
- [Sandboxed preload bridge](https://github.com/antelm-dev/shader-studio/blob/master/apps/desktop/preload/src/preload.ts): IPC boundary · Exposes a restricted typed API to the renderer. · `apps/desktop/preload/src/preload.ts`
- [Shader IPC handlers](https://github.com/antelm-dev/shader-studio/blob/master/apps/desktop/main/src/ipc/shader.ipc.ts): IPC adapter · Invokes the shared backend library from desktop UI requests. · `apps/desktop/main/src/ipc/shader.ipc.ts`
- [Surface window manager](https://github.com/antelm-dev/shader-studio/blob/master/apps/desktop/main/src/windows/surface-window-manager.ts): desktop output · Manages independent output windows. · `apps/desktop/main/src/windows/surface-window-manager.ts`

### Domain and storage

- [Shared domain contracts](https://github.com/antelm-dev/shader-studio/blob/master/libs/shared/src/model/index.ts): runtime-neutral core · Models projects, controls, validation, GLSL transforms, capture, and protocols. · `libs/shared/src/model/index.ts`
- [ShaderLibrary](https://github.com/antelm-dev/shader-studio/blob/master/libs/backend/src/library/shader-library.ts): domain service · Central domain operations with transactional revision-conflict handling. · `libs/backend/src/library/shader-library.ts`
- [ShaderRepository](https://github.com/antelm-dev/shader-studio/blob/master/libs/backend/src/persistence/shader-repository.ts): persistence port · Selects PostgreSQL for web production or SQLite for desktop and development. · `libs/backend/src/persistence/shader-repository.ts`
- [PostgreSQL / SQLite](https://github.com/antelm-dev/shader-studio/blob/master/docker-compose.yml): SQL stores · PostgreSQL is provisioned for Docker web deployments; SQLite is local desktop storage. · `docker-compose.yml`

### AI tooling

- [MCP stdio server](https://github.com/antelm-dev/shader-studio/blob/master/tools/mcp/src/server.ts): AI control bridge · Bridges AI clients to a locally open app tab through authenticated localhost messaging. · `tools/mcp/src/server.ts`

## Connections

- Angular SSR entry → Express API and SSR host: hosted by
- Angular browser app → Startup coordinator: starts
- Startup coordinator → Shader workspace state: selects shader
- Shader workspace state → Replaceable shader API: loads and saves
- Shader workspace state → Monaco GLSL editor: edits draft
- Shader workspace state → Shader engine: draft and params
- Shader engine → Offscreen pass compiler: compiles candidates
- Offscreen pass compiler → Frame render pipeline: valid pass graph
- Replaceable shader API → API controller: HTTP (web)
- API controller → ShaderLibrary: domain calls
- Express API and SSR host → Library factory: initializes
- Library factory → ShaderLibrary: provides
- ShaderLibrary → ShaderRepository: persists through
- ShaderRepository → PostgreSQL / SQLite: PostgreSQL or SQLite
- Sandboxed preload bridge → Shader IPC handlers: restricted typed IPC
- Shader IPC handlers → ShaderLibrary: domain calls
- Electron main process → Shader IPC handlers: registers
- Electron main process → Surface window manager: manages
- Replaceable shader API → Sandboxed preload bridge: desktop transport
- Shader workspace state → Shared domain contracts: uses contracts
- ShaderLibrary → Shared domain contracts: uses contracts
- MCP stdio server → Angular browser app: authenticated localhost control
