# amritpalsingh0007/interview_agent architecture

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

- Interactive diagram: https://gitdiagram.com/amritpalsingh0007/interview_agent
- Repository: https://github.com/amritpalsingh0007/interview_agent

## Overview

##### Project Type & Purpose
- This is a full-stack, real-time “interview agent” prototype.
- It consists of three coordinated services:
- A React/Vite frontend for user interaction
- A FastAPI backend exposing REST/WebSocket endpoints
- A Python “livekitAgent” service managing real-time media, LLM / STT / TTS integration, and persistence

##### File Structure
- Top-level directories:
- frontend/ – React app (Vite, JSX, CSS, ESLint config)
- backend/ – FastAPI server (server.py)
- livekitAgent/ – AgentSession orchestration, RPC layer, config, data classes, Mongo & Redis clients
- Config files signal environment-specific setup (.env.example), build tooling (vite.config.js), and Python deps (requirements.txt).

##### Readme Insights
- The Readme instructs running three separate processes (frontend, backend, livekitAgent), points to LLM/STT/TTS pluggable providers, and uses LiveKit for real-time voice.

##### Main Components & Their Interactions
1. User’s Browser (React Frontend)
2. FastAPI Backend (server.py)
3. livekitAgent Service
– AgentSession core
– RPC endpoint (agent_rpc.py)
– Data classes (interview_data.py)
– Config (config.py)
– Persistence: MongoDB client, Redis client
4. LiveKit Media Server (external real-time streaming)
5. External ML Services (STT, LLM, TTS providers)
6. Data Stores: MongoDB, Redis
b. Relationships & data flow:
- The Browser connects to the LiveKit Media Server (WebRTC) for real-time voice streams.
- The Browser also calls the FastAPI backend (REST/WebSocket) for session control, metadata retrieval.
- FastAPI backend communicates (RPC/HTTP) with livekitAgent to orchestrate LLM/STT/TTS and store conversation state.
- livekitAgent:
- Ingests audio from LiveKit, sends to STT provider -> obtains transcript.
- Sends transcript + context to LLM provider -> obtains response text.
- Sends response text to TTS provider -> obtains audio.
- Pushes audio back into LiveKit Media Server.
- livekitAgent persists transcripts and session data in MongoDB and caches state or rate-limits in Redis.
c. Architectural patterns & design principles:
- Three-tier separation: Presentation | Application | Data
- Microservice-style: independent deployable agent service
- Pluggable provider pattern for STT/LLM/TTS
- RPC abstraction between backend and agent
- Event-driven media flow via LiveKit
d. Key technologies / frameworks:
- Frontend: React, Vite, JSX, CSS
- Backend: Python, FastAPI, Uvicorn
- Agent: Python 3.x, livekit-python, custom STT/LLM/TTS clients, Pydantic data classes
- Datastores: MongoDB, Redis
- Dev tooling: ESLint, npm, pip

##### Essential Details to Capture
- ENV config at each service (pointing to .env files).
- Plug-in points in livekitAgent (“CustomSTT”, “CustomTTS”, “google.LLM”).
- Redis usage for caching/session and MongoDB for persistence.
- Don’t overcrowd: group components logically but label them fully.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["React Frontend"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        Backend["FastAPI Backend\n(server.py)"]:::backend
        LiveKit["LiveKit Media Server"]:::external
        subgraph "livekitAgent Service"
            direction TB
            AgentSession["AgentSession Core\n(agent.py)"]:::agent
            RPCEndpoint["RPC Endpoint\n(agent_rpc.py)"]:::agent
            DataClasses["Interview Data Classes\n(interview_data.py)"]:::agent
            Config["Config\n(config.py)"]:::agent
            MainLauncher["Main Launcher\n(main.py)"]:::agent
            MongoClient["MongoDB Client\n(mongo_client.py)"]:::datastore
            RedisClient["Redis Client\n(redis_client.py)"]:::datastore
            Questions["Static Questions\n(questions.json)"]:::agent
        end
    end

    %% Data & External Services
    subgraph "Data & External Services"
        MongoDB["MongoDB"]:::datastore
        Redis["Redis"]:::datastore
        ML["External ML Services\n(STT, LLM, TTS)"]:::external
    end

    %% Connections
    Browser -->|"HTTP/WebSocket\nREST API"| Backend
    Browser -->|WebRTC| LiveKit

    Backend -->|"RPC/HTTP"| AgentSession
    AgentSession -->|Audio Stream| LiveKit
    LiveKit -->|Audio In| AgentSession

    AgentSession -->|"Transcript"| ML
    ML -->|"Response Text"| AgentSession
    AgentSession -->|"Audio Payload"| LiveKit

    AgentSession -->|"Persist Session"| MongoDB
    AgentSession -->|"Cache State"| Redis

    %% Click Events
    click Browser "https://github.com/amritpalsingh0007/interview_agent/tree/main/frontend/"
    click Backend "https://github.com/amritpalsingh0007/interview_agent/blob/main/backend/server.py"
    click AgentSession "https://github.com/amritpalsingh0007/interview_agent/blob/main/livekitAgent/Agent/agent.py"
    click RPCEndpoint "https://github.com/amritpalsingh0007/interview_agent/blob/main/livekitAgent/RPC/agent_rpc.py"
    click DataClasses "https://github.com/amritpalsingh0007/interview_agent/blob/main/livekitAgent/data_class/interview_data.py"
    click Config "https://github.com/amritpalsingh0007/interview_agent/blob/main/livekitAgent/config/config.py"
    click MainLauncher "https://github.com/amritpalsingh0007/interview_agent/blob/main/livekitAgent/main.py"
    click MongoClient "https://github.com/amritpalsingh0007/interview_agent/blob/main/livekitAgent/mongo/mongo_client.py"
    click RedisClient "https://github.com/amritpalsingh0007/interview_agent/blob/main/livekitAgent/redisLogic/redis_client.py"
    click Questions "https://github.com/amritpalsingh0007/interview_agent/blob/main/livekitAgent/questions.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#409EFF
    classDef backend fill:#E0FFDC,stroke:#67C23A
    classDef agent fill:#E0F7FA,stroke:#009688
    classDef datastore fill:#FFF4E5,stroke:#E6A23C
    classDef external fill:#F5E1FF,stroke:#C63AFF
```
