How antelm-dev/shader-studio works
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: shader-store.ts Shader workspace state · shader-library.ts ShaderLibrary · shader-api.ts Replaceable shader API · shader.ipc.ts Shader IPC handlers
Components 21
Web workspace
- Angular browser app · Hydrates SSR output and runs the shader workspace.
apps/web/src/main.ts - Angular SSR entry
apps/web/src/main.server.ts - Shader workspace state · Separates saved records, editable drafts, and live parameters.
apps/web/src/app/workspace/shader-store.ts - Startup coordinator · Selects the active shader at application startup.
apps/web/src/app/workspace/startup-coordinator.ts - Replaceable shader API · Uses HTTP on web and typed IPC on desktop.
apps/web/src/app/api/shader-api.ts - Monaco GLSL editor · Keeps GLSL formatting and snippets separate from storage and rendering.
apps/web/src/app/editor/code-editor.ts - Shader engine · Maintains the live pass graph, preview, capture, and export outputs.
apps/web/src/app/rendering/shader-engine.ts - Offscreen pass compiler · Validates candidate passes before replacing the last valid material.
apps/web/src/app/rendering/engine/pass-compiler.ts - Frame render pipeline · 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 · Serves public API requests and Angular SSR.
apps/server/src/index.ts - API controller · Maps requests to domain operations and returns the public error envelope.
apps/server/src/api/api.controller.ts - Library factory · Selects and initializes persistence before API exposure.
apps/server/src/create-library.ts
Desktop runtime
- Electron main process · Owns local filesystem and database access.
apps/desktop/main/src/main.ts - Sandboxed preload bridge · Exposes a restricted typed API to the renderer.
apps/desktop/preload/src/preload.ts - Shader IPC handlers · Invokes the shared backend library from desktop UI requests.
apps/desktop/main/src/ipc/shader.ipc.ts - Surface window manager · Manages independent output windows.
apps/desktop/main/src/windows/surface-window-manager.ts
Domain and storage
- Shared domain contracts · Models projects, controls, validation, GLSL transforms, capture, and protocols.
libs/shared/src/model/index.ts - ShaderLibrary · Central domain operations with transactional revision-conflict handling.
libs/backend/src/library/shader-library.ts - ShaderRepository · Selects PostgreSQL for web production or SQLite for desktop and development.
libs/backend/src/persistence/shader-repository.ts - PostgreSQL / SQLite · PostgreSQL is provisioned for Docker web deployments; SQLite is local desktop storage.
docker-compose.yml
AI tooling
- MCP stdio server · Bridges AI clients to a locally open app tab through authenticated localhost messaging.
tools/mcp/src/server.ts
Connections 22
- 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