Technical SpecsSales Specs
Leads Architecture
Technical specification for Lead Management.
Leads Architecture
Data Model
The lead object represents a prospect. It serves as a staging area before conversion to account, contact, and opportunity.
// packages/crm/src/lead.object.ts
export default {
name: 'lead',
fields: {
...standardFields,
company: { type: 'text', required: true },
status: {
type: 'select',
options: ['New', 'Working', 'Nurturing', 'Converted', 'Disqualified'],
default: 'New'
},
lead_source: { type: 'text' },
annual_revenue: { type: 'currency' },
rating: { type: 'select', options: ['Hot', 'Warm', 'Cold'] },
score: { type: 'number', default: 0 }
}
}Lead Conversion Service
The conversion process is transactional and irreversible.
Input:
lead_idowner_id(optional)create_opportunity(boolean)
Logic:
- Validate: Check if
statusis already 'Converted'. - Transact:
- Create
accountfromcompanyname. - Create
contactlinked toaccount. - (Optional) Create
opportunitylinked toaccount. - Update
lead: Setstatus= 'Converted',is_converted= true.
- Create
- Return: IDs of created records.
Assignment Rules Engine
Implemented via lead.hook.ts on beforeInsert.
// Pseudo-code for assignment logic
if (!doc.owner) {
const rules = await broker.find('assignment_rule', { active: true });
for (const rule of rules) {
if (matches(doc, rule.criteria)) {
doc.owner = rule.assign_to;
break;
}
}
}