# saurabhjdsingh/sales-ai-crm architecture

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

- Interactive diagram: https://gitdiagram.com/saurabhjdsingh/sales-ai-crm
- Repository: https://github.com/saurabhjdsingh/sales-ai-crm

## Overview

#### Purpose and entry points
Sales AI CRM is a white-label sales CRM combining operational CRM records, AI prospecting, Twilio calling, and local call transcription. The Angular SPA boots at `frontend/src/main.ts` and routes from `frontend/src/app/app.routes.ts`. Django exposes REST endpoints through `backend/config/urls.py`; ASGI/WebSocket execution starts at `backend/config/asgi.py`. Container orchestration is defined in `docker-compose.yml`.

#### Client application and API boundary
Angular feature views call the Django API through shared authenticated services. JWT/token handling and route protection reside in `frontend/src/app/core/auth/auth.service.ts`, `frontend/src/app/core/auth/auth.interceptor.ts`, and `frontend/src/app/core/auth/auth.guard.ts`. Feature-local services/stores mediate UI state for CRM entities, e.g. `frontend/src/app/features/companies/services/company.service.ts` and `frontend/src/app/features/deals/services/deal.store.ts`.

#### Core CRM domain
Django apps own persistent business domains and expose the conventional model/serializer/service/view/URL boundary. Companies, contacts, deals, tasks, notes, activities, imports, reports, search, and dashboard form the operational CRM layer. Principal paths include `backend/apps/companies/models.py`, `backend/apps/contacts/models.py`, `backend/apps/deals/models.py`, and `backend/apps/tasks/services.py`. These records supply the context used by AI, calling, and follow-up workflows.

#### Accounts, tenancy, and branding
Accounts manages users, invitations, organization branding, and configurable SMTP. It delegates branding behavior through `backend/apps/accounts/services/branding.py`, while encryption and branded email concerns sit in `backend/apps/common/encryption.py` and `backend/apps/common/email.py`. This is a security and tenant-customization boundary: invite/onboarding and email credentials should remain isolated from CRM and AI domain logic.

#### AI engine and agent orchestration
The AI engine abstracts LLM providers and prompt assembly, supporting OpenAI and Claude via `backend/apps/ai_engine/services/providers/openai.py`, `backend/apps/ai_engine/services/providers/claude.py`, and `backend/apps/ai_engine/services/context_builder.py`. The agent layer orchestrates tool-driven prospect research and sales actions through `backend/apps/agent/services/orchestrator.py`, `backend/apps/agent/services/tool_router.py`, and `backend/apps/agent/tools/registry.py`. Tools access CRM context, research sources, LinkedIn/browser automation, outreach, and ICP/sales-strategy analysis; provider calls are a distinct external-service boundary.

#### Telephony and conversation intelligence
Telephony encapsulates Twilio integration behind a provider factory and provider interface: `backend/apps/telephony/providers/factory.py`, `backend/apps/telephony/providers/twilio.py`, and `backend/apps/telephony/services.py`. The Angular softphone and call state live in `frontend/src/app/features/telephony/twilio-voice.service.ts` and `frontend/src/app/features/telephony/call-state.service.ts`.

During calls, the frontend independently streams local and remote audio over WebSockets using `frontend/src/app/features/conversation-intelligence/conversation-intelligence.service.ts`. Django Channels consumers in `backend/apps/conversation_intelligence/websocket/consumers.py` send audio to the provider-independent transcription layer, currently `backend/apps/conversation_intelligence/providers/whisper_docker.py`. Post-call analysis runs through `backend/apps/conversation_intelligence/tasks/ai_analysis.py`, persists results, and can generate CRM follow-up actions.

#### Async processing and infrastructure
Celery provides deferred imports, reminders, AI work, and domain background jobs, configured by `backend/config/celery.py`; Redis is the broker/scheduler dependency. PostgreSQL is the system of record. Daphne/Channels provides ASGI WebSockets. Docker Compose runs frontend, Django, Celery, PostgreSQL, Redis, and a local `faster-whisper-server` container. External integrations include OpenAI/Anthropic, Twilio, optional SMTP providers, and LinkedIn/browser automation.

Main entry points: [`docker-compose.yml`](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/docker-compose.yml) (Container stack), [`backend/apps/companies/models.py`](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/companies/models.py) (CRM domain), [`backend/config/urls.py`](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/config/urls.py) (REST API), [`backend/apps/agent/services/orchestrator.py`](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/agent/services/orchestrator.py) (Sales agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Angular client"]
  node_spa["Angular SPA<br/>[main.ts]"]
  node_client_auth["Auth boundary<br/>Angular auth<br/>[auth.service.ts]"]
  node_crm_client["CRM feature state<br/>Angular services<br/>[company.service.ts]"]
  node_softphone["Softphone state<br/>Angular telephony"]
  node_audio_client["Audio streaming<br/>Angular WebSocket"]
end

subgraph group_backend["Django application"]
  node_http_api{{"REST API<br/>Django URLs<br/>[urls.py]"}}
  node_crm_domain["CRM domain<br/>Django apps<br/>[models.py]"]
  node_accounts["Accounts & tenancy<br/>Django app<br/>[branding.py]"]
  node_secure_email["Secure branded email<br/>common services<br/>[encryption.py]"]
  node_ai_engine["AI engine<br/>LLM abstraction<br/>[context_builder.py]"]
  node_agent["Sales agent<br/>agent orchestration<br/>[orchestrator.py]"]
end

subgraph group_calling["Calling intelligence"]
  node_telephony["Telephony service<br/>provider abstraction<br/>[services.py]"]
  node_ws_gateway{{"WebSocket consumers<br/>Django Channels<br/>[consumers.py]"}}
  node_transcription["Transcription provider<br/>speech-to-text<br/>[whisper_docker.py]"]
  node_call_analysis["Post-call analysis<br/>Celery task<br/>[ai_analysis.py]"]
end

subgraph group_infra["Async & infrastructure"]
  node_asgi["ASGI runtime<br/>Daphne / Channels<br/>[asgi.py]"]
  node_celery["Celery workers<br/>background jobs<br/>[celery.py]"]
  node_postgres[("PostgreSQL<br/>system of record")]
  node_redis["Redis<br/>broker & scheduler"]
  node_compose["Container stack<br/>Docker Compose<br/>[docker-compose.yml]"]
end

node_external{{"External providers<br/>integrations"}}

node_spa -->|"protects routes"| node_client_auth
node_spa -->|"uses"| node_crm_client
node_client_auth -->|"authenticated requests"| node_http_api
node_crm_client -->|"CRM API calls"| node_http_api
node_softphone -->|"call control"| node_telephony
node_audio_client -->|"audio WebSockets"| node_asgi
node_http_api -->|"serves"| node_crm_domain
node_http_api -->|"serves"| node_accounts
node_crm_domain -->|"persists records"| node_postgres
node_accounts -->|"branding and SMTP"| node_secure_email
node_secure_email -->|"SMTP"| node_external
node_agent -->|"reads and acts on context"| node_crm_domain
node_agent -->|"requests reasoning"| node_ai_engine
node_agent -->|"research and automation"| node_external
node_ai_engine -->|"LLM providers"| node_external
node_telephony -->|"Twilio"| node_external
node_asgi -->|"routes sockets"| node_ws_gateway
node_ws_gateway -->|"streams audio"| node_transcription
node_transcription -->|"transcript"| node_call_analysis
node_call_analysis -->|"follow-up actions"| node_crm_domain
node_celery -->|"broker and scheduler"| node_redis
node_celery -->|"background jobs"| node_crm_domain
node_compose -.->|"runs"| node_spa
node_compose -.->|"runs"| node_asgi
node_compose -.->|"runs"| node_celery
node_compose -.->|"runs"| node_postgres
node_compose -.->|"runs"| node_redis
node_compose -.->|"runs Whisper server"| node_transcription

click node_spa "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/frontend/src/main.ts"
click node_client_auth "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/frontend/src/app/core/auth/auth.service.ts"
click node_crm_client "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/frontend/src/app/features/companies/services/company.service.ts"
click node_softphone "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/frontend/src/app/features/telephony/twilio-voice.service.ts"
click node_audio_client "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/frontend/src/app/features/conversation-intelligence/conversation-intelligence.service.ts"
click node_http_api "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/config/urls.py"
click node_crm_domain "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/companies/models.py"
click node_accounts "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/accounts/services/branding.py"
click node_secure_email "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/common/encryption.py"
click node_ai_engine "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/ai_engine/services/context_builder.py"
click node_agent "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/agent/services/orchestrator.py"
click node_telephony "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/telephony/services.py"
click node_ws_gateway "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/conversation_intelligence/websocket/consumers.py"
click node_transcription "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/conversation_intelligence/providers/whisper_docker.py"
click node_call_analysis "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/conversation_intelligence/tasks/ai_analysis.py"
click node_asgi "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/config/asgi.py"
click node_celery "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/config/celery.py"
click node_compose "https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/docker-compose.yml"

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_spa,node_client_auth,node_crm_client,node_softphone,node_audio_client toneBlue
class node_http_api,node_crm_domain,node_accounts,node_secure_email,node_ai_engine,node_agent toneAmber
class node_telephony,node_ws_gateway,node_transcription,node_call_analysis toneMint
class node_asgi,node_celery,node_postgres,node_redis,node_compose toneRose
class node_external toneNeutral
```

## Components

### Angular client

- [Angular SPA](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/frontend/src/main.ts): application · Routes CRM and sales workflows. · `frontend/src/main.ts`
- [Auth boundary](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/frontend/src/app/core/auth/auth.service.ts): Angular auth · JWT handling, interceptor, and route guard. · `frontend/src/app/core/auth/auth.service.ts`
- [CRM feature state](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/frontend/src/app/features/companies/services/company.service.ts): Angular services · Feature services and stores mediate CRM UI state. · `frontend/src/app/features/companies/services/company.service.ts`
- [Softphone state](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/frontend/src/app/features/telephony/twilio-voice.service.ts): Angular telephony · Twilio voice and call-state client. · `frontend/src/app/features/telephony/twilio-voice.service.ts`
- [Audio streaming](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/frontend/src/app/features/conversation-intelligence/conversation-intelligence.service.ts): Angular WebSocket · Streams local and remote call audio. · `frontend/src/app/features/conversation-intelligence/conversation-intelligence.service.ts`

### Django application

- [REST API](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/config/urls.py): Django URLs · HTTP API entry boundary. · `backend/config/urls.py`
- [CRM domain](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/companies/models.py): Django apps · Companies, contacts, deals, tasks, and operational records. · `backend/apps/companies/models.py`
- [Accounts & tenancy](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/accounts/services/branding.py): Django app · Users, invitations, organization branding, and SMTP settings. · `backend/apps/accounts/services/branding.py`
- [Secure branded email](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/common/encryption.py): common services · Encrypts credentials and sends branded email. · `backend/apps/common/encryption.py`
- [AI engine](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/ai_engine/services/context_builder.py): LLM abstraction · Builds prompts and selects LLM providers. · `backend/apps/ai_engine/services/context_builder.py`
- [Sales agent](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/agent/services/orchestrator.py): agent orchestration · Routes tools for research and sales actions. · `backend/apps/agent/services/orchestrator.py`

### Calling intelligence

- [Telephony service](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/telephony/services.py): provider abstraction · Provider factory encapsulates Twilio calling. · `backend/apps/telephony/services.py`
- [WebSocket consumers](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/conversation_intelligence/websocket/consumers.py): Django Channels · Receives streamed call audio. · `backend/apps/conversation_intelligence/websocket/consumers.py`
- [Transcription provider](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/conversation_intelligence/providers/whisper_docker.py): speech-to-text · Provider-independent local Whisper integration. · `backend/apps/conversation_intelligence/providers/whisper_docker.py`
- [Post-call analysis](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/apps/conversation_intelligence/tasks/ai_analysis.py): Celery task · Persists analysis and generates CRM follow-ups. · `backend/apps/conversation_intelligence/tasks/ai_analysis.py`

### Async & infrastructure

- [ASGI runtime](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/config/asgi.py): Daphne / Channels · WebSocket application entry point. · `backend/config/asgi.py`
- [Celery workers](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/backend/config/celery.py): background jobs · Runs imports, reminders, AI, and domain work. · `backend/config/celery.py`
- **PostgreSQL**: system of record
- **Redis**: broker & scheduler
- [Container stack](https://github.com/saurabhjdsingh/sales-ai-crm/blob/main/docker-compose.yml): Docker Compose · Runs application services and local Whisper server. · `docker-compose.yml`

### Other components

- **External providers**: integrations · OpenAI, Anthropic, Twilio, SMTP, LinkedIn, and browser automation.

## Connections

- Angular SPA → Auth boundary: protects routes
- Angular SPA → CRM feature state: uses
- Auth boundary → REST API: authenticated requests
- CRM feature state → REST API: CRM API calls
- Softphone state → Telephony service: call control
- Audio streaming → ASGI runtime: audio WebSockets
- REST API → CRM domain: serves
- REST API → Accounts & tenancy: serves
- CRM domain → PostgreSQL: persists records
- Accounts & tenancy → Secure branded email: branding and SMTP
- Secure branded email → External providers: SMTP
- Sales agent → CRM domain: reads and acts on context
- Sales agent → AI engine: requests reasoning
- Sales agent → External providers: research and automation
- AI engine → External providers: LLM providers
- Telephony service → External providers: Twilio
- ASGI runtime → WebSocket consumers: routes sockets
- WebSocket consumers → Transcription provider: streams audio
- Transcription provider → Post-call analysis: transcript
- Post-call analysis → CRM domain: follow-up actions
- Celery workers → Redis: broker and scheduler
- Celery workers → CRM domain: background jobs
- Container stack → Angular SPA: runs
- Container stack → ASGI runtime: runs
- Container stack → Celery workers: runs
- Container stack → PostgreSQL: runs
- Container stack → Redis: runs
- Container stack → Transcription provider: runs Whisper server
