# zoan37/chatvrm architecture

> Architecture diagram of the GitHub repository zoan37/chatvrm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zoan37/chatvrm
- Repository: https://github.com/zoan37/chatvrm

## Overview

##### Main Components

Frontend Layer:
- React/Next.js Application (src/pages)
- VRM Viewer Components (src/components/vrmViewer.tsx)
- Chat Interface Components (src/components/chatLog.tsx, messageInput.tsx)
- Settings Interface (src/components/settings.tsx)

Core Features Layer:
- VRM Animation System (src/lib/VRMAnimation)
- Emote Controller (src/features/emoteController)
- Lip Sync System (src/features/lipSync)
- Message Processing System (src/features/messages)

External Services Layer:
- OpenRouter API (AI Chat)
- ElevenLabs API (Text-to-Speech)
- Web Speech API (Speech Recognition)
- Restream API (Livestream Integration)
- Vercel (Deployment Platform)

##### Component Relationships

**User Input → Frontend Components → Message Processing → External APIs → Character Response**
- ↓
- VRM Animation/Lip Sync/Emote Control

##### Specific Implementation Details

a) Frontend System (Blue):
- Next.js Pages
- React Components
- WebGL Viewer

b) Character Control System (Green):
- VRM Animation Controller
- Expression Controller
- Lip Sync Controller
- Auto Blink/Look At

c) Communication System (Yellow):
- WebSocket Service
- Token Refresh Service
- Message Processing
- API Routes

d) External Services (Purple):
- OpenRouter
- ElevenLabs
- Web Speech API
- Restream

- User Input → Speech Recognition → Text Processing
- Text → OpenRouter → Response Generation
- Response → ElevenLabs → Audio Generation
- Audio → Lip Sync → Character Animation
- Restream → WebSocket → Message Processing

##### Architecture Patterns

- Feature-based architecture (src/features)
- Service-based communication (src/services)
- Component-based UI (src/components)
- API Routes for backend functionality

##### The modular architecture allowing for easy extension

Keep the abstraction level high enough to understand the system at a glance but detailed enough to show the unique aspects of the VRM character interaction and AI integration.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI[User Interface]
        VV[VRM Viewer]:::component
        CI[Chat Interface]:::component
        SI[Settings Interface]:::component
        RT[Restream Tokens]:::component
    end

    subgraph Core_Features
        VAS[VRM Animation System]:::component
        EC[Emote Controller]:::component
        LSS[Lip Sync System]:::component
        MPS[Message Processing]:::component
        VC[VRM Viewer Core]:::component
    end

    subgraph External_Services
        OR[OpenRouter API]:::component
        EL[ElevenLabs API]:::component
        WSA[Web Speech API]
        RS[Restream Service]
    end

    subgraph Real_Time_Services
        WS[WebSocket Service]:::component
        TRS[Token Refresh Service]:::component
    end

    subgraph API_Routes
        CR["/api/chat"]:::component
        TR["/api/refresh-token"]:::component
        TTS["/api/tts"]:::component
    end

    UI --> CI
    UI --> VV
    UI --> SI
    UI --> RT

    CI --> MPS
    MPS --> OR
    OR --> MPS
    MPS --> EL
    EL --> LSS
    LSS --> VAS
    VAS --> VV
    EC --> VV
    VC --> VV

    WS --> MPS
    RS --> WS
    TRS --> CR
    TRS --> TR
    TRS --> TTS

    classDef component fill:#f9f,stroke:#333,stroke-width:2px
    classDef api fill:#69f,stroke:#333,stroke-width:2px

    click VV "https://github.com/zoan37/ChatVRM/blob/main/src/components/vrmViewer.tsx"
    click CI "https://github.com/zoan37/ChatVRM/blob/main/src/components/chatLog.tsx"
    click SI "https://github.com/zoan37/ChatVRM/blob/main/src/components/settings.tsx"
    click RT "https://github.com/zoan37/ChatVRM/blob/main/src/components/restreamTokens.tsx"
    click VAS "https://github.com/zoan37/ChatVRM/tree/main/src/lib/VRMAnimation"
    click EC "https://github.com/zoan37/ChatVRM/tree/main/src/features/emoteController"
    click LSS "https://github.com/zoan37/ChatVRM/tree/main/src/features/lipSync"
    click MPS "https://github.com/zoan37/ChatVRM/tree/main/src/features/messages"
    click OR "https://github.com/zoan37/ChatVRM/blob/main/src/features/chat/openAiChat.ts"
    click EL "https://github.com/zoan37/ChatVRM/blob/main/src/features/elevenlabs/elevenlabs.ts"
    click WS "https://github.com/zoan37/ChatVRM/blob/main/src/services/websocketService.ts"
    click TRS "https://github.com/zoan37/ChatVRM/blob/main/src/services/tokenRefreshService.ts"
    click CR "https://github.com/zoan37/ChatVRM/blob/main/src/pages/api/chat.ts"
    click TR "https://github.com/zoan37/ChatVRM/blob/main/src/pages/api/refresh-token.ts"
    click TTS "https://github.com/zoan37/ChatVRM/blob/main/src/pages/api/tts.ts"
    click VC "https://github.com/zoan37/ChatVRM/tree/main/src/features/vrmViewer"
```
