# rahulsamant37/ai-voice-coach architecture

> Architecture diagram of the GitHub repository rahulsamant37/ai-voice-coach, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rahulsamant37/ai-voice-coach
- Repository: https://github.com/rahulsamant37/ai-voice-coach

## Overview

##### Project Type and Purpose
- This is a full-stack, real-time web application (“AI Voice Coach”) built on Next.js with server-rendered React, a Convex-powered backend for real-time data and authentication, plus external AI/voice services (AssemblyAI for speech-to-text, OpenRouter/OpenAI for feedback generation, and AWS Polly for text-to-speech).

##### File Structure Analysis
- **app/**: Next.js App Router directory
- app/(main)/… contains page-level JSX components for dashboard, discussion rooms, and summary views.
- app/api/getToken/route.jsx: an internal API route to issue Convex/AWS tokens.
- app/handler/[...stack]/page.js: catch-all route, likely for dynamic client-side routing or fallback.
- Context, AuthProvider.jsx, _context/UserContext.jsx: user/session management.
- **components/**: shared UI components (shadcn/ui, magicui) and dialogs.
- **convex/**: Convex schema (schema.js, users.js) and generated client/server code for functions and data models.
- **services/** & **lib/utils.js**: wrappers around external APIs and app-wide helper functions.
- **stack.js**: orchestration of real-time pipeline or middleware.
- **Configuration**: next.config.mjs, postcss.config.mjs, jsconfig.json.

##### Key README Insights
- Frontend uses Next.js + Tailwind + Radix UI/shadcn for a responsive UI.
- Backend: Convex for real-time data, AssemblyAI for transcription, AWS Polly for voice synthesis, OpenRouter/OpenAI for feedback, RecordRTC for capturing audio.
- Deployment paths: Vercel, Docker, traditional hosting, plus Convex function deployment.

##### Main Components
a. Client Browser (React/Next.js UI)
b. Next.js Server (SSR, API routes, page rendering)
c. Convex Backend (database, real-time functions, auth)
d. External AI/Voice Services
- AssemblyAI (speech-to-text)
- OpenRouter/OpenAI (feedback generation)
- AWS Polly (text-to-speech)
e. Supporting Services
- RecordRTC (in-browser audio capture)
- Token issuance (app/api/getToken)

##### Relationships & Data Flows
1. User speaks → RecordRTC captures audio
2. Audio blob → Next.js API or directly to AssemblyAI (via services/GlobalServices)
3. AssemblyAI → real-time transcript streamed back to Next.js UI
4. Transcript → Convex function (stores message, triggers real-time update)
5. Transcript → OpenRouter/OpenAI via a Convex or Next.js serverless call → AI feedback text
6. Feedback text → AWS Polly via Next.js API → audio response
7. Both transcript and feedback persisted in Convex DB and pushed to all connected clients (discussion room)

##### Architectural Patterns & Principles
- Container/Component separation: UI, API, real-time backend, external services
- Event-driven flows: on new transcript/message, trigger AI feedback and DB update
- Serverless/API routes for token management and third-party integration
- Real-time synchronization via Convex subscriptions

##### Essential Elements
- Clear component labels (e.g., “DiscussionRoom.page.jsx”, “Convex Function: onNewTranscript”)
- Notes on security (JWT in headers), caching (if used), and deployment targets (Vercel, Docker).

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Client Browser Layer
  subgraph "Client Browser (UI)" 
    direction TB
    DBrowser["Dashboard"]:::ui
    DRoom["DiscussionRoom"]:::ui
    ChatBox["ChatBox Component"]:::ui
    Summary["Summary View"]:::ui
    SummaryBox["SummaryBox Component"]:::ui
    SharedUI["Shared UI Components"]:::ui
    MagicUI["MagicUI Components"]:::ui
    AuthCtx["UserContext"]:::ui
    AuthProv["AuthProvider"]:::ui
    RecordRTC["RecordRTC (Audio Capture)"]:::ui
  end

  %% Next.js Server Layer
  subgraph "Next.js Server" 
    direction TB
    AppRouter["App Router"]:::server
    TokenAPI["API Route: getToken"]:::server
    CatchAll["Catch-All Handler"]:::server
    Layout["Layout & App Entry"]:::server
    Middleware["Middleware & Config"]:::server
  end

  %% Convex Backend Layer
  subgraph "Convex Backend" 
    direction TB
    ConvexDB[(Users & Messages DB)]:::convex
    ConvexFuncs["Convex Functions & Triggers"]:::convex
    GenCode["Generated Client/Server Code"]:::convex
  end

  %% External Services Layer
  subgraph "External AI/Voice Services"
    direction TB
    AssemblyAI["AssemblyAI (STT)"]:::external
    OpenAI["OpenRouter/OpenAI (Feedback)"]:::external
    AWSPolly["AWS Polly (TTS)"]:::external
  end

  %% Utilities & Orchestration
  subgraph "Utilities & Orchestration"
    direction TB
    GlobalSvc["GlobalServices"]:::util
    Options["Options"]:::util
    Utils["Helper Utilities"]:::util
    Stack["Real-Time Pipeline (stack.js)"]:::util
  end

  %% Data & Control Flows
  DBrowser -->|uses| SharedUI
  DRoom -->|uses| ChatBox
  Summary -->|uses| SummaryBox
  DBrowser -->|auth via| AuthProv
  DRoom -->|auth via| AuthProv
  Summary -->|auth via| AuthProv
  DBrowser --> RecordRTC
  DRoom --> RecordRTC

  RecordRTC -->|stream audio| AssemblyAI
  AssemblyAI -->|transcript| DRoom
  AssemblyAI -->|transcript| ConvexFuncs

  DRoom -->|POST /api/getToken| TokenAPI
  TokenAPI -->|issues JWT| ConvexFuncs
  DRoom -->|subscribe room| ConvexFuncs
  ConvexFuncs -->|push updates| DRoom

  ConvexFuncs -->|store transcript| ConvexDB
  ConvexFuncs -->|trigger feedback| OpenAI

  OpenAI -->|feedback text| ConvexFuncs
  ConvexFuncs -->|store feedback| ConvexDB
  ConvexFuncs -->|push feedback| DRoom

  ConvexFuncs -->|invoke| AWSPolly
  AWSPolly -->|audio response| DRoom

  DRoom -->|calls| CatchAll
  DBrowser -->|renders via| AppRouter
  AppRouter -->|routes| Layout
  AppRouter -->|routes| CatchAll
  AppRouter -->|routes| TokenAPI
  Layout -->|loads| Middleware

  Stack --> ConvexFuncs
  GlobalSvc --> AssemblyAI
  GlobalSvc --> OpenAI
  GlobalSvc --> AWSPolly
  Options --> GlobalSvc
  Utils --> AWSPolly

  %% Click Events
  click DBrowser "https://github.com/rahulsamant37/ai-voice-coach/blob/main/app/(main)/dashboard/page.jsx"
  click DRoom "https://github.com/rahulsamant37/ai-voice-coach/blob/main/app/(main)/discussion-room/[roomid]/page.jsx"
  click ChatBox "https://github.com/rahulsamant37/ai-voice-coach/blob/main/app/(main)/discussion-room/[roomid]/_components/ChatBox.jsx"
  click Summary "https://github.com/rahulsamant37/ai-voice-coach/blob/main/app/(main)/view-summery/[roomid]/page.jsx"
  click SummaryBox "https://github.com/rahulsamant37/ai-voice-coach/blob/main/app/(main)/view-summery/_components/SummeryBox.jsx"
  click SharedUI "https://github.com/rahulsamant37/ai-voice-coach/tree/main/components/ui"
  click MagicUI "https://github.com/rahulsamant37/ai-voice-coach/blob/main/components/magicui/blur-fade.jsx"
  click AuthCtx "https://github.com/rahulsamant37/ai-voice-coach/blob/main/app/_context/UserContext.jsx"
  click AuthProv "https://github.com/rahulsamant37/ai-voice-coach/blob/main/app/AuthProvider.jsx"
  click TokenAPI "https://github.com/rahulsamant37/ai-voice-coach/blob/main/app/api/getToken/route.jsx"
  click CatchAll "https://github.com/rahulsamant37/ai-voice-coach/blob/main/app/handler/[...stack]/page.js"
  click Layout "https://github.com/rahulsamant37/ai-voice-coach/blob/main/app/layout.js"
  click Middleware "https://github.com/rahulsamant37/ai-voice-coach/blob/main/next.config.mjs"
  click Schema "https://github.com/rahulsamant37/ai-voice-coach/blob/main/convex/schema.js"
  click UsersColl "https://github.com/rahulsamant37/ai-voice-coach/blob/main/convex/users.js"
  click GenCode "https://github.com/rahulsamant37/ai-voice-coach/blob/main/convex/_generated/api.js"
  click ConvexFuncs "https://github.com/rahulsamant37/ai-voice-coach/blob/main/convex/DiscussionRoom.jsx"
  click GlobalSvc "https://github.com/rahulsamant37/ai-voice-coach/blob/main/services/GlobalServices.jsx"
  click Options "https://github.com/rahulsamant37/ai-voice-coach/blob/main/services/Options.jsx"
  click Utils "https://github.com/rahulsamant37/ai-voice-coach/blob/main/lib/utils.js"
  click Stack "https://github.com/rahulsamant37/ai-voice-coach/blob/main/stack.js"

  %% Styles
  classDef ui fill:#E0F7FA,stroke:#006064,color:#004D40
  classDef server fill:#E8F5E9,stroke:#2E7D32,color:#1B5E20
  classDef convex fill:#FFF3E0,stroke:#FB8C00,color:#E65100
  classDef external fill:#ECEFF1,stroke:#607D8B,color:#455A64
  classDef util fill:#F3E5F5,stroke:#8E24AA,color:#4A148C
```
