# nvidia/personaplex architecture

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

- Interactive diagram: https://gitdiagram.com/nvidia/personaplex
- Repository: https://github.com/nvidia/personaplex
- Video tour (about a minute): https://gitdiagram.com/nvidia/personaplex/video

## Overview

1. **This repo is split into two main runtimes**
   - `moshi/` is the Python inference package and backend runtime.
   - `client/` is the browser UI, built with Vite + React + TypeScript.
   - The top-level Dockerfiles and `docker-compose.yaml` support packaging and running these together, but the core architecture is a Python model server plus a browser-based audio front end.

2. **Primary execution modes**
   - **Live mode**: `python -m moshi.server` starts a real-time conversational server with SSL and a web UI on port `8998`.
   - **Offline mode**: `python -m moshi.offline` replays an input WAV stream and writes output audio/text files for evaluation.
   - These are two different entry points into the same model stack: one interactive, one batch.

3. **Browser UI responsibilities**
   - The `client/src/pages/Conversation` area is the live conversation screen.
   - It manages microphone capture, playback, audio level visualization, server text/audio display, and model parameter controls.
   - The `Queue` page is a separate pre-chat intake flow, likely collecting user email and calling a small API before entering the conversation experience.

4. **Client-side data path**
   - The browser captures user audio, processes it in the app, and streams it to the backend through a socket-based conversation channel.
   - Server responses come back as both text and audio, which the UI renders separately.
   - Audio is decoded and visualized client-side; there is also a decoder worker and an audio processor, which indicates some real-time processing is offloaded from the main UI thread.

5. **Conversation transport boundary**
   - The client has explicit socket, media, and text/audio hooks under `Conversation/hooks`.
   - This separation suggests the UI is organized around three streams:
     - **input audio stream** from microphone,
     - **output audio stream** from the model,
     - **text/control stream** for transcript, status, and model parameters.
   - The architecture is therefore duplex and streaming, not request/response only.

6. **Protocol layer between browser and server**
   - `client/src/protocol` contains an encoder and shared message types.
   - This is the wire-format boundary for messages exchanged with the backend.
   - Having a dedicated protocol package indicates the client/server contract is explicit and likely version-sensitive, especially for streaming audio chunks and turn-taking events.

7. **Backend server orchestration**
   - `moshi/server.py` is the live inference service entry point.
   - `moshi/utils/connection.py` and `moshi/utils/logging.py` suggest the server manages persistent client sessions, stream coordination, and operational logging.
   - `moshi/client_utils.py` likely contains helper logic for browser-facing integration, keeping protocol/transport concerns separate from model code.

8. **Model stack inside `moshi/models` and `moshi/modules`**
   - `models/lm.py`, `models/compression.py`, and `models/loaders.py` form the model-facing layer.
   - `modules/` contains the building blocks for the core architecture: transformer components, streaming support, convolution/resampling, RoPE, gating, and SEANet-style audio processing.
   - This implies the system is a streaming speech model with both text/LLM-style and audio-specific components rather than a plain TTS or ASR pipeline.

9. **Audio tokenization and quantization**
   - `moshi/quantization/` contains the code for vector quantization and related codebook handling.
   - That layer is important because the model operates on compressed audio representations rather than raw waveform generation directly.
   - In the overall data flow, raw user audio is encoded into model-friendly tokens, processed by the conversational model, then decoded back into audio.

10. **Offline evaluation path**
   - `moshi/offline.py` mirrors the live stack but runs from an input file instead of a live socket.
   - The sample assets in `assets/test/` show the expected inputs: assistant/service WAV files and a text prompt file.
   - Offline mode produces both waveform output and a text artifact, which is useful for reproducible evaluation and benchmarking.

11. **Persona and prompt conditioning**
   - Persona control is not a separate service; it is injected through text prompts and voice prompts at runtime.
   - The README’s “assistant” and “customer service” examples reflect two main behavioral regimes the model was trained for.
   - The web UI likely exposes these role/prompt controls through the `ModelParams` component and related state hooks.

12. **Deployment and runtime dependencies**
   - The project depends on **PyTorch**, **Hugging Face model weights/token access**, and the **Opus** codec for audio handling.
   - The server can optionally use CPU offload for large models, which affects deployment topology and latency/memory tradeoffs.
   - Temporary SSL cert generation is built into the run flow, which means browser access is expected over HTTPS even for local/demo use.

13. **How to think about the architecture diagram**
   - Draw three layers: **browser client**, **streaming inference server**, and **model internals**.
   - Show the browser sending microphone audio and prompt/control data over a socket/protocol boundary.
   - Show the server orchestrating real-time streaming inference, with model internals split into compression/quantization, language-modeling/transformer logic, and audio decode paths.
   - Add an alternate offline path that bypasses the browser and feeds WAV files directly into the same inference core.

Main entry points: [`client/src/pages/Conversation/Conversation.tsx`](https://github.com/nvidia/personaplex/blob/main/client/src/pages/Conversation/Conversation.tsx) (Conversation), [`moshi/moshi/server.py`](https://github.com/nvidia/personaplex/blob/main/moshi/moshi/server.py) (Live server), [`moshi/moshi/models/lm.py`](https://github.com/nvidia/personaplex/blob/main/moshi/moshi/models/lm.py) (LM layer), [`client/src/protocol/types.ts`](https://github.com/nvidia/personaplex/blob/main/client/src/protocol/types.ts) (Protocol)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_client_app["App shell<br/>React entry<br/>[app.tsx]"]
  node_client_conversation["Conversation<br/>live UI<br/>[Conversation.tsx]"]
  node_client_socket["Socket state<br/>transport context<br/>[SocketContext.ts]"]
  node_client_media["Media state<br/>audio context<br/>[MediaContext.ts]"]
  node_client_hooks["Conversation hooks<br/>stream hooks"]
  node_client_audio["Audio worker<br/>real-time audio<br/>[audio-processor.ts]"]
  node_client_audio_ui["Audio views<br/>visualization"]
  node_client_text_ui["Text views<br/>display<br/>[TextDisplay.tsx]"]
  node_client_controls["Controls<br/>[Controls.tsx]"]
  node_client_queue["Queue page<br/>pre-chat flow<br/>[Queue.tsx]"]
  node_client_queue_api["Queue API<br/>browser api<br/>[client.ts]"]
end

subgraph group_server["Inference server"]
  node_server_entry["Live server<br/>python service<br/>[server.py]"]
  node_server_offline["Offline replay<br/>batch runner<br/>[offline.py]"]
  node_server_conn["Connection utils<br/>session transport<br/>[connection.py]"]
  node_server_client_utils["Client helpers<br/>integration helpers<br/>[client_utils.py]"]
end

subgraph group_model["Model core"]
  node_model_lm["LM layer<br/>model orchestration<br/>[lm.py]"]
  node_model_compression["Compression<br/>audio tokens<br/>[compression.py]"]
  node_model_quant["Quantization<br/>vq stack<br/>[vq.py]"]
  node_model_modules["Modules<br/>core blocks<br/>[transformer.py]"]
end

subgraph group_protocol["Wire protocol"]
  node_protocol["Protocol<br/>wire format<br/>[types.ts]"]
end

subgraph group_ops["Packaging"]
  node_ops_docker["Deploy<br/>containers"]
end

node_client_app -->|"routes to"| node_client_conversation
node_client_app -->|"routes to"| node_client_queue
node_client_conversation -->|"uses"| node_client_socket
node_client_conversation -->|"uses"| node_client_media
node_client_conversation -->|"uses"| node_client_hooks
node_client_conversation -->|"renders"| node_client_audio_ui
node_client_conversation -->|"renders"| node_client_text_ui
node_client_conversation -->|"renders"| node_client_controls
node_client_hooks -->|"streams through"| node_client_audio
node_client_hooks -->|"encodes"| node_protocol
node_client_queue -->|"calls"| node_client_queue_api
node_client_queue_api -.->|"shares contract"| node_protocol
node_protocol -->|"speaks to"| node_server_entry
node_server_entry -->|"manages"| node_server_conn
node_server_entry -->|"integrates"| node_server_client_utils
node_server_entry -->|"runs"| node_model_lm
node_server_offline -->|"reuses"| node_model_lm
node_model_lm -->|"consumes"| node_model_compression
node_model_compression -->|"uses"| node_model_quant
node_model_lm -->|"builds from"| node_model_modules
node_server_entry -->|"emits"| node_protocol
node_server_offline -.->|"packages with"| node_ops_docker

click node_client_app "https://github.com/nvidia/personaplex/blob/main/client/src/app.tsx"
click node_client_conversation "https://github.com/nvidia/personaplex/blob/main/client/src/pages/Conversation/Conversation.tsx"
click node_client_socket "https://github.com/nvidia/personaplex/blob/main/client/src/pages/Conversation/SocketContext.ts"
click node_client_media "https://github.com/nvidia/personaplex/blob/main/client/src/pages/Conversation/MediaContext.ts"
click node_client_hooks "https://github.com/nvidia/personaplex/tree/main/client/src/pages/Conversation/hooks"
click node_client_audio "https://github.com/nvidia/personaplex/blob/main/client/src/audio-processor.ts"
click node_client_audio_ui "https://github.com/nvidia/personaplex/blob/main/client/src/pages/Conversation/components/AudioVisualizer/AudioVisualizer.tsx"
click node_client_text_ui "https://github.com/nvidia/personaplex/blob/main/client/src/pages/Conversation/components/TextDisplay/TextDisplay.tsx"
click node_client_controls "https://github.com/nvidia/personaplex/blob/main/client/src/pages/Conversation/components/Controls/Controls.tsx"
click node_client_queue "https://github.com/nvidia/personaplex/blob/main/client/src/pages/Queue/Queue.tsx"
click node_client_queue_api "https://github.com/nvidia/personaplex/blob/main/client/src/pages/Queue/api/client.ts"
click node_protocol "https://github.com/nvidia/personaplex/blob/main/client/src/protocol/types.ts"
click node_server_entry "https://github.com/nvidia/personaplex/blob/main/moshi/moshi/server.py"
click node_server_offline "https://github.com/nvidia/personaplex/blob/main/moshi/moshi/offline.py"
click node_server_conn "https://github.com/nvidia/personaplex/blob/main/moshi/moshi/utils/connection.py"
click node_server_client_utils "https://github.com/nvidia/personaplex/blob/main/moshi/moshi/client_utils.py"
click node_model_lm "https://github.com/nvidia/personaplex/blob/main/moshi/moshi/models/lm.py"
click node_model_compression "https://github.com/nvidia/personaplex/blob/main/moshi/moshi/models/compression.py"
click node_model_quant "https://github.com/nvidia/personaplex/blob/main/moshi/moshi/quantization/vq.py"
click node_model_modules "https://github.com/nvidia/personaplex/blob/main/moshi/moshi/modules/transformer.py"
click node_ops_docker "https://github.com/nvidia/personaplex/blob/main/docker-compose.yaml"

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_client_app,node_client_conversation,node_client_socket,node_client_media,node_client_hooks,node_client_audio,node_client_audio_ui,node_client_text_ui,node_client_controls,node_client_queue,node_client_queue_api toneBlue
class node_server_entry,node_server_offline,node_server_conn,node_server_client_utils toneAmber
class node_model_lm,node_model_compression,node_model_quant,node_model_modules toneMint
class node_protocol toneRose
class node_ops_docker toneIndigo
```

## Components

### Browser client

Vite + React UI for live conversation and queue intake.

- [App shell](https://github.com/nvidia/personaplex/blob/main/client/src/app.tsx): React entry · Top-level browser app wiring routes and global UI. · `client/src/app.tsx`
- [Conversation](https://github.com/nvidia/personaplex/blob/main/client/src/pages/Conversation/Conversation.tsx): live UI · Main duplex conversation screen for microphone, playback, transcript, and controls. · `client/src/pages/Conversation/Conversation.tsx`
- [Socket state](https://github.com/nvidia/personaplex/blob/main/client/src/pages/Conversation/SocketContext.ts): transport context · Conversation socket boundary and session state. · `client/src/pages/Conversation/SocketContext.ts`
- [Media state](https://github.com/nvidia/personaplex/blob/main/client/src/pages/Conversation/MediaContext.ts): audio context · Client-side media capture and playback state. · `client/src/pages/Conversation/MediaContext.ts`
- [Conversation hooks](https://github.com/nvidia/personaplex/tree/main/client/src/pages/Conversation/hooks): stream hooks · Mic input, server audio, server text, model params, and connection hooks. · `client/src/pages/Conversation/hooks`
- [Audio worker](https://github.com/nvidia/personaplex/blob/main/client/src/audio-processor.ts): real-time audio · Audio processor and decoder worker for off-main-thread handling. · `client/src/audio-processor.ts`
- [Audio views](https://github.com/nvidia/personaplex/blob/main/client/src/pages/Conversation/components/AudioVisualizer/AudioVisualizer.tsx): visualization · User and server audio visualizers plus stats panels. · `client/src/pages/Conversation/components/AudioVisualizer/AudioVisualizer.tsx`
- [Text views](https://github.com/nvidia/personaplex/blob/main/client/src/pages/Conversation/components/TextDisplay/TextDisplay.tsx): display · Transcript, server info, and text status components. · `client/src/pages/Conversation/components/TextDisplay/TextDisplay.tsx`
- [Controls](https://github.com/nvidia/personaplex/blob/main/client/src/pages/Conversation/components/Controls/Controls.tsx): model controls · Conversation controls and model parameter UI. · `client/src/pages/Conversation/components/Controls/Controls.tsx`
- [Queue page](https://github.com/nvidia/personaplex/blob/main/client/src/pages/Queue/Queue.tsx): pre-chat flow · Email intake and pre-conversation entry flow. · `client/src/pages/Queue/Queue.tsx`
- [Queue API](https://github.com/nvidia/personaplex/blob/main/client/src/pages/Queue/api/client.ts): browser api · Queue backend client, validation, and error handling. · `client/src/pages/Queue/api/client.ts`

### Inference server

Python runtime that handles live sessions and offline replay.

- [Live server](https://github.com/nvidia/personaplex/blob/main/moshi/moshi/server.py): python service · Real-time conversational inference entry point with browser session handling. · `moshi/moshi/server.py`
- [Offline replay](https://github.com/nvidia/personaplex/blob/main/moshi/moshi/offline.py): batch runner · File-based replay mode for evaluation and artifact generation. · `moshi/moshi/offline.py`
- [Connection utils](https://github.com/nvidia/personaplex/blob/main/moshi/moshi/utils/connection.py): session transport · Persistent client session coordination and stream management. · `moshi/moshi/utils/connection.py`
- [Client helpers](https://github.com/nvidia/personaplex/blob/main/moshi/moshi/client_utils.py): integration helpers · Browser-facing integration helpers separated from model code. · `moshi/moshi/client_utils.py`

### Model core

Compression, quantization, transformer, and audio modules.

- [LM layer](https://github.com/nvidia/personaplex/blob/main/moshi/moshi/models/lm.py): model orchestration · Model-facing loading and language-model orchestration. · `moshi/moshi/models/lm.py`
- [Compression](https://github.com/nvidia/personaplex/blob/main/moshi/moshi/models/compression.py): audio tokens · Audio compression and representation layer feeding the model. · `moshi/moshi/models/compression.py`
- [Quantization](https://github.com/nvidia/personaplex/blob/main/moshi/moshi/quantization/vq.py): vq stack · Vector quantization and codebook handling for compressed audio tokens. · `moshi/moshi/quantization/vq.py`
- [Modules](https://github.com/nvidia/personaplex/blob/main/moshi/moshi/modules/transformer.py): core blocks · Transformer, streaming, convolution, resampling, RoPE, gating, and SEANet blocks. · `moshi/moshi/modules/transformer.py`

### Wire protocol

Explicit client/server message format and encoding.

- [Protocol](https://github.com/nvidia/personaplex/blob/main/client/src/protocol/types.ts): wire format · Shared encoder and message types for browser/server exchange. · `client/src/protocol/types.ts`

### Packaging

Container and compose assets for local deployment.

- [Deploy](https://github.com/nvidia/personaplex/blob/main/docker-compose.yaml): containers · Dockerfiles and compose setup for local packaging and runtime wiring. · `docker-compose.yaml`

## Connections

- App shell → Conversation: routes to · Primary browser experience is the live conversation screen.
- App shell → Queue page: routes to · Secondary browser flow handles pre-chat intake.
- Conversation → Socket state: uses · Conversation page binds to socket session state.
- Conversation → Media state: uses · Conversation page binds to media capture and playback state.
- Conversation → Conversation hooks: uses · Conversation page coordinates streaming hooks.
- Conversation → Audio views: renders · Conversation page visualizes user and server audio.
- Conversation → Text views: renders · Conversation page shows transcript, status, and server info.
- Conversation → Controls: renders · Conversation page exposes runtime controls and parameters.
- Conversation hooks → Audio worker: streams through · Mic capture and decoded audio are processed off the main thread.
- Conversation hooks → Protocol: encodes · Conversation hooks serialize and parse streamed messages.
- Queue page → Queue API: calls · Queue UI submits intake data through a small API client.
- Queue API → Protocol: shares contract · Browser data exchange uses explicit message and validation shapes.
- Protocol → Live server: speaks to · Wire format defines browser/server conversation messages.
- Live server → Connection utils: manages · Live service coordinates persistent sessions and streams.
- Live server → Client helpers: integrates · Browser-facing helpers keep transport concerns separate.
- Live server → LM layer: runs · Live service invokes the model inference stack.
- Offline replay → LM layer: reuses · Batch replay uses the same inference core as live mode.
- LM layer → Compression: consumes · Model layer operates on compressed audio representations.
- Compression → Quantization: uses · Compression relies on vector quantization and codebooks.
- LM layer → Modules: builds from · Core model is assembled from transformer and audio blocks.
- Live server → Protocol: emits · Server produces text and audio turn events for the browser.
- Offline replay → Deploy: packages with · Deployment assets support both live and offline execution.
