How mahammadwahab540/callagent works
Project type and purpose
• This is a single-page front-end application built with React, TypeScript, and Vite.
Main architectural components
a. User & Browser
• User’s microphone and speaker (via Web Audio)
• Host environment: Chrome/Firefox, running index.html + bundle from Vite.
b. React Application
• Entry: index.tsx → App.tsx
• Components folder:
– Stepper (controls stage flow)
– StageContent (per-stage UI layout)
– TranscriptDisplay (shows live transcripts)
– VoiceVisualizer (audio waveform/levels)
• Hooks: useVoiceAgent (manages voice-agent lifecycle & API calls)
• Utils: audioUtils (wrapper around Web Audio API for mic access, stream manipulation)
c. External Voice Service
• Could be OpenAI, Azure Speech-to-Text/Text-to-Speech, or a custom REST/WebSocket API
• Endpoint(s): stream audio in, receive text, send back audio responses
d. Configuration / Assets
• metadata.json (app metadata)
• constants.ts & types.ts (shared type definitions)
• Vite config & package.json (build/deploy settings)
Determining relationships & data flows
• The browser’s Web Audio API captures raw PCM from the microphone → passes it to audioUtils.
• audioUtils buffers/encodes audio → forwards to useVoiceAgent.
• useVoiceAgent opens WebSocket/REST calls to the external voice service.
• On transcript events, useVoiceAgent emits text → TranscriptDisplay subscribes & renders.
• On audio events (playback), useVoiceAgent provides audio buffers → VoiceVisualizer animates, and the browser audio output plays.
• Stepper & StageContent drive when recording starts/stops and which prompts appear.
Architectural patterns & principles
• Layered Architecture:
1. Presentation layer (React components)
2. Application logic layer (custom hooks, state management)
3. Infrastructure layer (audioUtils, external API)
• Single Responsibility: each React component & hook does one well-defined job.
• Dependency Inversion: components depend on abstracted hooks, not directly on low-level audio APIs.