Cursor Rules Template: Lead Qualification Workflows for Agencies and Consultants
Cursor Rules Template for building AI-driven lead qualification workflows on Node.js/Express with PostgreSQL and TypeORM.
Target User
Developers building AI-driven lead qualification pipelines for agencies and consultants using Node.js/Express, PostgreSQL, and TypeORM.
Use Cases
- Automate initial lead qualification steps
- Score and route leads to sales teams
- Enrich CRM data via AI-driven prompts
- Automate outreach sequencing with qualification outcomes
Markdown Template
Cursor Rules Template: Lead Qualification Workflows for Agencies and Consultants
.cursorrules
Framework Role & Context: You are Cursor AI assistant configured for a Node.js/Express + PostgreSQL + TypeORM stack. You specialize in building AI-led lead qualification workflows for agencies and consultants. Your focus is on deterministic, auditable, and secure automation that integrates with REST APIs and the database layer.
Code Style and Style Guides: Use TypeScript, ESLint with Airbnb TS rules, and Prettier. Enforce 2-space indentation, semicolons, explicit types, and consistent import ordering. Prefer explicit interfaces over any and avoid any in business logic.
Architecture & Directory Rules: Organize code under /src with subfolders: /controllers, /services, /repositories, /entities, /routes, /middlewares, /config, /workflows, /tests. Migrations live in /src/migrations. Do not place service logic in controllers. Export service results through DTOs.
Authentication & Security Rules: Implement JWT authentication via Passport.js; verify tokens on protected endpoints; store secrets in environment variables; enforce HTTPS in production; apply rate limiting and input validation to prevent abuse.
Database and ORM patterns: Use PostgreSQL with TypeORM. Define Lead, QualificationRule, and LeadWorkflow entities. Use the repository pattern, migrations for schema changes, and database transactions for qualification steps. Avoid lazy relations in hot paths; index fields used in queries; map domain models to persistence models with DTOs.
Testing & Linting Workflows: Jest for unit tests; SuperTest for API tests; integrate ESLint/Prettier checks in CI; enforce pre-commit linting with Husky; run tests in GitHub Actions on push and pull_request.
Prohibited Actions and Anti-patterns for the AI: Do not spawn blocking external AI calls on request threads; do not log secrets or PII; do not bypass validation; do not mutate global state; avoid relying on fuzzy prompts for critical routing decisions; never write to the database outside a transaction unless intended.Overview
This Cursor Rules Template is tailored for building AI-driven lead qualification workflows on a Node.js/Express stack with PostgreSQL and TypeORM. It targets agencies and consultants who automate initial discovery, scoring, and routing of inquiries to human agents or CRM systems using Cursor AI methods. Paste the included .cursorrules block into your project root and adapt to your data models, auth strategy, and workflow orchestration.
When to Use These Cursor Rules
- You are implementing an AI-assisted lead qualification flow for multiple clients in a consulting or agency model.
- You need deterministic, logged, and testable AI-driven scoring and routing decisions.
- You require separation of concerns between controllers, services, and ORM entities for maintainability at scale.
- You want safe fallbacks if AI prompts fail or external services are unavailable.
- You must enforce strict input validation, authentication, and audit trails in production.
Copyable .cursorrules Configuration
.cursorrules
Framework Role & Context: You are Cursor AI assistant configured for a Node.js/Express + PostgreSQL + TypeORM stack. You specialize in building AI-led lead qualification workflows for agencies and consultants. Your focus is on deterministic, auditable, and secure automation that integrates with REST APIs and the database layer.
Code Style and Style Guides: Use TypeScript, ESLint with Airbnb TS rules, and Prettier. Enforce 2-space indentation, semicolons, explicit types, and consistent import ordering. Prefer explicit interfaces over any and avoid any in business logic.
Architecture & Directory Rules: Organize code under /src with subfolders: /controllers, /services, /repositories, /entities, /routes, /middlewares, /config, /workflows, /tests. Migrations live in /src/migrations. Do not place service logic in controllers. Export service results through DTOs.
Authentication & Security Rules: Implement JWT authentication via Passport.js; verify tokens on protected endpoints; store secrets in environment variables; enforce HTTPS in production; apply rate limiting and input validation to prevent abuse.
Database and ORM patterns: Use PostgreSQL with TypeORM. Define Lead, QualificationRule, and LeadWorkflow entities. Use the repository pattern, migrations for schema changes, and database transactions for qualification steps. Avoid lazy relations in hot paths; index fields used in queries; map domain models to persistence models with DTOs.
Testing & Linting Workflows: Jest for unit tests; SuperTest for API tests; integrate ESLint/Prettier checks in CI; enforce pre-commit linting with Husky; run tests in GitHub Actions on push and pull_request.
Prohibited Actions and Anti-patterns for the AI: Do not spawn blocking external AI calls on request threads; do not log secrets or PII; do not bypass validation; do not mutate global state; avoid relying on fuzzy prompts for critical routing decisions; never write to the database outside a transaction unless intended.
Recommended Project Structure
/src
/controllers
/services
/repositories
/entities
/routes
/middlewares
/config
/workflows
/tests
/migrations
.env
package.json
tsconfig.json
jest.config.js
Core Engineering Principles
- Explicit data contracts and typed inputs/outputs for all API endpoints and workflow steps.
- Idempotent, deterministic qualification steps with clear rollback paths.
- Safe AI-assisted decision making with explicit fallbacks and human review when uncertain.
- Observability: structured logs, metrics, and tracing for all AI-driven decisions.
- Strong validation, error handling, and clear boundary between domain logic and infrastructure.
- Security by design: least privilege access, secrets management, and data privacy controls.
Code Construction Rules
- Use DTOs for all inputs; validate with class-validator and class-transformer; map to domain models via mappers.
- Encapsulate lead qualification logic in a dedicated service layer; controllers should delegate to services only.
- Define TypeORM entities with explicit relations, indexes on lookup fields, and migration-based schema changes.
- Prompts and AI prompts must be parameterized; store prompt templates in a config module and load at runtime.
- Handle errors with standardized error responses and do not leak internal error details to clients.
Security and Production Rules
- Use TLS, rotate secrets regularly, and store credentials in a vault or environment manager.
- Enable rate limiting, input validation, and CSRF protection for API routes; enforce CORS policies for clients.
- Audit logs for AI-driven decisions; redact PII in logs; maintain an immutable record of qualification outcomes.
- Configure proper database connection pooling and timeouts; isolate AI call latency with fallbacks.
Testing Checklist
- Unit tests for validators, mappers, and workflow services.
- Integration tests for API endpoints performing lead intake and qualification routing.
- End-to-end tests that simulate AI-driven decision paths with mocked prompts.
- CI checks for lint, tests, type checks, and build artifacts.
- Security tests including input validation, auth flows, and rate limiting behavior.
Common Mistakes to Avoid
- Mixing business logic into routing layers or controllers.
- Skipping input validation or failing to handle edge cases in lead data.
- Hardcoding secrets or using unsafe defaults in production configs.
- Directly calling external AI services in hot paths without timeouts or fallbacks.
- Neglecting migrations and schema changes in production environments.
Related implementation resources: AI Agent Use Case for Agencies Using Inbound Leads to Qualify Prospects Before Sales Calls and Designing thin, production-grade API controller routes that delegate logic to separate service layers.
FAQ
What stack does this Cursor Rules Template cover?
This template targets Node.js with Express, PostgreSQL, and TypeORM to implement AI-driven lead qualification workflows for agencies and consultants. It focuses on secure API design, typed data contracts, and reliable orchestration of AI prompts within a SQL-backed data model.
How do I apply this as a copyable .cursorrules block?
Copy the code block from the Copyable .cursorrules Configuration section and paste it into a root .cursorrules file in your project. Ensure the slug in your page path matches the template slug, then reference it from Cursor AI during rule evaluation.
What should I customize first?
Begin by defining your Lead, QualificationRule, and LeadWorkflow entities. Then implement a LeadService to orchestrate qualification steps and ensure prompts are parameterized and testable. Finally, wire in API routes and authentication middleware.
How do I test the AI-driven lead qualification safely?
Use a staging environment with mock AI responses and synthetic lead data. Wrap AI calls behind feature flags, mock responses in tests, and verify input/output contracts through unit and integration tests.
What are common mistakes to avoid?
Avoid combining routing with business logic, bypassing validations, exposing secrets in logs, and performing blocking AI calls in request paths. Maintain clear separation of concerns and thorough validation throughout the stack.