# myned-ai/avatar-chat-widget architecture

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

- Interactive diagram: https://gitdiagram.com/myned-ai/avatar-chat-widget
- Repository: https://github.com/myned-ai/avatar-chat-widget

## Overview

Avatar Chat Widget is an embeddable voice-and-text chat product with a lazy-loaded Gaussian-splat avatar. The documented user workflow is to initialize the widget, exchange text or microphone audio with a WebSocket service, and present streamed chat and synchronized avatar responses. A renderer-only mount is also supported. The graph preserves major audio, animation, authentication, and presentation subsystems; several links among unsampled components are omitted or marked unverified rather than inferred from names.

Main entry points: [`src/widget.ts`](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/widget.ts) (Widget runtime), [`src/services/AvatarProtocolClient.ts`](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/AvatarProtocolClient.ts) (Avatar protocol client), [`src/managers/ChatManager.ts`](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/managers/ChatManager.ts) (Chat orchestration), [`src/services/SocketService.ts`](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/SocketService.ts) (WebSocket connection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Widget entry"]
  node_widget_api["Widget API<br/>[main.ts]"]
  node_widget_runtime["Widget runtime<br/>[widget.ts]"]
  node_config["Widget configuration<br/>[config.ts]"]
end

subgraph group_chat["Chat experience"]
  node_templates["Widget templates<br/>[templates.ts]"]
  node_styles["Shadow DOM styles<br/>[styles.ts]"]
  node_drawer["View-mode drawer"]
  node_chat_manager["Chat orchestration<br/>[ChatManager.ts]"]
  node_transcript["Transcript streaming"]
  node_subtitles["Subtitle display"]
end

subgraph group_transport["Voice and transport"]
  node_voice_controller["Voice input control"]
  node_audio_input["Microphone capture<br/>[AudioInput.ts]"]
  node_pcm_worklet["PCM16 audio worklet"]
  node_audio_context["Audio context"]
  node_audio_output["Audio playback<br/>[AudioOutput.ts]"]
  node_sync_playback["Synchronized playback<br/>[SyncPlayback.ts]"]
  node_protocol["Avatar protocol client"]
  node_socket["WebSocket connection<br/>[SocketService.ts]"]
  node_auth["Token authentication<br/>[AuthService.ts]"]
end

subgraph group_avatar["Avatar runtime"]
  node_avatar_mount["Avatar mount API<br/>[mount-avatar.ts]"]
  node_lazy_avatar["Lazy avatar loader<br/>[LazyAvatar.ts]"]
  node_gaussian_avatar["Gaussian avatar renderer<br/>[GaussianAvatar.ts]"]
  node_avatar_state["Avatar state arbiter"]
  node_energy["Energy envelope<br/>[EnergyEnvelope.ts]"]
  node_blendshape_buffer["Blendshape buffering"]
end

subgraph group_shared["Shared services"]
  node_shared_utils["Runtime utilities"]
  node_chat_constants["Chat constants<br/>[chat.ts]"]
  node_arkit_constants["ARKit weights<br/>[arkit.ts]"]
  node_layout_constants["Layout constants<br/>[layout.ts]"]
end

node_site(("Embedding site"))
node_backend(("Chat backend"))

node_site -->|"initializes"| node_widget_api
node_widget_api -.->|"starts widget"| node_widget_runtime
node_widget_runtime -.->|"uses settings"| node_config
node_widget_runtime -.->|"renders"| node_templates
node_widget_runtime -->|"encapsulates styles"| node_styles
node_widget_runtime -.->|"manages chat"| node_chat_manager
node_widget_runtime -.->|"mounts avatar"| node_avatar_mount
node_widget_runtime -.->|"controls views"| node_drawer
node_chat_manager -.->|"exchanges messages"| node_protocol
node_chat_manager -.->|"updates transcript"| node_transcript
node_chat_manager -.->|"updates subtitles"| node_subtitles
node_voice_controller -->|"starts capture"| node_audio_input
node_voice_controller -->|"sends audio"| node_protocol
node_audio_input -.->|"processes audio"| node_pcm_worklet
node_audio_input -.->|"uses context"| node_audio_context
node_protocol -->|"sends protocol messages"| node_socket
node_socket -->|"requests token"| node_auth
node_socket -->|"connects"| node_backend
node_backend -->|"streams responses"| node_protocol
node_protocol -.->|"delivers sync events"| node_sync_playback
node_sync_playback -.->|"synchronizes playback"| node_audio_output
node_sync_playback -.->|"coordinates animation data"| node_blendshape_buffer
node_avatar_mount -->|"loads lazily"| node_lazy_avatar
node_lazy_avatar -.->|"loads renderer"| node_gaussian_avatar
node_gaussian_avatar -->|"uses envelope"| node_energy
node_gaussian_avatar -->|"initializes weights"| node_arkit_constants
node_avatar_state -.->|"arbitrates state"| node_gaussian_avatar
node_drawer -->|"uses dimensions"| node_layout_constants
node_transcript -->|"uses timing settings"| node_chat_constants
node_subtitles -->|"uses subtitle settings"| node_chat_constants
node_protocol -->|"uses event emitter"| node_shared_utils
node_socket -->|"uses runtime helpers"| node_shared_utils

click node_widget_api "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/main.ts"
click node_widget_runtime "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/widget.ts"
click node_config "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/config.ts"
click node_templates "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/widget/templates.ts"
click node_styles "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/widget/styles.ts"
click node_drawer "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/widget/DrawerController.ts"
click node_chat_manager "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/managers/ChatManager.ts"
click node_transcript "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/managers/TranscriptManager.ts"
click node_subtitles "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/managers/SubtitleController.ts"
click node_voice_controller "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/managers/VoiceInputController.ts"
click node_audio_input "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/AudioInput.ts"
click node_pcm_worklet "https://github.com/myned-ai/avatar-chat-widget/blob/main/public/pcm16-processor.worklet.js"
click node_audio_context "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/AudioContextManager.ts"
click node_audio_output "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/AudioOutput.ts"
click node_sync_playback "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/SyncPlayback.ts"
click node_protocol "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/AvatarProtocolClient.ts"
click node_socket "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/SocketService.ts"
click node_auth "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/AuthService.ts"
click node_avatar_mount "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/avatar/mount-avatar.ts"
click node_lazy_avatar "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/avatar/LazyAvatar.ts"
click node_gaussian_avatar "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/avatar/GaussianAvatar.ts"
click node_avatar_state "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/managers/AvatarStateArbiter.ts"
click node_energy "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/avatar/EnergyEnvelope.ts"
click node_blendshape_buffer "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/BlendshapeBuffer.ts"
click node_shared_utils "https://github.com/myned-ai/avatar-chat-widget/tree/main/src/utils"
click node_chat_constants "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/constants/chat.ts"
click node_arkit_constants "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/constants/arkit.ts"
click node_layout_constants "https://github.com/myned-ai/avatar-chat-widget/blob/main/src/constants/layout.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_widget_api,node_widget_runtime,node_config toneBlue
class node_templates,node_styles,node_drawer,node_chat_manager,node_transcript,node_subtitles toneAmber
class node_voice_controller,node_audio_input,node_pcm_worklet,node_audio_context,node_audio_output,node_sync_playback,node_protocol,node_socket,node_auth toneMint
class node_avatar_mount,node_lazy_avatar,node_gaussian_avatar,node_avatar_state,node_energy,node_blendshape_buffer toneRose
class node_shared_utils,node_chat_constants,node_arkit_constants,node_layout_constants,node_site,node_backend toneIndigo
```

## Components

### Widget entry

- [Widget API](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/main.ts): `src/main.ts`
- [Widget runtime](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/widget.ts): `src/widget.ts`
- [Widget configuration](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/config.ts): `src/config.ts`

### Chat experience

- [Widget templates](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/widget/templates.ts): `src/widget/templates.ts`
- [Shadow DOM styles](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/widget/styles.ts): `src/widget/styles.ts`
- [View-mode drawer](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/widget/DrawerController.ts): `src/widget/DrawerController.ts`
- [Chat orchestration](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/managers/ChatManager.ts): `src/managers/ChatManager.ts`
- [Transcript streaming](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/managers/TranscriptManager.ts): `src/managers/TranscriptManager.ts`
- [Subtitle display](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/managers/SubtitleController.ts): `src/managers/SubtitleController.ts`

### Voice and transport

- [Voice input control](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/managers/VoiceInputController.ts): `src/managers/VoiceInputController.ts`
- [Microphone capture](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/AudioInput.ts): `src/services/AudioInput.ts`
- [PCM16 audio worklet](https://github.com/myned-ai/avatar-chat-widget/blob/main/public/pcm16-processor.worklet.js): `public/pcm16-processor.worklet.js`
- [Audio context](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/AudioContextManager.ts): `src/services/AudioContextManager.ts`
- [Audio playback](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/AudioOutput.ts): `src/services/AudioOutput.ts`
- [Synchronized playback](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/SyncPlayback.ts): `src/services/SyncPlayback.ts`
- [Avatar protocol client](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/AvatarProtocolClient.ts): `src/services/AvatarProtocolClient.ts`
- [WebSocket connection](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/SocketService.ts): `src/services/SocketService.ts`
- [Token authentication](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/AuthService.ts): `src/services/AuthService.ts`

### Avatar runtime

- [Avatar mount API](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/avatar/mount-avatar.ts): `src/avatar/mount-avatar.ts`
- [Lazy avatar loader](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/avatar/LazyAvatar.ts): `src/avatar/LazyAvatar.ts`
- [Gaussian avatar renderer](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/avatar/GaussianAvatar.ts): `src/avatar/GaussianAvatar.ts`
- [Avatar state arbiter](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/managers/AvatarStateArbiter.ts): `src/managers/AvatarStateArbiter.ts`
- [Energy envelope](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/avatar/EnergyEnvelope.ts): `src/avatar/EnergyEnvelope.ts`
- [Blendshape buffering](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/services/BlendshapeBuffer.ts): `src/services/BlendshapeBuffer.ts`

### Shared services

- [Runtime utilities](https://github.com/myned-ai/avatar-chat-widget/tree/main/src/utils): `src/utils`
- [Chat constants](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/constants/chat.ts): `src/constants/chat.ts`
- [ARKit weights](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/constants/arkit.ts): `src/constants/arkit.ts`
- [Layout constants](https://github.com/myned-ai/avatar-chat-widget/blob/main/src/constants/layout.ts): `src/constants/layout.ts`

### Other components

- **Embedding site**
- **Chat backend**

## Connections

- Embedding site → Widget API: initializes (evidence: `README.md`)
- Widget API → Widget runtime: starts widget
- Widget runtime → Widget configuration: uses settings
- Widget runtime → Widget templates: renders
- Widget runtime → Shadow DOM styles: encapsulates styles (evidence: `README.md`)
- Widget runtime → Chat orchestration: manages chat
- Widget runtime → Avatar mount API: mounts avatar
- Widget runtime → View-mode drawer: controls views
- Chat orchestration → Avatar protocol client: exchanges messages
- Chat orchestration → Transcript streaming: updates transcript
- Chat orchestration → Subtitle display: updates subtitles
- Voice input control → Microphone capture: starts capture (evidence: `src/managers/VoiceInputController.ts`)
- Voice input control → Avatar protocol client: sends audio (evidence: `src/managers/VoiceInputController.ts`)
- Microphone capture → PCM16 audio worklet: processes audio
- Microphone capture → Audio context: uses context
- Avatar protocol client → WebSocket connection: sends protocol messages (evidence: `src/services/AvatarProtocolClient.ts`)
- WebSocket connection → Token authentication: requests token (evidence: `src/services/SocketService.ts`)
- WebSocket connection → Chat backend: connects (evidence: `README.md`)
- Chat backend → Avatar protocol client: streams responses (evidence: `README.md`)
- Avatar protocol client → Synchronized playback: delivers sync events
- Synchronized playback → Audio playback: synchronizes playback
- Synchronized playback → Blendshape buffering: coordinates animation data
- Avatar mount API → Lazy avatar loader: loads lazily (evidence: `README.md`)
- Lazy avatar loader → Gaussian avatar renderer: loads renderer
- Gaussian avatar renderer → Energy envelope: uses envelope (evidence: `src/avatar/GaussianAvatar.ts`)
- Gaussian avatar renderer → ARKit weights: initializes weights (evidence: `src/avatar/GaussianAvatar.ts`)
- Avatar state arbiter → Gaussian avatar renderer: arbitrates state
- View-mode drawer → Layout constants: uses dimensions (evidence: `src/widget/DrawerController.ts`)
- Transcript streaming → Chat constants: uses timing settings (evidence: `src/managers/TranscriptManager.ts`)
- Subtitle display → Chat constants: uses subtitle settings (evidence: `src/managers/SubtitleController.ts`)
- Avatar protocol client → Runtime utilities: uses event emitter (evidence: `src/services/AvatarProtocolClient.ts`)
- WebSocket connection → Runtime utilities: uses runtime helpers (evidence: `src/services/SocketService.ts`)
