# devaprasath4/caretta architecture

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

- Interactive diagram: https://gitdiagram.com/devaprasath4/caretta
- Repository: https://github.com/devaprasath4/caretta

## Overview

#### Purpose and Entry Points
Caretta is a real-time sales-call intelligence system: it captures conversation audio/transcripts, detects technical questions or objections, generates AI coaching and answers, and preserves call history. The Node backend starts through `server/src/server.js` and configures the Express application in `server/src/app.js`. Static browser-facing entry pages include `client/index.html`, `client/login.html`, and `client/pages/dashboard.html`.

#### Browser Client
The frontend is plain HTML/CSS/JavaScript rather than a framework application. Dashboard and call-facing behavior is organized in `client/js/dashboard.js`, `client/js/ai-coach.js`, and `client/js/transcript.js`; session authentication is handled by `client/js/login.js`. `client/js/socket.js` is the client boundary for real-time server communication, allowing generated guidance and transcript events to reach an active sales screen.

#### HTTP, Authentication, and Session Boundary
Express exposes separate route domains for identity, calls, transcripts, AI, and knowledge-base operations: `server/src/routes/authRoutes.js`, `server/src/routes/callRoutes.js`, and `server/src/routes/aiRoutes.js`. Authentication controller logic resides in `server/src/controllers/authController.js`; protected requests pass through `server/src/middleware/authMiddleware.js`. JWT configuration is implied by the required `JWT_SECRET`, separating user/session access from call and AI workflows.

#### Real-Time Call and Transcript Flow
A call session is created and managed through `server/src/controllers/callController.js` and persisted as `server/src/models/CallSession.js`. Speech transcription enters through `server/src/services/whisperService.js`, with transcript request handling in `server/src/controllers/transcriptController.js` and durable transcript records in `server/src/models/Transcript.js`. Socket infrastructure in `server/src/config/socket.js` distributes live call/transcript and coaching updates to connected clients.

#### AI Coaching Pipeline
Transcript/question content is passed to the LLM boundary in `server/src/services/llmService.js`, intended for Google Gemini. `server/src/services/coachingService.js` turns model output into sales-oriented responses, objection guidance, and follow-up recommendations. Suggestions are represented by `server/src/models/Suggestion.js`; this provides a persistence boundary between ephemeral real-time advice and historical call insights. Voice output can be delegated to ElevenLabs through `server/src/services/ttsService.js`.

#### Retrieval-Augmented Knowledge Layer
The repository supports grounding AI responses in product knowledge. Knowledge content is modeled as chunks in `server/src/models/KnowledgeChunk.js`, with source data at `server/src/data/knowledgeBase.js`. Retrieval and response augmentation are implemented in `server/src/services/ragService.js`, while knowledge/AI-facing endpoints are defined in `server/src/routes/kbRoutes.js`, `server/src/routes/ragService.js`, and `server/src/routes/aiRoutes.js`. This is the boundary between internal sales/product knowledge and external LLM generation.

#### Data, Infrastructure, and External Services
MongoDB is the system of record, initialized via `server/src/config/db.js`, for users, calls, transcripts, knowledge chunks, and suggestions; user records are defined in `server/src/models/User.js`. Required runtime services are Node.js, MongoDB, Google Gemini, speech-to-text integration, ElevenLabs, and Socket.IO-style real-time transport. Environment-dependent credentials and connection settings are documented by `server/.env.example`; centralized error handling is at `server/src/middleware/errorMiddleware.js`.

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser Client"]
  node_pages["Browser pages<br/>HTML entry points<br/>[dashboard.html]"]
  node_ui["Dashboard &amp; call UI<br/>browser JS<br/>[dashboard.js]"]
  node_login["Session login<br/>browser JS<br/>[login.js]"]
  node_client_socket["Realtime client<br/>Socket client<br/>[socket.js]"]
end

subgraph group_api["Node API &amp; Realtime"]
  node_express["Express application<br/>Node application<br/>[app.js]"]
  node_auth["Auth &amp; JWT guard<br/>controller middleware<br/>[authController.js]"]
  node_calls["Call sessions<br/>controller<br/>[callController.js]"]
  node_transcripts["Transcript intake<br/>controller"]
  node_socket_hub["Realtime socket hub<br/>Socket server<br/>[socket.js]"]
end

subgraph group_intelligence["Speech &amp; AI Pipeline"]
  node_speech["Speech transcription<br/>speech service<br/>[whisperService.js]"]
  node_coaching["Sales coaching<br/>AI orchestration<br/>[coachingService.js]"]
  node_rag["Knowledge retrieval<br/>RAG service<br/>[ragService.js]"]
  node_llm["Gemini generation<br/>LLM adapter<br/>[llmService.js]"]
  node_tts["Voice output<br/>TTS adapter<br/>[ttsService.js]"]
end

subgraph group_data["Data &amp; External Services"]
  node_mongodb[("MongoDB<br/>system of record<br/>[db.js]")]
  node_users["Users<br/>model<br/>[User.js]"]
  node_call_data["Call records<br/>model<br/>[CallSession.js]"]
  node_transcript_data["Transcript records<br/>model<br/>[Transcript.js]"]
  node_suggestions["Coaching history<br/>model<br/>[Suggestion.js]"]
  node_knowledge["Knowledge chunks<br/>model<br/>[KnowledgeChunk.js]"]
  node_kb_source["Knowledge source<br/>seed data<br/>[knowledgeBase.js]"]
  node_external_ai{{"AI providers<br/>Gemini and ElevenLabs"}}
end

node_pages -->|"loads"| node_ui
node_pages -->|"loads"| node_login
node_ui -->|"subscribes"| node_client_socket
node_login -->|"auth requests"| node_express
node_ui -->|"call and AI requests"| node_express
node_client_socket -->|"live events"| node_socket_hub
node_express -->|"identity routes"| node_auth
node_express -->|"call routes"| node_calls
node_express -->|"transcript requests"| node_transcripts
node_express -->|"AI routes"| node_coaching
node_express -->|"knowledge routes"| node_rag
node_auth -->|"user access"| node_users
node_calls -->|"persists"| node_call_data
node_transcripts -->|"submits audio"| node_speech
node_speech -->|"stores transcript"| node_transcript_data
node_transcripts -->|"publishes transcript"| node_socket_hub
node_transcript_data -->|"conversation context"| node_coaching
node_coaching -->|"grounds answers"| node_rag
node_rag -->|"retrieves chunks"| node_knowledge
node_kb_source -->|"supplies content"| node_knowledge
node_coaching -->|"generates guidance"| node_llm
node_llm -->|"Gemini"| node_external_ai
node_coaching -->|"persists advice"| node_suggestions
node_coaching -->|"pushes coaching"| node_socket_hub
node_coaching -.->|"optional speech"| node_tts
node_tts -->|"ElevenLabs"| node_external_ai
node_users -->|"stored in"| node_mongodb
node_call_data -->|"stored in"| node_mongodb
node_transcript_data -->|"stored in"| node_mongodb
node_suggestions -->|"stored in"| node_mongodb
node_knowledge -->|"stored in"| node_mongodb

click node_pages "https://github.com/devaprasath4/caretta/blob/main/client/pages/dashboard.html"
click node_ui "https://github.com/devaprasath4/caretta/blob/main/client/js/dashboard.js"
click node_login "https://github.com/devaprasath4/caretta/blob/main/client/js/login.js"
click node_client_socket "https://github.com/devaprasath4/caretta/blob/main/client/js/socket.js"
click node_express "https://github.com/devaprasath4/caretta/blob/main/server/src/app.js"
click node_auth "https://github.com/devaprasath4/caretta/blob/main/server/src/controllers/authController.js"
click node_calls "https://github.com/devaprasath4/caretta/blob/main/server/src/controllers/callController.js"
click node_transcripts "https://github.com/devaprasath4/caretta/blob/main/server/src/controllers/transcriptController.js"
click node_socket_hub "https://github.com/devaprasath4/caretta/blob/main/server/src/config/socket.js"
click node_speech "https://github.com/devaprasath4/caretta/blob/main/server/src/services/whisperService.js"
click node_coaching "https://github.com/devaprasath4/caretta/blob/main/server/src/services/coachingService.js"
click node_rag "https://github.com/devaprasath4/caretta/blob/main/server/src/services/ragService.js"
click node_llm "https://github.com/devaprasath4/caretta/blob/main/server/src/services/llmService.js"
click node_tts "https://github.com/devaprasath4/caretta/blob/main/server/src/services/ttsService.js"
click node_mongodb "https://github.com/devaprasath4/caretta/blob/main/server/src/config/db.js"
click node_users "https://github.com/devaprasath4/caretta/blob/main/server/src/models/User.js"
click node_call_data "https://github.com/devaprasath4/caretta/blob/main/server/src/models/CallSession.js"
click node_transcript_data "https://github.com/devaprasath4/caretta/blob/main/server/src/models/Transcript.js"
click node_suggestions "https://github.com/devaprasath4/caretta/blob/main/server/src/models/Suggestion.js"
click node_knowledge "https://github.com/devaprasath4/caretta/blob/main/server/src/models/KnowledgeChunk.js"
click node_kb_source "https://github.com/devaprasath4/caretta/blob/main/server/src/data/knowledgeBase.js"

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_pages,node_ui,node_login,node_client_socket toneBlue
class node_express,node_auth,node_calls,node_transcripts,node_socket_hub toneAmber
class node_speech,node_coaching,node_rag,node_llm,node_tts toneMint
class node_mongodb,node_users,node_call_data,node_transcript_data,node_suggestions,node_knowledge,node_kb_source,node_external_ai toneRose
```

## Components

### Browser Client

- [Browser pages](https://github.com/devaprasath4/caretta/blob/main/client/pages/dashboard.html): HTML entry points · `client/pages/dashboard.html`
- [Dashboard & call UI](https://github.com/devaprasath4/caretta/blob/main/client/js/dashboard.js): browser JS · `client/js/dashboard.js`
- [Session login](https://github.com/devaprasath4/caretta/blob/main/client/js/login.js): browser JS · `client/js/login.js`
- [Realtime client](https://github.com/devaprasath4/caretta/blob/main/client/js/socket.js): Socket client · `client/js/socket.js`

### Node API & Realtime

- [Express application](https://github.com/devaprasath4/caretta/blob/main/server/src/app.js): Node application · `server/src/app.js`
- [Auth & JWT guard](https://github.com/devaprasath4/caretta/blob/main/server/src/controllers/authController.js): controller middleware · `server/src/controllers/authController.js`
- [Call sessions](https://github.com/devaprasath4/caretta/blob/main/server/src/controllers/callController.js): controller · `server/src/controllers/callController.js`
- [Transcript intake](https://github.com/devaprasath4/caretta/blob/main/server/src/controllers/transcriptController.js): controller · `server/src/controllers/transcriptController.js`
- [Realtime socket hub](https://github.com/devaprasath4/caretta/blob/main/server/src/config/socket.js): Socket server · `server/src/config/socket.js`

### Speech & AI Pipeline

- [Speech transcription](https://github.com/devaprasath4/caretta/blob/main/server/src/services/whisperService.js): speech service · `server/src/services/whisperService.js`
- [Sales coaching](https://github.com/devaprasath4/caretta/blob/main/server/src/services/coachingService.js): AI orchestration · `server/src/services/coachingService.js`
- [Knowledge retrieval](https://github.com/devaprasath4/caretta/blob/main/server/src/services/ragService.js): RAG service · `server/src/services/ragService.js`
- [Gemini generation](https://github.com/devaprasath4/caretta/blob/main/server/src/services/llmService.js): LLM adapter · `server/src/services/llmService.js`
- [Voice output](https://github.com/devaprasath4/caretta/blob/main/server/src/services/ttsService.js): TTS adapter · `server/src/services/ttsService.js`

### Data & External Services

- [MongoDB](https://github.com/devaprasath4/caretta/blob/main/server/src/config/db.js): system of record · Stores users, calls, transcripts, knowledge chunks, and suggestions. · `server/src/config/db.js`
- [Users](https://github.com/devaprasath4/caretta/blob/main/server/src/models/User.js): model · `server/src/models/User.js`
- [Call records](https://github.com/devaprasath4/caretta/blob/main/server/src/models/CallSession.js): model · `server/src/models/CallSession.js`
- [Transcript records](https://github.com/devaprasath4/caretta/blob/main/server/src/models/Transcript.js): model · `server/src/models/Transcript.js`
- [Coaching history](https://github.com/devaprasath4/caretta/blob/main/server/src/models/Suggestion.js): model · `server/src/models/Suggestion.js`
- [Knowledge chunks](https://github.com/devaprasath4/caretta/blob/main/server/src/models/KnowledgeChunk.js): model · `server/src/models/KnowledgeChunk.js`
- [Knowledge source](https://github.com/devaprasath4/caretta/blob/main/server/src/data/knowledgeBase.js): seed data · `server/src/data/knowledgeBase.js`
- **AI providers**: Gemini and ElevenLabs

## Connections

- Browser pages → Dashboard & call UI: loads
- Browser pages → Session login: loads
- Dashboard & call UI → Realtime client: subscribes
- Session login → Express application: auth requests
- Dashboard & call UI → Express application: call and AI requests
- Realtime client → Realtime socket hub: live events
- Express application → Auth & JWT guard: identity routes
- Express application → Call sessions: call routes
- Express application → Transcript intake: transcript requests
- Express application → Sales coaching: AI routes
- Express application → Knowledge retrieval: knowledge routes
- Auth & JWT guard → Users: user access
- Call sessions → Call records: persists
- Transcript intake → Speech transcription: submits audio
- Speech transcription → Transcript records: stores transcript
- Transcript intake → Realtime socket hub: publishes transcript
- Transcript records → Sales coaching: conversation context
- Sales coaching → Knowledge retrieval: grounds answers
- Knowledge retrieval → Knowledge chunks: retrieves chunks
- Knowledge source → Knowledge chunks: supplies content
- Sales coaching → Gemini generation: generates guidance
- Gemini generation → AI providers: Gemini
- Sales coaching → Coaching history: persists advice
- Sales coaching → Realtime socket hub: pushes coaching
- Sales coaching → Voice output: optional speech
- Voice output → AI providers: ElevenLabs
- Users → MongoDB: stored in
- Call records → MongoDB: stored in
- Transcript records → MongoDB: stored in
- Coaching history → MongoDB: stored in
- Knowledge chunks → MongoDB: stored in
