# trycompai/crm architecture

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

- Interactive diagram: https://gitdiagram.com/trycompai/crm
- Repository: https://github.com/trycompai/crm

## Overview

Comp AI CRM is an agent-first customer relationship platform. A user works in the Next.js CRM, whose requests pass through the API to authenticated CRM records, conversations, search, enrichment, and dashboards. Independently, scheduled agent sessions lease due work, inspect CRM evidence and optional external sources, then record facts or schedule follow-ups. Tracking and mailbox synchronization provide additional signals. The tree and README establish these boundaries; several internal service-to-service links remain intentionally conservative because their implementations were not sampled.

Main entry points: [`apps/api/src/database/database.module.ts`](https://github.com/trycompai/crm/blob/release/apps/api/src/database/database.module.ts) (CRM Database), [`apps/agent/agent/agent.ts`](https://github.com/trycompai/crm/blob/release/apps/agent/agent/agent.ts) (Agent Runtime), [`apps/agent/agent/tools/record_fact.ts`](https://github.com/trycompai/crm/blob/release/apps/agent/agent/tools/record_fact.ts) (Agent Tools), [`apps/api/src/tracking/tracking-ingest.service.ts`](https://github.com/trycompai/crm/blob/release/apps/api/src/tracking/tracking-ingest.service.ts) (Tracking Ingest)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User Experience"]
  node_web_app["Web App<br/>[page.tsx]"]
  node_api_proxy["API Proxy<br/>[route.ts]"]
end

subgraph group_api["CRM API"]
  node_crm_api["CRM API<br/>[app.module.ts]"]
  node_auth_service["Auth Service<br/>[auth.service.ts]"]
  node_search_service["CRM Search<br/>[search.service.ts]"]
  node_conversation_service["Conversations"]
  node_enrichment_service["Enrichment"]
  node_agent_bridge["Agent Bridge<br/>[bridge.ts]"]
end

subgraph group_agent["Agent Runtime"]
  node_agent_runtime["Agent Runtime<br/>[agent.ts]"]
  node_agent_schedule["Agent Schedule<br/>[dispatch.ts]"]
  node_work_queue[("Work Queue<br/>[tasks.ts]")]
  node_agent_tools["Agent Tools<br/>[record_fact.ts]"]
  node_agent_sandbox["Agent Sandbox<br/>[sandbox.ts]"]
end

subgraph group_data["Data Integrations"]
  node_crm_database[("CRM Database<br/>[database.module.ts]")]
  node_mailbox_sync["Mailbox Sync"]
  node_google_service["Google Sync"]
  node_microsoft_service["Microsoft Sync"]
end

subgraph group_tracking["Tracking Analytics"]
  node_tracking_script["Tracking Script<br/>[route.ts]"]
  node_tracking_ingest["Tracking Ingest"]
  node_tracking_api["Tracking API"]
  node_analytics["Analytics Service"]
end

node_user(("CRM User"))
node_external_google["Google APIs"]
node_external_microsoft["Microsoft APIs"]

node_user -->|"uses"| node_web_app
node_web_app -->|"requests"| node_api_proxy
node_api_proxy -->|"forwards"| node_crm_api
node_crm_api -->|"authenticates"| node_auth_service
node_search_service -->|"reads records"| node_crm_database
node_conversation_service -->|"stores conversations"| node_crm_database
node_enrichment_service -->|"updates records"| node_crm_database
node_agent_schedule -->|"leases due work"| node_work_queue
node_agent_schedule -->|"starts sessions"| node_agent_runtime
node_agent_runtime -->|"dispatches tools"| node_agent_tools
node_agent_runtime -->|"uses sandbox"| node_agent_sandbox
node_agent_tools -->|"writes evidence"| node_crm_database
node_agent_tools -->|"schedules follow-up"| node_work_queue
node_agent_bridge -->|"calls agent"| node_agent_runtime
node_mailbox_sync -.->|"runs sync"| node_google_service
node_mailbox_sync -.->|"runs sync"| node_microsoft_service
node_google_service -.->|"reads mail"| node_external_google
node_microsoft_service -.->|"reads mail"| node_external_microsoft
node_tracking_script -->|"posts events"| node_tracking_api
node_tracking_api -->|"dispatches ingest"| node_tracking_ingest
node_tracking_ingest -->|"stores events"| node_crm_database
node_tracking_ingest -->|"files submissions"| node_enrichment_service
node_analytics -->|"reads metrics"| node_crm_database

click node_web_app "https://github.com/trycompai/crm/blob/release/apps/app/app/(app)/%5Bslug%5D/page.tsx"
click node_api_proxy "https://github.com/trycompai/crm/blob/release/apps/app/app/api/%5B...path%5D/route.ts"
click node_crm_api "https://github.com/trycompai/crm/blob/release/apps/api/src/app.module.ts"
click node_auth_service "https://github.com/trycompai/crm/blob/release/apps/api/src/auth/auth.service.ts"
click node_search_service "https://github.com/trycompai/crm/blob/release/apps/api/src/search/search.service.ts"
click node_conversation_service "https://github.com/trycompai/crm/blob/release/apps/api/src/conversations/conversations.service.ts"
click node_enrichment_service "https://github.com/trycompai/crm/blob/release/apps/api/src/enrichment/enrichment.service.ts"
click node_crm_database "https://github.com/trycompai/crm/blob/release/apps/api/src/database/database.module.ts"
click node_agent_runtime "https://github.com/trycompai/crm/blob/release/apps/agent/agent/agent.ts"
click node_agent_schedule "https://github.com/trycompai/crm/blob/release/apps/agent/agent/schedules/dispatch.ts"
click node_work_queue "https://github.com/trycompai/crm/blob/release/apps/agent/agent/lib/tasks.ts"
click node_agent_tools "https://github.com/trycompai/crm/blob/release/apps/agent/agent/tools/record_fact.ts"
click node_agent_sandbox "https://github.com/trycompai/crm/blob/release/apps/agent/agent/sandbox/sandbox.ts"
click node_agent_bridge "https://github.com/trycompai/crm/blob/release/apps/api/src/agent/bridge.ts"
click node_mailbox_sync "https://github.com/trycompai/crm/blob/release/apps/api/src/sync/mailbox-sync.service.ts"
click node_google_service "https://github.com/trycompai/crm/blob/release/apps/api/src/google/google-sync.service.ts"
click node_microsoft_service "https://github.com/trycompai/crm/blob/release/apps/api/src/microsoft/microsoft-sync.service.ts"
click node_tracking_script "https://github.com/trycompai/crm/blob/release/apps/app/app/t/%5Bsite%5D/route.ts"
click node_tracking_ingest "https://github.com/trycompai/crm/blob/release/apps/api/src/tracking/tracking-ingest.service.ts"
click node_tracking_api "https://github.com/trycompai/crm/blob/release/apps/api/src/tracking/tracking.controller.ts"
click node_analytics "https://github.com/trycompai/crm/blob/release/apps/api/src/telemetry/telemetry.service.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_web_app,node_api_proxy,node_user toneBlue
class node_crm_api,node_auth_service,node_search_service,node_conversation_service,node_enrichment_service,node_agent_bridge toneAmber
class node_agent_runtime,node_agent_schedule,node_work_queue,node_agent_tools,node_agent_sandbox,node_external_google,node_external_microsoft toneMint
class node_crm_database,node_mailbox_sync,node_google_service,node_microsoft_service toneRose
class node_tracking_script,node_tracking_ingest,node_tracking_api,node_analytics toneIndigo
```

## Components

### User Experience

- [Web App](https://github.com/trycompai/crm/blob/release/apps/app/app/(app)/%5Bslug%5D/page.tsx): `apps/app/app/(app)/[slug]/page.tsx`
- [API Proxy](https://github.com/trycompai/crm/blob/release/apps/app/app/api/%5B...path%5D/route.ts): `apps/app/app/api/[...path]/route.ts`

### CRM API

- [CRM API](https://github.com/trycompai/crm/blob/release/apps/api/src/app.module.ts): `apps/api/src/app.module.ts`
- [Auth Service](https://github.com/trycompai/crm/blob/release/apps/api/src/auth/auth.service.ts): `apps/api/src/auth/auth.service.ts`
- [CRM Search](https://github.com/trycompai/crm/blob/release/apps/api/src/search/search.service.ts): `apps/api/src/search/search.service.ts`
- [Conversations](https://github.com/trycompai/crm/blob/release/apps/api/src/conversations/conversations.service.ts): `apps/api/src/conversations/conversations.service.ts`
- [Enrichment](https://github.com/trycompai/crm/blob/release/apps/api/src/enrichment/enrichment.service.ts): `apps/api/src/enrichment/enrichment.service.ts`
- [Agent Bridge](https://github.com/trycompai/crm/blob/release/apps/api/src/agent/bridge.ts): `apps/api/src/agent/bridge.ts`

### Agent Runtime

- [Agent Runtime](https://github.com/trycompai/crm/blob/release/apps/agent/agent/agent.ts): `apps/agent/agent/agent.ts`
- [Agent Schedule](https://github.com/trycompai/crm/blob/release/apps/agent/agent/schedules/dispatch.ts): `apps/agent/agent/schedules/dispatch.ts`
- [Work Queue](https://github.com/trycompai/crm/blob/release/apps/agent/agent/lib/tasks.ts): `apps/agent/agent/lib/tasks.ts`
- [Agent Tools](https://github.com/trycompai/crm/blob/release/apps/agent/agent/tools/record_fact.ts): `apps/agent/agent/tools/record_fact.ts`
- [Agent Sandbox](https://github.com/trycompai/crm/blob/release/apps/agent/agent/sandbox/sandbox.ts): `apps/agent/agent/sandbox/sandbox.ts`

### Data Integrations

- [CRM Database](https://github.com/trycompai/crm/blob/release/apps/api/src/database/database.module.ts): `apps/api/src/database/database.module.ts`
- [Mailbox Sync](https://github.com/trycompai/crm/blob/release/apps/api/src/sync/mailbox-sync.service.ts): `apps/api/src/sync/mailbox-sync.service.ts`
- [Google Sync](https://github.com/trycompai/crm/blob/release/apps/api/src/google/google-sync.service.ts): `apps/api/src/google/google-sync.service.ts`
- [Microsoft Sync](https://github.com/trycompai/crm/blob/release/apps/api/src/microsoft/microsoft-sync.service.ts): `apps/api/src/microsoft/microsoft-sync.service.ts`

### Tracking Analytics

- [Tracking Script](https://github.com/trycompai/crm/blob/release/apps/app/app/t/%5Bsite%5D/route.ts): `apps/app/app/t/[site]/route.ts`
- [Tracking Ingest](https://github.com/trycompai/crm/blob/release/apps/api/src/tracking/tracking-ingest.service.ts): `apps/api/src/tracking/tracking-ingest.service.ts`
- [Tracking API](https://github.com/trycompai/crm/blob/release/apps/api/src/tracking/tracking.controller.ts): `apps/api/src/tracking/tracking.controller.ts`
- [Analytics Service](https://github.com/trycompai/crm/blob/release/apps/api/src/telemetry/telemetry.service.ts): `apps/api/src/telemetry/telemetry.service.ts`

### Other components

- **CRM User**
- **Google APIs**
- **Microsoft APIs**

## Connections

- CRM User → Web App: uses
- Web App → API Proxy: requests
- API Proxy → CRM API: forwards
- CRM API → Auth Service: authenticates
- CRM Search → CRM Database: reads records
- Conversations → CRM Database: stores conversations
- Enrichment → CRM Database: updates records
- Agent Schedule → Work Queue: leases due work
- Agent Schedule → Agent Runtime: starts sessions
- Agent Runtime → Agent Tools: dispatches tools
- Agent Runtime → Agent Sandbox: uses sandbox
- Agent Tools → CRM Database: writes evidence
- Agent Tools → Work Queue: schedules follow-up
- Agent Bridge → Agent Runtime: calls agent
- Mailbox Sync → Google Sync: runs sync
- Mailbox Sync → Microsoft Sync: runs sync
- Google Sync → Google APIs: reads mail
- Microsoft Sync → Microsoft APIs: reads mail
- Tracking Script → Tracking API: posts events
- Tracking API → Tracking Ingest: dispatches ingest
- Tracking Ingest → CRM Database: stores events
- Tracking Ingest → Enrichment: files submissions
- Analytics Service → CRM Database: reads metrics
