# aashuthosh10/clara-launch architecture

> Architecture diagram of the GitHub repository aashuthosh10/clara-launch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aashuthosh10/clara-launch
- Repository: https://github.com/aashuthosh10/clara-launch

## Overview

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: [`backend/core/audio_pipeline.py`](https://github.com/aashuthosh10/clara-launch/blob/main/backend/core/audio_pipeline.py) (Audio pipeline), [`backend/clients/database.py`](https://github.com/aashuthosh10/clara-launch/blob/main/backend/clients/database.py) (DB clients), [`frontend/src/screens/ChatScreen.tsx`](https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/screens/ChatScreen.tsx) (Chat screen), [`frontend/src/hooks/useWebSocket.ts`](https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/hooks/useWebSocket.ts) (WebSocket)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["App shell<br/>React/Vite app<br/>[App.tsx]"]
  node_frontend_ws["WebSocket<br/>client transport<br/>[useWebSocket.ts]"]
  node_frontend_voice["Voice input<br/>speech hooks"]
  node_frontend_analyser(("Voice analyser<br/>audio hook"))
  node_frontend_chat["Chat screen<br/>conversation UI<br/>[ChatScreen.tsx]"]
  node_frontend_lang["Language UI<br/>locale state"]
  node_frontend_cards["Rich cards<br/>response renderers<br/>[CardMessage.tsx]"]
  node_frontend_orb(("Voice orb<br/>voice UI<br/>[VoiceOrb.tsx]"))
  node_frontend_intent["Intent parsing<br/>client reply parsing"]
end

subgraph group_backend["Backend"]
  node_backend_entry["WS endpoint<br/>FastAPI app<br/>[main.py]"]
  node_backend_flow["Audio pipeline<br/>turn orchestration<br/>[audio_pipeline.py]"]
  node_backend_stt["Speech-to-text<br/>ASR stage<br/>[stt.py]"]
  node_backend_lang["Language state<br/>language detection"]
  node_backend_session["Session language<br/>session service"]
  node_backend_rag["RAG layer<br/>retrieval<br/>[rag.py]"]
  node_backend_answer["Answer generation<br/>response service"]
  node_backend_clients["Provider adapters<br/>external client layer"]
  node_backend_db[("DB clients<br/>persistence clients<br/>[database.py]")]
  node_backend_config["Settings<br/>runtime config<br/>[settings.py]"]
end

subgraph group_data["Data"]
  node_postgres[("PostgreSQL<br/>pgvector store<br/>[init_pgvector.sql]")]
  node_college_knowledge["Knowledge base<br/>source corpus"]
  node_locales["Locales<br/>translation assets<br/>[en.json]"]
end

subgraph group_ops["Ops"]
  node_docker["Compose setup<br/>deployment<br/>[docker-compose.yml]"]
end

node_frontend_app -->|"opens turn stream"| node_frontend_ws
node_frontend_app -->|"renders"| node_frontend_chat
node_frontend_chat -->|"shows responses"| node_frontend_cards
node_frontend_chat -->|"voice UI"| node_frontend_orb
node_frontend_voice -->|"sends audio"| node_frontend_ws
node_frontend_analyser -->|"drives visuals"| node_frontend_orb
node_frontend_lang -->|"loads strings"| node_locales
node_frontend_intent -->|"maps replies"| node_frontend_cards
node_frontend_ws -->|"ws /ws/clara"| node_backend_entry
node_backend_entry -->|"routes turns"| node_backend_flow
node_backend_flow -->|"transcribes"| node_backend_stt
node_backend_flow -->|"detects language"| node_backend_lang
node_backend_flow -->|"persists language"| node_backend_session
node_backend_flow -->|"retrieves facts"| node_backend_rag
node_backend_flow -->|"generates reply"| node_backend_answer
node_backend_answer -->|"calls providers"| node_backend_clients
node_backend_rag -->|"queries store"| node_backend_db
node_backend_db -->|"vector search"| node_postgres
node_backend_db -->|"ingests corpus"| node_college_knowledge
node_backend_config -->|"provider settings"| node_backend_clients
node_backend_config -->|"db settings"| node_backend_db
node_docker -->|"starts service"| node_postgres
node_docker -->|"runs backend"| node_backend_entry

click node_frontend_app "https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/App.tsx"
click node_frontend_ws "https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/hooks/useWebSocket.ts"
click node_frontend_voice "https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/hooks/useSpeechRecognition.ts"
click node_frontend_analyser "https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/hooks/useVoiceAnalyser.ts"
click node_frontend_chat "https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/screens/ChatScreen.tsx"
click node_frontend_lang "https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/context/LanguageContext.tsx"
click node_frontend_cards "https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/components/chat/CardMessage.tsx"
click node_frontend_orb "https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/components/VoiceOrb.tsx"
click node_frontend_intent "https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/lib/intentClassifier.ts"
click node_backend_entry "https://github.com/aashuthosh10/clara-launch/blob/main/backend/app/main.py"
click node_backend_flow "https://github.com/aashuthosh10/clara-launch/blob/main/backend/core/audio_pipeline.py"
click node_backend_stt "https://github.com/aashuthosh10/clara-launch/blob/main/backend/core/stt.py"
click node_backend_lang "https://github.com/aashuthosh10/clara-launch/blob/main/backend/core/language_detection.py"
click node_backend_session "https://github.com/aashuthosh10/clara-launch/blob/main/backend/services/session_language.py"
click node_backend_rag "https://github.com/aashuthosh10/clara-launch/blob/main/backend/core/rag.py"
click node_backend_answer "https://github.com/aashuthosh10/clara-launch/blob/main/backend/services/answer_generation.py"
click node_backend_clients "https://github.com/aashuthosh10/clara-launch/blob/main/backend/clients/provider_clients.py"
click node_backend_db "https://github.com/aashuthosh10/clara-launch/blob/main/backend/clients/database.py"
click node_backend_config "https://github.com/aashuthosh10/clara-launch/blob/main/backend/config/settings.py"
click node_postgres "https://github.com/aashuthosh10/clara-launch/blob/main/scripts/db/init_pgvector.sql"
click node_college_knowledge "https://github.com/aashuthosh10/clara-launch/blob/main/college_knowledge.txt"
click node_locales "https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/data/locales/en.json"
click node_docker "https://github.com/aashuthosh10/clara-launch/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_app,node_frontend_ws,node_frontend_voice,node_frontend_analyser,node_frontend_chat,node_frontend_lang,node_frontend_cards,node_frontend_orb,node_frontend_intent toneBlue
class node_backend_entry,node_backend_flow,node_backend_stt,node_backend_lang,node_backend_session,node_backend_rag,node_backend_answer,node_backend_clients,node_backend_db,node_backend_config toneAmber
class node_postgres,node_college_knowledge,node_locales toneMint
class node_docker toneRose
```

## Components

### Frontend

React/Vite kiosk client for voice and chat interaction.

- [App shell](https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/App.tsx): React/Vite app · Top-level client entry and screen routing for the kiosk UI. · `frontend/src/App.tsx`
- [WebSocket](https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/hooks/useWebSocket.ts): client transport · Manages the live conversation connection to the backend. · `frontend/src/hooks/useWebSocket.ts`
- [Voice input](https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/hooks/useSpeechRecognition.ts): speech hooks · Captures microphone input and voice activity for conversational turns. · `frontend/src/hooks/useSpeechRecognition.ts`
- [Voice analyser](https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/hooks/useVoiceAnalyser.ts): audio hook · Measures audio levels for voice feedback and visualization. · `frontend/src/hooks/useVoiceAnalyser.ts`
- [Chat screen](https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/screens/ChatScreen.tsx): conversation UI · Primary chat-and-card surface for the kiosk experience. · `frontend/src/screens/ChatScreen.tsx`
- [Language UI](https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/context/LanguageContext.tsx): locale state · Tracks selected UI language and localized strings. · `frontend/src/context/LanguageContext.tsx`
- [Rich cards](https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/components/chat/CardMessage.tsx): response renderers · Department, HOD, course, leadership, and image card components. · `frontend/src/components/chat/CardMessage.tsx`
- [Voice orb](https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/components/VoiceOrb.tsx): voice UI · Animated voice conversation surfaces and waveform feedback. · `frontend/src/components/VoiceOrb.tsx`
- [Intent parsing](https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/lib/intentClassifier.ts): client reply parsing · Normalizes backend replies into display intents and overview states. · `frontend/src/lib/intentClassifier.ts`

### Backend

FastAPI conversation service and orchestration layers.

- [WS endpoint](https://github.com/aashuthosh10/clara-launch/blob/main/backend/app/main.py): FastAPI app · Single websocket entrypoint for conversation turns. · `backend/app/main.py`
- [Audio pipeline](https://github.com/aashuthosh10/clara-launch/blob/main/backend/core/audio_pipeline.py): turn orchestration · Coordinates websocket turn handling across speech, language, retrieval, and reply generation. · `backend/core/audio_pipeline.py`
- [Speech-to-text](https://github.com/aashuthosh10/clara-launch/blob/main/backend/core/stt.py): ASR stage · Converts voice input into transcript text. · `backend/core/stt.py`
- [Language state](https://github.com/aashuthosh10/clara-launch/blob/main/backend/core/language_detection.py): language detection · Detects or persists the active session language. · `backend/core/language_detection.py`
- [Session language](https://github.com/aashuthosh10/clara-launch/blob/main/backend/services/session_language.py): session service · Stores the selected language for the conversation session. · `backend/services/session_language.py`
- [RAG layer](https://github.com/aashuthosh10/clara-launch/blob/main/backend/core/rag.py): retrieval · Retrieves college facts from vector-backed storage for grounded answers. · `backend/core/rag.py`
- [Answer generation](https://github.com/aashuthosh10/clara-launch/blob/main/backend/services/answer_generation.py): response service · Builds final text replies from the conversation context and retrieved knowledge. · `backend/services/answer_generation.py`
- [Provider adapters](https://github.com/aashuthosh10/clara-launch/blob/main/backend/clients/provider_clients.py): external client layer · Abstracts outbound AI, speech, and vendor integrations. · `backend/clients/provider_clients.py`
- [DB clients](https://github.com/aashuthosh10/clara-launch/blob/main/backend/clients/database.py): persistence clients · Database access layer for pgvector-backed knowledge and retrieval. · `backend/clients/database.py`
- [Settings](https://github.com/aashuthosh10/clara-launch/blob/main/backend/config/settings.py): runtime config · Loads environment-driven configuration for providers, language, and database access. · `backend/config/settings.py`

### Data

Persistent knowledge and locale assets.

- [PostgreSQL](https://github.com/aashuthosh10/clara-launch/blob/main/scripts/db/init_pgvector.sql): pgvector store · Persistent college knowledge and embedding-backed retrieval store. · `scripts/db/init_pgvector.sql`
- [Knowledge base](https://github.com/aashuthosh10/clara-launch/blob/main/college_knowledge.txt): source corpus · Institutional facts ingested into the retrieval store. · `college_knowledge.txt`
- [Locales](https://github.com/aashuthosh10/clara-launch/blob/main/frontend/src/data/locales/en.json): translation assets · Localized text resources for supported UI and backend languages. · `frontend/src/data/locales/en.json`

### Ops

Containerization, scripts, and deployment support.

- [Compose setup](https://github.com/aashuthosh10/clara-launch/blob/main/docker-compose.yml): deployment · Containerized local bring-up for app and database services. · `docker-compose.yml`

## Connections

- 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.
