# mritunjaii/client-buddy architecture

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

- Interactive diagram: https://gitdiagram.com/mritunjaii/client-buddy
- Repository: https://github.com/mritunjaii/client-buddy

## Overview

Client Buddy captures WhatsApp conversations, filters them by monitoring preferences, batches message bursts, and uses local AI to produce client briefs and reminder candidates. Critical briefs can trigger outbound voice alerts; the dashboard presents briefs, contacts, reminders, source messages, and live alert updates. The excerpts show the core server, batching, worker, AI, database, and alert responsibilities. Several dashboard and API capabilities are documented in the README but their implementation details are not sampled, so those relationships are cited to the README.

Main entry points: [`apps/server/src/worker.ts`](https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/worker.ts) (Analysis Worker), [`apps/web/src/pages/index.tsx`](https://github.com/mritunjaii/client-buddy/blob/main/apps/web/src/pages/index.tsx) (Client Dashboard), [`apps/server/src/server.ts`](https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/server.ts) (Ingest and Filter), [`apps/server/src/batching.ts`](https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/batching.ts) (Burst Batching)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Message Ingestion"]
  node_ingest_service["WhatsApp Connector<br/>[whatsapp.ts]"]
  node_ingest_pipeline["Ingest and Filter<br/>[server.ts]"]
  node_batching["Burst Batching<br/>[batching.ts]"]
end

subgraph group_intelligence["Brief Intelligence"]
  node_worker["Analysis Worker<br/>[worker.ts]"]
  node_ai_analysis["Brief Analysis<br/>[ai.ts]"]
  node_call_alert["Critical Call Alerts<br/>[callAlert.ts]"]
end

subgraph group_serverdata["Server Data"]
  node_source_messages[("Source Messages<br/>[batching.ts]")]
  node_pending_batches[("Pending Batches<br/>[batching.ts]")]
  node_summaries_reminders[("Briefs and Reminders<br/>[worker.ts]")]
  node_contacts[("Contact Preferences<br/>[server.ts]")]
  node_shared_types["Shared Domain Types<br/>[index.ts]"]
end

subgraph group_experience["User Experience"]
  node_dashboard["Client Dashboard<br/>[index.tsx]"]
end

node_user(("Freelancer"))
node_whatsapp["WhatsApp Web"]
node_ollama["Local Ollama"]
node_elevenlabs["ElevenLabs"]
node_twilio["Twilio"]
node_phone(("User Phone"))
node_mongodb[("MongoDB")]

node_user -->|"messages"| node_whatsapp
node_whatsapp -->|"streams messages"| node_ingest_service
node_ingest_service -->|"normalizes messages"| node_ingest_pipeline
node_ingest_pipeline -->|"checks preferences"| node_contacts
node_ingest_pipeline -->|"ingests allowed messages"| node_batching
node_batching -->|"caches messages"| node_source_messages
node_batching -->|"updates batches"| node_pending_batches
node_worker -->|"claims due batches"| node_pending_batches
node_worker -->|"reads context"| node_contacts
node_worker -->|"analyzes batch"| node_ai_analysis
node_ai_analysis -->|"requests generation"| node_ollama
node_worker -->|"persists results"| node_summaries_reminders
node_worker -->|"marks processed"| node_pending_batches
node_worker -->|"dispatches critical alert"| node_call_alert
node_call_alert -->|"synthesizes voice"| node_elevenlabs
node_call_alert -->|"places call"| node_twilio
node_twilio -->|"rings"| node_phone
node_worker -->|"emits live events"| node_dashboard
node_user -->|"reviews intelligence"| node_dashboard
node_dashboard -->|"views briefs and reminders"| node_summaries_reminders
node_dashboard -->|"inspects originals"| node_source_messages
node_dashboard -->|"manages profiles"| node_contacts
node_ingest_pipeline -->|"reads and writes"| node_mongodb
node_batching -->|"stores batches and sources"| node_mongodb
node_worker -->|"stores analysis records"| node_mongodb
node_ingest_pipeline -->|"uses domain types"| node_shared_types
node_worker -->|"uses domain types"| node_shared_types
node_dashboard -->|"replays alert audio"| node_elevenlabs

click node_ingest_service "https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/whatsapp.ts"
click node_ingest_pipeline "https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/server.ts"
click node_batching "https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/batching.ts"
click node_source_messages "https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/batching.ts"
click node_pending_batches "https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/batching.ts"
click node_worker "https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/worker.ts"
click node_ai_analysis "https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/ai.ts"
click node_summaries_reminders "https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/worker.ts"
click node_contacts "https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/server.ts"
click node_call_alert "https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/callAlert.ts"
click node_dashboard "https://github.com/mritunjaii/client-buddy/blob/main/apps/web/src/pages/index.tsx"
click node_shared_types "https://github.com/mritunjaii/client-buddy/blob/main/packages/shared/src/index.ts"

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_ingest_service,node_ingest_pipeline,node_batching,node_phone toneBlue
class node_worker,node_ai_analysis,node_call_alert,node_mongodb toneAmber
class node_source_messages,node_pending_batches,node_summaries_reminders,node_contacts,node_shared_types toneMint
class node_dashboard toneRose
class node_user,node_whatsapp,node_ollama,node_elevenlabs,node_twilio toneIndigo
```

## Components

### Message Ingestion

- [WhatsApp Connector](https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/whatsapp.ts): `apps/server/src/whatsapp.ts`
- [Ingest and Filter](https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/server.ts): `apps/server/src/server.ts`
- [Burst Batching](https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/batching.ts): `apps/server/src/batching.ts`

### Brief Intelligence

- [Analysis Worker](https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/worker.ts): `apps/server/src/worker.ts`
- [Brief Analysis](https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/ai.ts): `apps/server/src/ai.ts`
- [Critical Call Alerts](https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/callAlert.ts): `apps/server/src/callAlert.ts`

### Server Data

- [Source Messages](https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/batching.ts): `apps/server/src/batching.ts`
- [Pending Batches](https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/batching.ts): `apps/server/src/batching.ts`
- [Briefs and Reminders](https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/worker.ts): `apps/server/src/worker.ts`
- [Contact Preferences](https://github.com/mritunjaii/client-buddy/blob/main/apps/server/src/server.ts): `apps/server/src/server.ts`
- [Shared Domain Types](https://github.com/mritunjaii/client-buddy/blob/main/packages/shared/src/index.ts): `packages/shared/src/index.ts`

### User Experience

- [Client Dashboard](https://github.com/mritunjaii/client-buddy/blob/main/apps/web/src/pages/index.tsx): `apps/web/src/pages/index.tsx`

### Other components

- **Freelancer**
- **WhatsApp Web**
- **Local Ollama**
- **ElevenLabs**
- **Twilio**
- **User Phone**
- **MongoDB**

## Connections

- Freelancer → WhatsApp Web: messages (evidence: `README.md`)
- WhatsApp Web → WhatsApp Connector: streams messages (evidence: `README.md`)
- WhatsApp Connector → Ingest and Filter: normalizes messages (evidence: `README.md`)
- Ingest and Filter → Contact Preferences: checks preferences (evidence: `apps/server/src/server.ts`)
- Ingest and Filter → Burst Batching: ingests allowed messages (evidence: `apps/server/src/server.ts`)
- Burst Batching → Source Messages: caches messages (evidence: `apps/server/src/batching.ts`)
- Burst Batching → Pending Batches: updates batches (evidence: `apps/server/src/batching.ts`)
- Analysis Worker → Pending Batches: claims due batches (evidence: `apps/server/src/worker.ts`)
- Analysis Worker → Contact Preferences: reads context (evidence: `apps/server/src/worker.ts`)
- Analysis Worker → Brief Analysis: analyzes batch (evidence: `apps/server/src/worker.ts`)
- Brief Analysis → Local Ollama: requests generation (evidence: `apps/server/src/ai.ts`)
- Analysis Worker → Briefs and Reminders: persists results (evidence: `apps/server/src/worker.ts`)
- Analysis Worker → Pending Batches: marks processed (evidence: `apps/server/src/worker.ts`)
- Analysis Worker → Critical Call Alerts: dispatches critical alert (evidence: `apps/server/src/worker.ts`)
- Critical Call Alerts → ElevenLabs: synthesizes voice (evidence: `apps/server/src/callAlert.ts`)
- Critical Call Alerts → Twilio: places call (evidence: `apps/server/src/callAlert.ts`)
- Twilio → User Phone: rings (evidence: `README.md`)
- Analysis Worker → Client Dashboard: emits live events (evidence: `README.md`)
- Freelancer → Client Dashboard: reviews intelligence (evidence: `README.md`)
- Client Dashboard → Briefs and Reminders: views briefs and reminders (evidence: `README.md`)
- Client Dashboard → Source Messages: inspects originals (evidence: `README.md`)
- Client Dashboard → Contact Preferences: manages profiles (evidence: `README.md`)
- Ingest and Filter → MongoDB: reads and writes (evidence: `apps/server/src/server.ts`)
- Burst Batching → MongoDB: stores batches and sources (evidence: `apps/server/src/batching.ts`)
- Analysis Worker → MongoDB: stores analysis records (evidence: `apps/server/src/worker.ts`)
- Ingest and Filter → Shared Domain Types: uses domain types (evidence: `apps/server/src/server.ts`)
- Analysis Worker → Shared Domain Types: uses domain types (evidence: `apps/server/src/worker.ts`)
- Client Dashboard → ElevenLabs: replays alert audio (evidence: `README.md`)
