# CRM App Improvement Specification
## Current State Analysis
The CRM app (`botui/ui/suite/crm/crm.html`) provides basic customer relationship management with:
- Pipeline view (Lead → Qualified → Proposal → Negotiation → Won/Lost)
- Deals, Accounts, Contacts, Campaigns tabs
- Lead form with basic fields
- Drag-and-drop pipeline cards
- HTMX-based data loading
## Critical Issues to Fix
### 1. Broken API Endpoints
**Problem:** Mixed endpoint patterns causing 404s
- Pipeline uses `/api/ui/crm/pipeline` (correct)
- Counts use `/api/ui/crm/count` AND `/api/crm/count` (inconsistent)
- Deals use `/api/ui/crm/deals` (correct)
- Stage updates use `/api/crm/opportunity/{id}/stage` (missing `/ui/`)
**Fix:**
```html
0000
```
**Action:** Standardize ALL endpoints to `/api/ui/crm/*` pattern.
### 2. Missing Deal Card Template
**Problem:** Pipeline loads empty - no HTML template for deal cards returned by API
**Fix:** Backend must return HTML fragments like:
```html
{{title}}
${{value}}
{{company}}
{{contact_name}}
```
**Action:** Create `botserver/src/ui/crm/templates/deal_card.html` and render in API response.
### 3. Drag-and-Drop Not Working
**Problem:** Cards need `draggable="true"` and proper event handlers
**Fix:**
```javascript
// Add to pipeline card template
// Update drop handler
column.addEventListener('drop', async (e) => {
e.preventDefault();
const cardId = e.dataTransfer.getData('text/plain');
const newStage = column.closest('.pipeline-column').dataset.stage;
const token = localStorage.getItem('gb_token');
await fetch(`/api/ui/crm/opportunity/${cardId}/stage`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
},
body: JSON.stringify({ stage: newStage })
});
// Refresh pipeline
htmx.trigger('#crm-pipeline-view', 'refresh');
});
```
### 4. Form Validation Missing
**Problem:** Lead form submits incomplete data
**Fix:**
```html
```
## Major Improvements Needed
### 5. Activity Timeline
**What:** Show interaction history for each deal/contact
**Implementation:**
```html