You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+
## Development commands
6
+
7
+
- Install dependencies: `npm install`
8
+
- Start dev server: `npm run dev`
9
+
- Production build: `npm run build`
10
+
- Alternate builds:
11
+
-`npm run build:mobile`
12
+
-`npm run build:desktop`
13
+
-`npm run build:ar`
14
+
- Preview production build locally: `npm run preview`
15
+
- Serve preview on `0.0.0.0:3000`: `npm run serve`
16
+
- Lint: `npm run lint`
17
+
- Run tests in watch mode: `npm test`
18
+
- Run tests once: `npm run test:run`
19
+
- Run coverage: `npm run test:coverage`
20
+
- Run a single test file: `npx vitest run src/__tests__/digitalHuman.test.tsx`
21
+
- Run tests matching a name: `npx vitest run -t "test name"`
22
+
23
+
## Stack and build setup
24
+
25
+
- React 18 + TypeScript app built with Vite.
26
+
- Path alias `@/*` points to `src/*` in both Vite and Vitest configs.
27
+
- Tailwind CSS is used for UI styling; dark-mode class support is enabled in `tailwind.config.js`.
28
+
- Vitest uses the `jsdom` environment with setup from `src/__tests__/setup.ts`.
29
+
- Vite build modes `mobile`, `desktop`, and `ar` only change compile-time flags (`__MOBILE__`, `__DESKTOP__`, `__AR__`) and output directories (`dist-mobile`, `dist-desktop`, `dist-ar`).
30
+
31
+
## High-level architecture
32
+
33
+
### App shell and routing
34
+
35
+
- Entry point is `src/main.tsx`, which renders `src/App.tsx`.
36
+
-`src/App.tsx` sets up React Router with lazy-loaded pages:
37
+
-`/` and `/advanced` -> `AdvancedDigitalHumanPage`
38
+
-`/digital-human` -> `DigitalHumanPage`
39
+
- The app is wrapped in a global `ErrorBoundary` and Suspense fallback UI.
40
+
41
+
### Two page modes
42
+
43
+
-`src/pages/AdvancedDigitalHumanPage.tsx` is the main experience and the default route. It combines:
44
+
- full-screen 3D viewer background
45
+
- settings drawer with tabs for basic controls, expressions, behavior, vision, and voice
46
+
- chat/session UI
47
+
- server health checks and reconnect flow
48
+
- keyboard shortcuts and toast-driven status feedback
49
+
-`src/pages/DigitalHumanPage.tsx` is a simpler demo page with the viewer plus a basic control panel.
50
+
51
+
### Central state model
52
+
53
+
-`src/store/digitalHumanStore.ts` is the central Zustand store for nearly all runtime state.
54
+
- It holds playback, recording, mute, speaking, expression/emotion, behavior, connection status, loading/error state, and chat/session history.
55
+
- Session IDs are persisted in `localStorage` under `metahuman_session_id`, with SSR-safe storage access.
56
+
- Core services and pages commonly read/write state directly via `useDigitalHumanStore.getState()` rather than passing state deeply through props.
57
+
58
+
### Core runtime layers
59
+
60
+
The app is organized around `src/core/*` services:
61
+
62
+
-`src/core/avatar/DigitalHumanEngine.ts`
63
+
- imperative façade over the Zustand store
64
+
- translates high-level actions like `play`, `reset`, `setEmotion`, `setBehavior`, `playAnimation` into store updates
65
+
- contains emotion -> expression mapping and timed auto-reset for animations
66
+
-`src/core/audio/audioService.ts`
67
+
- browser-only audio integration using Web Speech APIs
68
+
-`TTSService` drives speech synthesis and updates speaking/behavior store state
69
+
-`ASRService` wraps speech recognition, handles command mode vs dictation mode, and can forward transcripts into dialogue handling
70
+
-`src/core/dialogue/dialogueService.ts`
71
+
- HTTP client for backend chat requests
72
+
- sends requests to `${VITE_API_BASE_URL || 'http://localhost:8000'}/v1/chat`
73
+
- checks `${baseUrl}/health` for connectivity
74
+
- includes timeout handling, retry logic for retryable failures, friendly error messages, and a local fallback reply when backend calls fail
75
+
-`src/core/dialogue/dialogueOrchestrator.ts`
76
+
- orchestrates a full dialogue turn
77
+
- appends user/assistant messages to store history
78
+
- toggles loading/thinking state
79
+
- applies backend response emotion/action to the avatar engine
80
+
- optionally invokes TTS for spoken replies
81
+
-`src/core/vision/visionService.ts`
82
+
- camera + MediaPipe integration for face/pose analysis
83
+
- dynamically imports `@mediapipe/face_mesh` and `@mediapipe/pose`
84
+
- maps face landmarks to emotion and derives motions like nod/shake/raiseHand/waveHand
85
+
- model files are loaded from jsDelivr CDN at runtime, so vision features depend on camera permission and network access
86
+
-`src/core/vision/visionMapper.ts`
87
+
- converts raw face landmarks into the app’s higher-level emotion model
88
+
89
+
### UI/component structure
90
+
91
+
-`src/components/DigitalHumanViewer.tsx` is the 3D rendering boundary.
92
+
- Uses React Three Fiber + Drei.
93
+
- If `modelUrl` loads successfully, it renders the GLTF scene.
94
+
- If loading fails or no model is supplied, it falls back to an internal procedural “CyberAvatar”.
95
+
- Viewer behavior is driven from store state (`currentExpression`, `isSpeaking`, `currentAnimation`, `expressionIntensity`).
96
+
- Control panels (`ControlPanel`, `ExpressionControlPanel`, `BehaviorControlPanel`, `VoiceInteractionPanel`, `VisionMirrorPanel`) are mostly thin UI layers that call into the engine/services.
97
+
- Shared UI primitives live under `src/components/ui`.
98
+
99
+
## Backend/API assumptions
100
+
101
+
- The frontend expects a separate backend service at `VITE_API_BASE_URL` or `http://localhost:8000`.
102
+
- Chat response shape expected by the frontend:
103
+
-`replyText: string`
104
+
-`emotion: string`
105
+
-`action: string`
106
+
- Health endpoint expected: `GET /health`
107
+
- Chat endpoint expected: `POST /v1/chat`
108
+
109
+
## Testing notes
110
+
111
+
- Current test coverage is centered in `src/__tests__/digitalHuman.test.tsx`.
112
+
- Tests heavily mock Three.js, React Three Fiber, and browser speech APIs; follow that pattern when adding UI/runtime tests for viewer or audio behavior.
113
+
- Because the app relies on browser APIs (speech synthesis, speech recognition, camera/media devices), new tests usually need mocks rather than real integrations.
114
+
115
+
## Practical implementation notes
116
+
117
+
- Prefer modifying the advanced page flow unless the task is explicitly about the simpler `/digital-human` demo.
118
+
- For behavior changes affecting avatar reactions, inspect the interaction between:
119
+
-`src/store/digitalHumanStore.ts`
120
+
-`src/core/avatar/DigitalHumanEngine.ts`
121
+
-`src/core/dialogue/dialogueOrchestrator.ts`
122
+
-`src/components/DigitalHumanViewer.tsx`
123
+
- For backend chat issues, check both `dialogueService.ts` retry/fallback behavior and `AdvancedDigitalHumanPage.tsx` health-check/reconnect UI.
124
+
- For speech features, verify whether logic belongs in browser service wrappers (`audioService.ts`) or page-level orchestration.
0 commit comments