Data Flow
Understanding how data flows through SmarterAvatar helps with debugging, optimization, and customization.
User Interaction Flow
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ User │────▶│ Client │────▶│ API │────▶│Providers │
│ Input │ │ App │ │ Layer │ │ │
└──────────┘ └──────────┘ └──────────┘ └──────────┘
│ │ │
│ │ │
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Local │ │ Database │ │ External │
│ State │ │(Postgres)│ │ APIs │
└──────────┘ └──────────┘ └──────────┘
Voice Input Flow
When a user speaks:
- Browser captures audio via Web Audio API
- Client sends audio to
/api/transcribeendpoint - STT Provider (Whisper/Deepgram) transcribes audio to text
- Text is processed same as typed input
- Transcript is logged to database (if enabled)
[Microphone] → [Audio Buffer] → [STT API] → [Text] → [Chat Processing]
Chat Processing Flow
For each user message:
- Message received at
/api/chatendpoint - RAG retrieval searches knowledge base for context
- Prompt construction combines system prompt + context + user message
- LLM inference generates response
- Response logged to database
- Response sent to avatar for synthesis
[User Message]
│
▼
[RAG Retrieval] ──▶ [Relevant Documents]
│ │
▼ ▼
[System Prompt] + [Context] + [User Message]
│
▼
[LLM Provider] ──▶ [Generated Response]
│
▼
[Avatar Provider] ──▶ [Video Stream]
Avatar Synthesis Flow
The avatar rendering uses a hybrid approach:
- Session created via server-side API (secure)
- Token issued to client
- Client SDK connects directly to HeyGen
- Text sent for synthesis
- Video streams back to client
[Server] [Client] [HeyGen]
│ │ │
│──── Create Session ────────────▶│ │
│◀─── Session Token ──────────────│ │
│ │ │
│ │──── Connect with Token ──────▶│
│ │◀─── WebSocket Established ────│
│ │ │
│──── Send Response Text ────────▶│──── Synthesize ─────────────▶│
│ │◀─── Video Stream ─────────────│
Knowledge Base Flow
Documents are processed asynchronously:
- Upload via Admin → File saved to storage
- Processing triggered → File parsed and chunked
- Embeddings generated → Vectors created for each chunk
- Index updated → Ready for retrieval
[Document Upload] → [Parser] → [Chunker] → [Embedder] → [Vector Store]
│
▼
[RAG Retrieval]
Analytics Flow
Session data is captured throughout:
[Session Start] ──▶ [Conversation] ──▶ [Session End]
│ │ │
▼ ▼ ▼
[Start Time] [Messages] [Duration]
[IP Address] [Topics] [Email (opt)]
[User Agent] [Citations] [Feedback]
│
▼
[Database Storage]
│
▼
[Admin Dashboard]
Security Considerations
- API keys never exposed to client
- Session tokens are short-lived and scoped
- Database contains no sensitive credentials
- Audio is processed but not stored (unless configured)
- Analytics can be configured for privacy compliance