CRM Automation: Lead Scoring
Build a lightweight CRM with automated lead scoring, follow-up sequences, pipeline management, and activity tracking — replacing expensive SaaS tools for small teams.
CRM data model and lead lifecycle
A CRM (Customer Relationship Management) system tracks every interaction with potential and current customers. The core objects are: contacts (people), companies (organisations), deals (potential sales), and activities (emails, calls, meetings, notes). Ask Claude Code: Create a new Node.js project with TypeScript for a CRM system. Define types at src/types.ts for Contact (id, first_name, last_name, email, phone, company_id, job_title, source like website or referral or linkedin, lead_score, status as new or contacted or qualified or customer or churned, tags, created_at, last_contacted_at), Company (id, name, domain, industry, size_range, website, contacts array), Deal (id, contact_id, company_id, title, value, currency, stage as lead or qualified or proposal or negotiation or closed_won or closed_lost, probability, expected_close_date, created_at, updated_at), and Activity (id, contact_id, deal_id optional, type as email or call or meeting or note, subject, body, outcome, created_at). Create sample data at src/data.ts with 20 contacts across 8 companies, 10 deals at various stages, and 30 activities spread across the contacts. Make the data realistic: use real industry names, realistic deal values, and varied activity patterns. Ask Claude Code: Create utility functions at src/crm-utils.ts for: looking up a contact with their company and activities, calculating deal pipeline value by stage, finding contacts with no activity in the last 30 days, and generating a timeline of all activities for a contact sorted by date. These utilities form the foundation that every CRM feature builds on.
Building the lead scoring model
Lead scoring assigns a numerical value to each contact based on how likely they are to become a customer. Higher scores mean higher priority. Ask Claude Code: Create a lead scoring engine at src/lead-scoring.ts. Define scoring rules in two categories. Demographic scoring (who they are): job title contains Director, VP, or C-level adds 20 points. Company size over 50 employees adds 15 points. Industry matches our target verticals adds 10 points. Has a company email domain (not gmail, yahoo, hotmail) adds 5 points. Behavioural scoring (what they have done): visited pricing page adds 15 points. Downloaded a resource adds 10 points. Attended a webinar adds 10 points. Opened 3 or more emails adds 5 points. Replied to an email adds 20 points. Requested a demo adds 30 points. No activity in 30 days subtracts 10 points. No activity in 60 days subtracts 20 points. The scoring function should take a contact with their activities and return the total score with a breakdown showing which rules fired and how many points each contributed. Scores classify into bands: cold (0-25), warm (26-50), hot (51-75), and very hot (76 plus). Ask Claude Code: Run the scoring model against all 20 sample contacts. Show the results sorted by score with the score breakdown for each. Verify the model produces reasonable rankings — a VP who requested a demo should score higher than a junior employee who only opened one email. Ask Claude Code: Add score decay — reduce scores by 5 points every 30 days of inactivity. This ensures that old leads do not stay hot forever. Create a function that recalculates all scores and flags contacts whose classification changed (for example, from hot to warm). Send a notification when a lead moves to very hot status so the sales team can act immediately.
Automated follow-up sequences
Consistent follow-up is what separates successful sales from missed opportunities. Most deals require 5 to 12 touchpoints. Ask Claude Code: Create a follow-up automation system at src/sequences.ts. Define a Sequence type with: name, trigger condition (when does this sequence start), steps as an array of Step objects (delay in days from previous step, action type as email or task or notification, template name, and conditions for skipping this step). Create three sequences. New Lead sequence triggered when a contact is created from the website: Day 0 send welcome email, Day 2 send value proposition email, Day 5 create a task to make a phone call, Day 10 send case study email, Day 15 send a final follow-up email. If the contact replies at any point, stop the sequence and create a task for personal follow-up. Demo Request sequence triggered when a contact requests a demo: Day 0 send confirmation with calendar link, Day 1 create a task to prepare for the demo, Day 3 if demo not scheduled send a reminder email, Day 7 if demo completed send follow-up with proposal. Inactive Customer sequence triggered when an existing customer has no activity for 60 days: Day 0 send check-in email, Day 14 send product update email, Day 30 create a task for personal outreach. Ask Claude Code: Create a sequence runner that processes all active sequences daily. For each contact in a sequence, check which step they are on, whether enough time has passed for the next step, whether any skip conditions are met, and execute the action (send email, create task, or send notification). Log every action. Handle edge cases: what if a contact is in two sequences simultaneously (prioritise the more specific one), what if an email bounces (pause the sequence and flag for review).
Pipeline management and visualisation
The sales pipeline shows all deals and their progress from first contact to closed. Ask Claude Code: Create a pipeline visualisation at src/pipeline.ts that generates an HTML dashboard. The pipeline should show deals as cards arranged in columns by stage: Lead, Qualified, Proposal, Negotiation, Closed Won, Closed Lost. Each card shows the deal title, company name, value, expected close date, and the number of days in the current stage. Cards should be colour-coded by age: green for under 14 days in the current stage, yellow for 14 to 30 days, and red for over 30 days (stale deals need attention). Show pipeline summary statistics at the top: total pipeline value, weighted pipeline value (each deal's value multiplied by its stage probability), average deal size, average time to close for won deals, and win rate as a percentage of closed deals that were won. Ask Claude Code: Add a pipeline velocity metric. Calculate the speed at which deals move through stages: average days per stage, bottleneck stage (where deals spend the longest), and conversion rate between each pair of adjacent stages. If 80 percent of deals pass from Qualified to Proposal but only 30 percent pass from Proposal to Negotiation, the Proposal stage is the bottleneck — your proposals need improvement. Create a forecast based on the pipeline. For each deal, calculate the expected revenue by multiplying the deal value by the stage probability. Sum these for the total weighted forecast. Group by expected close month for a monthly revenue forecast. Compare the forecast to actual closed revenue to measure forecast accuracy over time. Ask Claude Code: Add deal activity tracking. When a deal changes stage, log the transition with the date, previous stage, new stage, and reason. Show the stage history on each deal card. Calculate stage duration: how long did this deal spend in each stage compared to the average? Deals that move faster than average are likely to close. Deals that linger are at risk.
Activity tracking and contact timeline
Every interaction with a contact should be logged for context. Ask Claude Code: Create an activity logging system at src/activities.ts. Build functions to: log an email sent or received (extract the contact from the email address, create an activity with the subject and body), log a phone call (contact, duration, outcome as connected or voicemail or no_answer, and notes), log a meeting (contact, attendees, agenda, notes, and follow-up actions), and log a note (free-form text about a contact or deal). Each activity is linked to a contact and optionally to a deal. Create a contact timeline view that shows all activities for a contact in chronological order. Ask Claude Code: Build a daily activity report generator. At the end of each day, produce a summary showing: activities completed today by type (5 emails, 3 calls, 1 meeting), contacts touched today, deals progressed (stage changes), and tomorrow's planned activities (from sequence-generated tasks and calendar). Format as both an HTML report for browser viewing and a plain text email for inbox delivery. Ask Claude Code: Add email integration. Create a script that reads emails from a dedicated mailbox (using IMAP), matches them to contacts by email address, creates activity records, and updates the contact's last_contacted_at timestamp. When an email from an unknown address arrives, create a new contact automatically with the information available from the email headers and signature. This email integration ensures the CRM stays up to date without manual data entry — the most common reason CRMs fail is that people stop updating them. Ask Claude Code: Create a contact enrichment function. Given a contact's email address, extract the domain, look up the company website, and attempt to find the company name, industry, and size from publicly available sources. This automates the research that sales teams typically do manually for each new lead.
Reporting and analytics
Data-driven decisions require clear reporting. Ask Claude Code: Create a comprehensive CRM reporting system at src/reports.ts. Build five core reports. Sales Performance: total revenue closed this month, quarter, and year. Breakdown by sales stage, by source, and by industry. Compare to the same period last year if data exists. Show a trend chart of monthly closed revenue. Lead Source Analysis: for each source (website, referral, LinkedIn, events), show the number of leads, the conversion rate to customer, the average deal value, and the time to close. This reveals which sources produce the highest quality leads. Activity Metrics: calls made, emails sent, meetings held, and proposals sent per week. Show the correlation between activity volume and closed deals — does more activity actually drive more revenue? Pipeline Health: total pipeline value, number of stale deals, stage conversion rates, and forecast accuracy. A healthy pipeline has a consistent flow of new deals entering and won or lost deals exiting. Customer Concentration: percentage of revenue from the top 5 clients. High concentration is a risk — if your largest client leaves, what happens to revenue? Ask Claude Code: Generate all five reports as an HTML dashboard with charts. Use the sample data to produce realistic-looking reports. Add a date range selector that filters all reports to the selected period. Add an export button that downloads the data as CSV for import into spreadsheets. Ask Claude Code: Add a weekly email digest that sends the key metrics to the team every Monday morning. Include: last week's wins (closed deals), this week's pipeline (deals expected to close), stale deals needing attention, and top leads by score. Keep it concise — the email should be scannable in 30 seconds.
Deploying and scaling the CRM
Move from a local tool to a web application the team can use. Ask Claude Code: Convert the CRM into a Next.js web application. Create pages for: a dashboard showing pipeline, key metrics, and recent activity; a contacts list with search, filtering by status and score, and sorting; individual contact pages with the timeline, deals, and activity log; a deals board with the pipeline visualisation; and a reports page with the analytics dashboard. Move the data storage from JSON files to a PostgreSQL database. Create a schema with tables for contacts, companies, deals, activities, and sequences. Write migration scripts. Add simple authentication (email and password) so multiple team members can use the CRM. Track which user performed each activity for accountability. Deploy to Vercel (frontend) and Railway (database). Ask Claude Code: Add real-time updates using server-sent events. When one team member adds an activity or moves a deal, other team members see the update without refreshing. This prevents conflicts where two people call the same lead because neither knew the other had already made contact. Ask Claude Code: Add data import and export. Create an import function that reads contacts from a CSV file (the format exported by most CRMs and spreadsheet tools). Map CSV columns to contact fields with a preview showing the first 5 rows before importing. Add duplicate detection: if a contact with the same email already exists, offer to merge or skip. Create an export function that exports all data as CSV files grouped by entity type. This ensures you are never locked into the tool — your data is always portable. The CRM is now a complete system that can replace tools costing 50 to 200 dollars per month per user. For a small team of 3 to 5 people, that is a significant saving — and you have full control over the features and data.
AI for Sales and Marketing
This guide is hands-on and practical. The full curriculum covers the conceptual foundations in depth with structured lessons and quizzes.
Go to lesson