# open-din/din-studio architecture

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

- Interactive diagram: https://gitdiagram.com/open-din/din-studio
- Repository: https://github.com/open-din/din-studio

## Overview

1. **What this repo owns**
   - `din-studio` is the studio layer above `@open-din/react`: it owns the editor UI, the desktop/browser shells, the MCP server, and code-generation/agent workflows.
   - It deliberately does **not** own the public patch schema or runtime semantics; those belong to `react-din` / `din-core`.

2. **Top-level architecture**
   - The repository is organized around a few runtime targets: a **browser editor**, an **Electron desktop app**, and an **MCP server**.
   - Most user-facing behavior lives in `ui/`, while `targets/` contains thin platform entrypoints that host the same product surface in different runtimes.

3. **Product contract and generated manifests**
   - The `project/` directory is the repository’s specification layer: route cards, editor node slices, MCP tool slices, surface manifests, coverage manifests, feature specs, and skills.
   - These files act as the source of truth for what the editor exposes, what MCP tools exist, and what scenarios tests should cover.
   - Validation and generation scripts in `scripts/` and tests in `tests/` enforce consistency between these manifests and the implementation.

4. **Editor shell and workspace UI**
   - The main UI entry points are `ui/App.tsx`, `ui/ProjectLauncher.tsx`, and `ui/Editor.tsx`.
   - The shell layer in `ui/shell/` composes the workspace into panels and drawers: activity rail, inspector, catalog explorer, source control, agent panel, command palette, and status/footer areas.
   - This is the main coordination layer for navigation, panel state, and editor-level actions.

5. **Graph editor subsystem**
   - The actual graph-building experience is centered in `ui/editor/`.
   - `store.ts`, `graphStorage.ts`, `graphBuilders.ts`, `graphUtils.ts`, and `defaultGraph.ts` manage graph state and persistence.
   - `nodeCatalog/`, `nodeUiRegistry.ts`, `nodes/`, and `templateLibrary.ts` define the available node types, their UI affordances, and reusable graph templates.

6. **Audio and MIDI runtime-facing features**
   - Audio and MIDI concerns are isolated inside the editor subsystem but represent a distinct data flow from graph state into interactive runtime behavior.
   - Files such as `AudioEngine.ts`, `audioImport.ts`, `audioExport.ts`, `audioLibrary.ts`, `midiRuntime.ts`, `midiDetectionStore.ts`, and the MIDI-related node components implement import/export, device detection, playback, recording, and control surfaces.
   - The editor UI is therefore both a graph authoring tool and a live audio/MIDI control surface.

7. **Node rendering and inspector/code generation**
   - Each node type has a dedicated React component under `ui/editor/nodes/`, with shared UI primitives in `ui/editor/components/`.
   - `Inspector.tsx` and `CodeGenerator.tsx` bridge the visual graph to generated outputs and editable node metadata.
   - This is where user edits on the canvas become structured changes to node parameters, connections, and generated code or patch artifacts.

8. **AI agent and operation pipeline**
   - `ui/ai/` contains the agent-facing layer: prompt construction, tool definitions, settings, chat storage, and operation application.
   - `bridge/` adds a lightweight protocol/status layer for connecting the editor UI to the agent/MCP world.
   - The important architectural boundary here is that the agent does not directly mutate UI state; it proposes or applies **operations** that are funneled through shared editing logic.

9. **Shared operation/session abstractions**
   - `core/` contains reusable abstractions such as sessions, operations, and offline behavior.
   - This is the shared backbone for cross-cutting workflows like persistence, agent actions, and any logic that needs to work consistently in browser, desktop, or bridge contexts.

10. **RAG/search support**
    - `src/rag/` and `src/rag-ui.ts` implement retrieval and augmentation support: chunking, embeddings, vector storage, search, and retrieval.
    - This subsystem is likely used to enrich agent workflows with repository context, docs, or generated knowledge rather than to power the editor core itself.
    - It sits adjacent to the AI tooling boundary, feeding context into assistant-driven actions.

11. **MCP server target**
    - `targets/mcp/` is a standalone runtime exposing the studio’s capabilities through MCP.
    - It includes both stdio and TLS/bridge server paths, runtime definitions/handlers/resources, session registry, logging, and config.
    - This target is the main integration boundary for external agents/tools and mirrors the same underlying manifest/tooling contracts defined in `project/`.

12. **Desktop and web hosts**
    - `targets/app/` is the Electron host, split into main, preload, and renderer entrypoints.
    - `targets/web/` is the browser host, built with Vite and used for the editor in a pure web runtime.
    - These targets are intentionally thin: they host the same UI/product surface while changing packaging and process boundaries.

13. **Documentation, feature specs, and tests as architecture enforcement**
    - `docs/` and `project/features/` describe the intended behaviors of the editor, nodes, panels, and agent/MCP flows.
    - `tests/unit/` and `tests/e2e/` map closely to those specs, giving the repo a strong contract-testing shape.
    - For an architecture diagram, these are not just documentation; they are the governance layer that keeps the UI, manifests, and MCP surfaces aligned.

14. **External dependencies and trust boundaries**
    - The repo assumes `@open-din/react` provides the public patch/MIDI/data surfaces and treats that package as the runtime authority boundary.
    - `din-core` owns runtime/registry semantics, while `din-agents` owns routing and quality gates.
    - `din-studio` therefore sits in the middle: it authoring tools, shell UI, and integration surfaces that orchestrate those external authorities without redefining them.

Main entry points: [`ui/shell/EditorShell.tsx`](https://github.com/open-din/din-studio/blob/main/ui/shell/EditorShell.tsx) (Editor shell), [`targets/mcp/src/index.ts`](https://github.com/open-din/din-studio/blob/main/targets/mcp/src/index.ts) (MCP server), [`tests/unit/store-and-codegen.spec.ts`](https://github.com/open-din/din-studio/blob/main/tests/unit/store-and-codegen.spec.ts) (Tests), [`ui/App.tsx`](https://github.com/open-din/din-studio/blob/main/ui/App.tsx) (App shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["UI layer"]
  node_ui_app["App shell<br/>entrypoint<br/>[App.tsx]"]
  node_ui_launcher["Project launcher"]
  node_ui_editor["Editor surface<br/>workspace<br/>[Editor.tsx]"]
  node_ui_shell["Editor shell<br/>workspace-shell<br/>[EditorShell.tsx]"]
  node_ui_graph[("Graph editor<br/>graph-core<br/>[store.ts]")]
  node_ui_nodes["Node library<br/>node-ui<br/>[index.ts]"]
  node_ui_inspector_codegen["Inspector/codegen<br/>metadata<br/>[Inspector.tsx]"]
  node_ui_audio_midi{{"Audio/MIDI runtime<br/>runtime-controls<br/>[AudioEngine.ts]"}}
  node_ui_ai["AI tools<br/>agent-layer<br/>[agent.ts]"]
  node_bridge["Bridge protocol<br/>[protocol.ts]"]
end

subgraph group_targets["Runtime targets"]
  node_targets_web["Web host<br/>[main.tsx]"]
  node_targets_app["Electron host<br/>desktop-host<br/>[main.ts]"]
  node_targets_mcp["MCP server<br/>runtime-server<br/>[index.ts]"]
end

subgraph group_governance["Specs and tests"]
  node_project_specs["Studio specs<br/>manifests<br/>[REPO_MANIFEST.json]"]
  node_docs["Docs<br/>[README.md]"]
  node_tests["Tests<br/>verification"]
end

node_core_ops["Core ops<br/>shared-core<br/>[operations.ts]"]
node_rag[("RAG stack<br/>retrieval<br/>[search.ts]")]

node_ui_app -->|"opens"| node_ui_launcher
node_ui_app -->|"hosts"| node_ui_editor
node_ui_launcher -->|"reads"| node_project_specs
node_ui_editor -->|"uses"| node_ui_shell
node_ui_shell -->|"controls"| node_ui_graph
node_ui_shell -->|"opens"| node_ui_inspector_codegen
node_ui_shell -->|"surfaces"| node_ui_audio_midi
node_ui_graph -->|"instantiates"| node_ui_nodes
node_ui_graph -->|"feeds"| node_ui_inspector_codegen
node_ui_nodes -->|"includes"| node_ui_audio_midi
node_ui_ai -->|"connects"| node_bridge
node_ui_ai -->|"applies"| node_core_ops
node_ui_ai -->|"retrieves"| node_rag
node_bridge -->|"adapts"| node_targets_mcp
node_targets_web -->|"boots"| node_ui_app
node_targets_app -->|"boots"| node_ui_app
node_targets_mcp -->|"implements"| node_project_specs
node_targets_mcp -->|"shares"| node_core_ops
node_project_specs -->|"governs"| node_tests
node_docs -->|"describes"| node_ui_shell
node_docs -->|"describes"| node_targets_mcp
node_tests -->|"verifies"| node_ui_graph
node_tests -->|"verifies"| node_targets_mcp
node_tests -->|"verifies"| node_rag

click node_ui_app "https://github.com/open-din/din-studio/blob/main/ui/App.tsx"
click node_ui_launcher "https://github.com/open-din/din-studio/blob/main/ui/ProjectLauncher.tsx"
click node_ui_editor "https://github.com/open-din/din-studio/blob/main/ui/Editor.tsx"
click node_ui_shell "https://github.com/open-din/din-studio/blob/main/ui/shell/EditorShell.tsx"
click node_ui_graph "https://github.com/open-din/din-studio/blob/main/ui/editor/store.ts"
click node_ui_nodes "https://github.com/open-din/din-studio/blob/main/ui/editor/nodes/index.ts"
click node_ui_inspector_codegen "https://github.com/open-din/din-studio/blob/main/ui/editor/Inspector.tsx"
click node_ui_audio_midi "https://github.com/open-din/din-studio/blob/main/ui/editor/AudioEngine.ts"
click node_ui_ai "https://github.com/open-din/din-studio/blob/main/ui/ai/agent.ts"
click node_bridge "https://github.com/open-din/din-studio/blob/main/bridge/protocol.ts"
click node_core_ops "https://github.com/open-din/din-studio/blob/main/core/operations.ts"
click node_rag "https://github.com/open-din/din-studio/blob/main/src/rag/search.ts"
click node_targets_web "https://github.com/open-din/din-studio/blob/main/targets/web/main.tsx"
click node_targets_app "https://github.com/open-din/din-studio/blob/main/targets/app/main.ts"
click node_targets_mcp "https://github.com/open-din/din-studio/blob/main/targets/mcp/src/index.ts"
click node_project_specs "https://github.com/open-din/din-studio/blob/main/project/REPO_MANIFEST.json"
click node_docs "https://github.com/open-din/din-studio/blob/main/docs/README.md"
click node_tests "https://github.com/open-din/din-studio/blob/main/tests/unit/store-and-codegen.spec.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_ui_app,node_ui_launcher,node_ui_editor,node_ui_shell,node_ui_graph,node_ui_nodes,node_ui_inspector_codegen,node_ui_audio_midi,node_ui_ai,node_bridge toneBlue
class node_targets_web,node_targets_app,node_targets_mcp toneAmber
class node_project_specs,node_docs,node_tests toneMint
class node_core_ops,node_rag toneNeutral
```

## Components

### UI layer

Browser and desktop-facing studio UI, including shell, editor, and AI surfaces.

- [App shell](https://github.com/open-din/din-studio/blob/main/ui/App.tsx): entrypoint · Top-level app composition and routing between launcher and editor. · `ui/App.tsx`
- [Project launcher](https://github.com/open-din/din-studio/blob/main/ui/ProjectLauncher.tsx): launcher · Entry flow for choosing or opening a studio project. · `ui/ProjectLauncher.tsx`
- [Editor surface](https://github.com/open-din/din-studio/blob/main/ui/Editor.tsx): workspace · Main editing experience that hosts the graph editor and shared studio actions. · `ui/Editor.tsx`
- [Editor shell](https://github.com/open-din/din-studio/blob/main/ui/shell/EditorShell.tsx): workspace-shell · Panel and drawer orchestration for navigation, inspector, catalog, source control, and agent tools. · `ui/shell/EditorShell.tsx`
- [Graph editor](https://github.com/open-din/din-studio/blob/main/ui/editor/store.ts): graph-core · Graph state, persistence, builders, defaults, and template-driven canvas behavior. · `ui/editor/store.ts`
- [Node library](https://github.com/open-din/din-studio/blob/main/ui/editor/nodes/index.ts): node-ui · Node catalog, registry, node components, and reusable node templates. · `ui/editor/nodes/index.ts`
- [Inspector/codegen](https://github.com/open-din/din-studio/blob/main/ui/editor/Inspector.tsx): metadata · Inspector and code generation bridge from canvas edits to structured outputs. · `ui/editor/Inspector.tsx`
- [Audio/MIDI runtime](https://github.com/open-din/din-studio/blob/main/ui/editor/AudioEngine.ts): runtime-controls · Live audio, MIDI import/export, device detection, playback, and control surfaces. · `ui/editor/AudioEngine.ts`
- [AI tools](https://github.com/open-din/din-studio/blob/main/ui/ai/agent.ts): agent-layer · Agent prompts, tools, settings, chat storage, and operation application. · `ui/ai/agent.ts`
- [Bridge protocol](https://github.com/open-din/din-studio/blob/main/bridge/protocol.ts): protocol · Lightweight status and client bridge between the editor UI and agent/MCP world. · `bridge/protocol.ts`

### Runtime targets

Thin host entrypoints for web, Electron, and MCP runtimes.

- [Web host](https://github.com/open-din/din-studio/blob/main/targets/web/main.tsx): host · Browser runtime entrypoint for the studio UI. · `targets/web/main.tsx`
- [Electron host](https://github.com/open-din/din-studio/blob/main/targets/app/main.ts): desktop-host · Electron main, preload, and renderer entrypoints for the desktop app. · `targets/app/main.ts`
- [MCP server](https://github.com/open-din/din-studio/blob/main/targets/mcp/src/index.ts): runtime-server · Standalone MCP runtime with stdio, TLS/bridge, session registry, and handlers. · `targets/mcp/src/index.ts`

### Specs and tests

Manifests, feature specs, docs, and tests that lock the studio contract.

- [Studio specs](https://github.com/open-din/din-studio/blob/main/project/REPO_MANIFEST.json): manifests · Repository manifests, route cards, surface definitions, coverage, and skills that define the product contract. · `project/REPO_MANIFEST.json`
- [Docs](https://github.com/open-din/din-studio/blob/main/docs/README.md): docs · Behavioral and architectural documentation for shells, panels, runtimes, and workflows. · `docs/README.md`
- [Tests](https://github.com/open-din/din-studio/blob/main/tests/unit/store-and-codegen.spec.ts): verification · Unit and end-to-end suites that enforce UI, manifest, audio/MIDI, RAG, and MCP behavior. · `tests/unit/store-and-codegen.spec.ts`

### Other components

- [Core ops](https://github.com/open-din/din-studio/blob/main/core/operations.ts): shared-core · Shared session, operation, and offline abstractions used across runtimes. · `core/operations.ts`
- [RAG stack](https://github.com/open-din/din-studio/blob/main/src/rag/search.ts): retrieval · Chunking, embeddings, vector storage, search, and augmentation for agent context. · `src/rag/search.ts`

## Connections

- App shell → Project launcher: opens · App routes users into project selection or the editor.
- App shell → Editor surface: hosts · App composes the main studio editor experience.
- Project launcher → Studio specs: reads · Launcher behavior follows repository manifest and flow specs.
- Editor surface → Editor shell: uses · Editor delegates workspace composition and panel state to the shell.
- Editor shell → Graph editor: controls · Shell actions mutate graph workspace state.
- Editor shell → Inspector/codegen: opens · Shell exposes inspector and generation panels.
- Editor shell → Audio/MIDI runtime: surfaces · Shell hosts audio and MIDI status/controls.
- Graph editor → Node library: instantiates · Graph state is rendered through node catalog and components.
- Graph editor → Inspector/codegen: feeds · Selected nodes and connections drive inspector/code generation.
- Node library → Audio/MIDI runtime: includes · Several nodes expose audio and MIDI runtime controls.
- AI tools → Bridge protocol: connects · Agent tooling exchanges status and protocol data through the bridge.
- AI tools → Core ops: applies · Agent actions flow through shared operations and session abstractions.
- AI tools → RAG stack: retrieves · Agent workflows can pull contextual retrieval results.
- Bridge protocol → MCP server: adapts · Bridge aligns UI status and protocol expectations with MCP runtime.
- Web host → App shell: boots · Web host mounts the studio app.
- Electron host → App shell: boots · Electron renderer hosts the same app surface.
- MCP server → Studio specs: implements · MCP runtime mirrors the manifest-defined tool and surface contract.
- MCP server → Core ops: shares · Server runtime reuses session and operation abstractions.
- Studio specs → Tests: governs · Specs and manifests are enforced by unit and e2e coverage.
- Docs → Editor shell: describes · Documentation explains shell panels, drawers, and navigation.
- Docs → MCP server: describes · Docs cover MCP runtime behavior and integration boundaries.
- Tests → Graph editor: verifies · Tests cover graph state, codegen, and editor behaviors.
- Tests → MCP server: verifies · Tests cover MCP server runtime and bridge paths.
- Tests → RAG stack: verifies · Tests cover retrieval and search behavior.
