How aashuthosh10/clara-launch works
1. System shape
- CLARA is a two-process full-stack kiosk app: a React/Vite frontend for the conversational UI and a FastAPI backend that exposes the main conversation endpoint over WebSocket (/ws/clara).
- The frontend is the interactive shell; the backend owns conversation state, language decisions, speech/LLM orchestration, and retrieval.
2. Frontend boundary
- The frontend lives under frontend/ and is built with React 19 + TypeScript + Vite.
- Its primary runtime flow is: screen selection → websocket connection → voice/chat turn handling → UI rendering of replies/cards/visual effects.
- Key integration points are src/hooks/useWebSocket.ts, useSpeechRecognition.ts, useVoiceAnalyser.ts, and the main screen components in src/screens/.
3. Frontend conversation UI
- ChatScreen.tsx, VoiceConversation.tsx, VoiceOrb*, and VoiceWaveformVisualizer.tsx are the main conversation surface for the kiosk.
- The chat layer is not just text: it renders specialized content cards such as department cards, HOD cards, leadership overviews, course menus, and image cards, which means the backend response can drive richer UI states than plain messages.
4. Frontend language and content model
- Localized strings exist in frontend/src/data/locales/*.json, and LanguageContext.tsx keeps the selected language in the UI.
- Frontend helper libs like intentClassifier.ts, intentNormalizer.ts, and parseOverviewReply.ts suggest the client also interprets backend replies into display intents for card-heavy responses.
5. Backend application boundary
- The backend lives under backend/ and is structured around a FastAPI app in backend/app/main.py, with a compatibility entrypoint in backend/main.py.
- The backend is divided into clear layers: app/ for app entry/flow, core/ for pipeline logic, services/ for business rules, clients/ for external integrations, and config/ for settings.
6. Conversation pipeline on the backend
- The central flow is audio/text input arriving via WebSocket, then passing through language detection, session language management, retrieval-augmented generation, answer generation, and optionally text-to-speech for spoken replies.
- core/audio_pipeline.py, core/stt.py, core/language_detection.py, core/rag.py, and services/answer_generation.py are the main orchestration pieces for a turn.
7. Session and language behavior
- Language is a first-class state dimension. services/session_language.py persists the chosen language for the session, while core/language_detection.py can auto-detect the first meaningful transcript when enabled.
- Supported languages are English, Hindi, Kannada, Tamil, Telugu, and Malayalam; the README indicates manual selection overrides auto-detection for the session.
8. AI, speech, and external provider boundary
- backend/clients/provider_clients.py is the likely abstraction layer for external AI/speech providers such as Groq for LLM replies and Sarvam for ASR/TTS.
- This means the backend isolates vendor-specific calls behind a client layer instead of letting UI or core logic talk to providers directly.
9. RAG and persistent knowledge
- The knowledge base is ingested from college_knowledge.txt into PostgreSQL with pgvector, using scripts under backend/tools/ and backend/ingest_college_knowledge_pg.py.
- core/rag.py, clients/database.py, and core/db.py form the persistence/retrieval boundary for college facts, so the answer generator can mix live model output with retrieved institutional data.
10. Runtime configuration and dependencies
- Runtime settings come from .env via backend/config/settings.py, with required secrets for API providers and PostgreSQL.
- The repo includes multiple backend requirement sets (minimal, no-dlib, voice, full) showing that voice support is modular and can be deployed in reduced-capability environments.
11. Observability and performance
- The backend has explicit latency instrumentation and voice debug hooks in utils/timing.py, utils/voice_logger.py, and the latency tooling under backend/tools/.
- The system measures turn-level metrics like STT, LLM, TTS, and total latency, which is important for a kiosk UX where response time matters.
12. Operational and deployment boundaries
- docker-compose.yml, scripts/db/init_pgvector.sql, and the launch scripts indicate the repo expects local or containerized bring-up with a separate Postgres service.
- The frontend can be pointed at different backend websocket URLs via environment config, so frontend and backend are intentionally decoupled at runtime.
13. What to show in an architecture diagram
- Draw the frontend as a client shell with voice capture, websocket transport, and rich response rendering.
- Draw the backend as a conversation orchestrator with a single websocket entrypoint, then split it into STT/language detection, session state, RAG/Postgres, answer generation, and TTS/provider adapters.
- Include PostgreSQL/pgvector as the persistent knowledge subsystem and external LLM/TTS services as outbound dependencies of the backend, not the frontend.
Main entry points: audio_pipeline.py Audio pipeline · database.py DB clients · ChatScreen.tsx Chat screen · useWebSocket.ts WebSocket
Components 23
Frontend
React/Vite kiosk client for voice and chat interaction.
- App shell · Top-level client entry and screen routing for the kiosk UI.
frontend/src/App.tsx - WebSocket · Manages the live conversation connection to the backend.
frontend/src/hooks/useWebSocket.ts - Voice input · Captures microphone input and voice activity for conversational turns.
frontend/src/hooks/useSpeechRecognition.ts - Voice analyser · Measures audio levels for voice feedback and visualization.
frontend/src/hooks/useVoiceAnalyser.ts - Chat screen · Primary chat-and-card surface for the kiosk experience.
frontend/src/screens/ChatScreen.tsx - Language UI · Tracks selected UI language and localized strings.
frontend/src/context/LanguageContext.tsx - Rich cards · Department, HOD, course, leadership, and image card components.
frontend/src/components/chat/CardMessage.tsx - Voice orb · Animated voice conversation surfaces and waveform feedback.
frontend/src/components/VoiceOrb.tsx - Intent parsing · Normalizes backend replies into display intents and overview states.
frontend/src/lib/intentClassifier.ts
Backend
FastAPI conversation service and orchestration layers.
- WS endpoint · Single websocket entrypoint for conversation turns.
backend/app/main.py - Audio pipeline · Coordinates websocket turn handling across speech, language, retrieval, and reply generation.
backend/core/audio_pipeline.py - Speech-to-text · Converts voice input into transcript text.
backend/core/stt.py - Language state · Detects or persists the active session language.
backend/core/language_detection.py - Session language · Stores the selected language for the conversation session.
backend/services/session_language.py - RAG layer · Retrieves college facts from vector-backed storage for grounded answers.
backend/core/rag.py - Answer generation · Builds final text replies from the conversation context and retrieved knowledge.
backend/services/answer_generation.py - Provider adapters · Abstracts outbound AI, speech, and vendor integrations.
backend/clients/provider_clients.py - DB clients · Database access layer for pgvector-backed knowledge and retrieval.
backend/clients/database.py - Settings · Loads environment-driven configuration for providers, language, and database access.
backend/config/settings.py
Data
Persistent knowledge and locale assets.
- PostgreSQL · Persistent college knowledge and embedding-backed retrieval store.
scripts/db/init_pgvector.sql - Knowledge base · Institutional facts ingested into the retrieval store.
college_knowledge.txt - Locales · Localized text resources for supported UI and backend languages.
frontend/src/data/locales/en.json
Ops
Containerization, scripts, and deployment support.
- Compose setup · Containerized local bring-up for app and database services.
docker-compose.yml
Connections 23
- App shell → WebSocket: opens turn stream · The client shell initializes the live conversation channel.
- App shell → Chat screen: renders · Main app routes users into the chat conversation screen.
- Chat screen → Rich cards: shows responses · Chat responses can render specialized cards and overviews.
- Chat screen → Voice orb: voice UI · Conversation screen includes voice-centric animated controls.
- Voice input → WebSocket: sends audio · Captured speech is forwarded through the websocket flow.
- Voice analyser → Voice orb: drives visuals · Audio levels animate the voice interface.
- Language UI → Locales: loads strings · Selected language determines localized UI content.
- Intent parsing → Rich cards: maps replies · Parsed intent determines which card surface to display.
- WebSocket → WS endpoint: ws /ws/clara · Primary client-server conversation transport.
- WS endpoint → Audio pipeline: routes turns · WebSocket handler hands each exchange to the turn pipeline.
- Audio pipeline → Speech-to-text: transcribes · Voice turns are converted into text for downstream processing.
- Audio pipeline → Language state: detects language · Pipeline can infer the first meaningful transcript language.
- Audio pipeline → Session language: persists language · Chosen language is stored for the active session.
- Audio pipeline → RAG layer: retrieves facts · Relevant institutional context is fetched before answering.
- Audio pipeline → Answer generation: generates reply · Pipeline assembles the final conversational response.
- Answer generation → Provider adapters: calls providers · Answer generation delegates to external model and speech providers.
- RAG layer → DB clients: queries store · Retrieval uses the database access layer.
- DB clients → PostgreSQL: vector search · Knowledge retrieval operates over pgvector-backed PostgreSQL.
- DB clients → Knowledge base: ingests corpus · Source knowledge is loaded into persistent storage.
- Settings → Provider adapters: provider settings · Runtime secrets and endpoints configure external integrations.
- Settings → DB clients: db settings · Database connection parameters come from environment configuration.
- Compose setup → PostgreSQL: starts service · Compose setup provides the database runtime.
- Compose setup → WS endpoint: runs backend · Containerized launch brings up the API service.