# diegovasquez-ai/builder-crm architecture

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

- Interactive diagram: https://gitdiagram.com/diegovasquez-ai/builder-crm
- Repository: https://github.com/diegovasquez-ai/builder-crm

## Overview

Builder CRM is a self-hosted agentic CRM: people manage contacts and sales pipelines while an AI agent handles inbound conversations, updates lead records, and can hand work to an adviser. The main flow runs from a connected messaging channel through ingestion and the agent to CRM state and replies. Other major branches cover team access, automations, reporting, and customer-specific modules. Edges use README statements or shown source references; unsampled implementation details are not inferred.

Main entry points: [`src/db/schema.ts`](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/db/schema.ts) (CRM database), [`src/lib/agent/index.ts`](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/agent/index.ts) (AI agent), [`src/app/api/contacts/route.ts`](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/app/api/contacts/route.ts) (Contact management), [`src/lib/channels/ingest.ts`](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/channels/ingest.ts) (Message ingestion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_messaging["Messaging and agent"]
  node_webhook["WhatsApp webhook<br/>[route.ts]"]
  node_ingest["Message ingestion<br/>[ingest.ts]"]
  node_agentqueue["Agent queue<br/>[queue.ts]"]
  node_agent["AI agent<br/>[index.ts]"]
  node_inbox["Conversation inbox"]
end

subgraph group_crm["CRM workflow"]
  node_contacts["Contact management<br/>[route.ts]"]
  node_pipeline["Sales pipeline"]
  node_activities["Activities<br/>[route.ts]"]
  node_documents["Contact documents<br/>[documents.ts]"]
end

subgraph group_access["Access and configuration"]
  node_auth["Member access<br/>[api-auth.ts]"]
  node_team["Team and roles<br/>[team.ts]"]
end

subgraph group_automation["Automation and insights"]
  node_automations["Automations<br/>[index.ts]"]
  node_reports["Reports and dashboard<br/>[reportes.ts]"]
  node_simulator["Agent simulator<br/>[simulador.ts]"]
end

subgraph group_modules["Customer modules"]
  node_properties["Property search<br/>[busqueda.ts]"]
  node_visits["Visit scheduling<br/>[servidor.tsx]"]
  node_moduleconfig["Customer modules<br/>[cliente.ts]"]
end

node_user(("CRM user"))
node_channels{{"Messaging channels"}}
node_openrouter{{"OpenRouter"}}
node_database[("CRM database<br/>[schema.ts]")]

node_channels -->|"sends events"| node_webhook
node_webhook -->|"upserts messages"| node_ingest
node_ingest -->|"enqueues job"| node_agentqueue
node_ingest -->|"writes conversations"| node_database
node_agentqueue -->|"stores jobs"| node_database
node_agentqueue -.->|"dispatches work"| node_agent
node_agent -.->|"requests inference"| node_openrouter
node_agent -->|"updates lead"| node_contacts
node_agent -->|"moves stages"| node_pipeline
node_agent -->|"records activity"| node_activities
node_agent -->|"replies in"| node_inbox
node_inbox -->|"sends replies"| node_channels
node_user -->|"handles conversations"| node_inbox
node_user -->|"manages leads"| node_contacts
node_contacts -->|"reads and writes"| node_database
node_contacts -->|"requires member"| node_auth
node_auth -->|"checks membership"| node_team
node_team -->|"reads members"| node_database
node_pipeline -->|"loads pipeline data"| node_database
node_user -->|"configures rules"| node_automations
node_automations -.->|"persists runs"| node_database
node_user -->|"views results"| node_reports
node_user -->|"tests agent"| node_simulator
node_user -->|"manages documents"| node_documents
node_user -->|"configures modules"| node_moduleconfig
node_moduleconfig -->|"enables module"| node_properties
node_moduleconfig -->|"enables module"| node_visits
node_properties -.->|"uses property data"| node_database
node_visits -.->|"uses visit data"| node_database

click node_database "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/db/schema.ts"
click node_webhook "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/app/api/webhooks/whatsapp/route.ts"
click node_ingest "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/channels/ingest.ts"
click node_agentqueue "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/agent/queue.ts"
click node_agent "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/agent/index.ts"
click node_inbox "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/components/conversations/ConversationView.tsx"
click node_contacts "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/app/api/contacts/route.ts"
click node_pipeline "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/components/pipeline/PipelineWorkspace.tsx"
click node_activities "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/app/api/activities/route.ts"
click node_documents "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/documents.ts"
click node_auth "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/api-auth.ts"
click node_team "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/team.ts"
click node_automations "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/automations/index.ts"
click node_reports "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/reportes.ts"
click node_simulator "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/simulador.ts"
click node_properties "https://github.com/diegovasquez-ai/builder-crm/blob/main/modules/propiedades/lib/busqueda.ts"
click node_visits "https://github.com/diegovasquez-ai/builder-crm/blob/main/modules/visitas/servidor.tsx"
click node_moduleconfig "https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/modules/cliente.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_webhook,node_ingest,node_agentqueue,node_agent,node_inbox,node_user toneBlue
class node_contacts,node_pipeline,node_activities,node_documents,node_database toneAmber
class node_auth,node_team,node_openrouter toneMint
class node_automations,node_reports,node_simulator toneRose
class node_properties,node_visits,node_moduleconfig,node_channels toneIndigo
```

## Components

### Messaging and agent

- [WhatsApp webhook](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/app/api/webhooks/whatsapp/route.ts): `src/app/api/webhooks/whatsapp/route.ts`
- [Message ingestion](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/channels/ingest.ts): `src/lib/channels/ingest.ts`
- [Agent queue](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/agent/queue.ts): `src/lib/agent/queue.ts`
- [AI agent](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/agent/index.ts): `src/lib/agent/index.ts`
- [Conversation inbox](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/components/conversations/ConversationView.tsx): `src/components/conversations/ConversationView.tsx`

### CRM workflow

- [Contact management](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/app/api/contacts/route.ts): `src/app/api/contacts/route.ts`
- [Sales pipeline](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/components/pipeline/PipelineWorkspace.tsx): `src/components/pipeline/PipelineWorkspace.tsx`
- [Activities](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/app/api/activities/route.ts): `src/app/api/activities/route.ts`
- [Contact documents](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/documents.ts): `src/lib/documents.ts`

### Access and configuration

- [Member access](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/api-auth.ts): `src/lib/api-auth.ts`
- [Team and roles](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/team.ts): `src/lib/team.ts`

### Automation and insights

- [Automations](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/automations/index.ts): `src/lib/automations/index.ts`
- [Reports and dashboard](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/reportes.ts): `src/lib/reportes.ts`
- [Agent simulator](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/simulador.ts): `src/lib/simulador.ts`

### Customer modules

- [Property search](https://github.com/diegovasquez-ai/builder-crm/blob/main/modules/propiedades/lib/busqueda.ts): `modules/propiedades/lib/busqueda.ts`
- [Visit scheduling](https://github.com/diegovasquez-ai/builder-crm/blob/main/modules/visitas/servidor.tsx): `modules/visitas/servidor.tsx`
- [Customer modules](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/lib/modules/cliente.ts): `src/lib/modules/cliente.ts`

### Other components

- **CRM user**
- **Messaging channels**
- **OpenRouter**
- [CRM database](https://github.com/diegovasquez-ai/builder-crm/blob/main/src/db/schema.ts): `src/db/schema.ts`

## Connections

- Messaging channels → WhatsApp webhook: sends events
- WhatsApp webhook → Message ingestion: upserts messages (evidence: `src/app/api/webhooks/whatsapp/route.ts`)
- Message ingestion → Agent queue: enqueues job (evidence: `src/lib/channels/ingest.ts`)
- Message ingestion → CRM database: writes conversations (evidence: `src/lib/channels/ingest.ts`)
- Agent queue → CRM database: stores jobs (evidence: `src/lib/agent/queue.ts`)
- Agent queue → AI agent: dispatches work
- AI agent → OpenRouter: requests inference
- AI agent → Contact management: updates lead
- AI agent → Sales pipeline: moves stages
- AI agent → Activities: records activity
- AI agent → Conversation inbox: replies in
- Conversation inbox → Messaging channels: sends replies
- CRM user → Conversation inbox: handles conversations
- CRM user → Contact management: manages leads
- Contact management → CRM database: reads and writes (evidence: `src/app/api/contacts/route.ts`)
- Contact management → Member access: requires member (evidence: `src/app/api/contacts/route.ts`)
- Member access → Team and roles: checks membership (evidence: `src/lib/api-auth.ts`)
- Team and roles → CRM database: reads members (evidence: `src/lib/team.ts`)
- Sales pipeline → CRM database: loads pipeline data
- CRM user → Automations: configures rules
- Automations → CRM database: persists runs
- CRM user → Reports and dashboard: views results
- CRM user → Agent simulator: tests agent
- CRM user → Contact documents: manages documents
- CRM user → Customer modules: configures modules
- Customer modules → Property search: enables module
- Customer modules → Visit scheduling: enables module
- Property search → CRM database: uses property data
- Visit scheduling → CRM database: uses visit data
