Repository navigation
Architecture Event System
The Event System manages how user inputs (clicks, keypresses) and network events (WebSocket messages) propagate through the frontend application to update the UI.
In standard React, updating state high in the component tree causes the entire application to re-render. In a 3D application, doing this 60 times a second will cause massive stuttering. The Event System decouples state updates from React renders wherever possible.
TokenPrint utilizes Zustand (lib/store.ts) as a centralized event bus and state manager.
State that updates constantly (like activeOp during Live Inference playback) is stored in Zustand. R3F components use the useStore.getState() pattern inside their useFrame loops to read this data without triggering a React render.
State that dictates the UI layout (like appMode or sidebarOpen) is hooked into React components normally via useStore(state => state.appMode).
Keyboard shortcuts (handled in lib/useKeyboard.ts) bypass React entirely, listening directly on the window object and dispatching actions straight to the Zustand store.
flowchart TD
subgraph Inputs
WS[WebSocket Frame]
Key[Keyboard Event]
Mouse[Mouse Click]
end
Inputs --> Action[Dispatch Action]
Action --> Zustand[Zustand Store]
subgraph Consumers
Zustand -.->|State Hook| UI[React UI updates]
Zustand -.->|Transient Read| R3F[useFrame: WebGL updates]
end
| Previous | Home | Next |
|---|---|---|
| Renderer | Home | Developer Guide |
TokenPrint Wiki | Home | Getting Started | User Guide | Concepts | Architecture | API | GitHub
TokenPrint is an interactive 3D visualization platform for exploring transformer architectures, tensors, and real-time LLM inference.
- User Guide
- Architecture Explorer
- Live Inference
- Tensor Inspector
- Camera Controls
- HUD
- Timeline
- Scene Navigation
- Transformer Concepts
- Tokenization
- Embeddings
- Positional Encoding
- RoPE
- Multi-Head Attention
- KV Cache
- LayerNorm
- Feed Forward Network
- Residual Connections
- Logits
- Softmax
- Sampling
- Autoregressive Generation
- Visualization System
- Scene Graph
- Geometry
- Materials
- Animation System
- Color Mapping
- Camera System
- Interaction Model
- Architecture
- Overall Architecture
- Frontend
- Backend
- WebSocket Protocol
- Data Pipeline
- Renderer
- Event System