The n8n automation workflow system has been successfully implemented for the YC Company Evaluation platform. This allows you to use n8n Cloud to handle AI-powered evaluations and report generation without exposing your backend API publicly.
AI Integration (backend/ai/):
claudeAPI.js- Claude API client with retry logic and token trackingevaluationLogic.js- Company evaluation logic with 6 metricsreportGeneration.js- Markdown report generationprompts/evaluationPrompt.js- Dynamic evaluation prompt generatorprompts/reportPrompt.js- Report generation prompt templateutils/tokenTracker.js- Token usage monitoring
Scraping (backend/scraping/):
ycScraper.js- YC company directory scraper (Puppeteer-based)utils/retryLogic.js- Exponential backoff retry utility
Services:
services/n8nWorkflowService.js- n8n webhook trigger service
Controllers & Routes:
controllers/workflowController.js- Workflow API logicroutes/workflows.js- Workflow API endpoints
Three production-ready workflows in backend/n8n/workflows/:
-
evaluate-company.json
- Evaluates companies across 6 metrics
- Returns structured JSON with scores and explanations
- Supports historical examples for few-shot learning
-
generate-report.json
- Generates comprehensive markdown reports
- Includes company overview, team, product, market analysis
- Returns formatted markdown
-
re-evaluate-company.json
- Re-evaluates companies with change detection
- Compares against previous evaluations
- Tracks score changes
New workflow endpoints (all require authentication):
POST /api/companies/:id/workflows/evaluate - Trigger evaluation
POST /api/companies/:id/workflows/re-evaluate - Re-evaluate company
POST /api/companies/:id/workflows/generate-report - Generate report
GET /api/companies/:id/workflows/check-completeness - Check data completeness
POST /api/companies/:id/workflows/detect-changes - Detect changes
GET /api/workflows/n8n-status - Get n8n config status
Comprehensive documentation created:
- AI_AUTOMATION_README.md - Main documentation (you're here!)
- backend/n8n/N8N_SETUP_GUIDE.md - Step-by-step n8n Cloud setup
- backend/n8n/README.md - Quick reference for workflows
┌─────────────────────────────────────────────────┐
│ Your Computer (localhost) │
│ │
│ ┌──────────────┐ │
│ │ Backend │ │
│ │ (port 3000) │ │
│ └──────┬───────┘ │
│ │ │
│ │ POST webhook with ALL data │
│ │ (company data, config, API key, etc.) │
└─────────┼────────────────────────────────────────┘
│
↓ HTTPS
┌─────────────────────────────────────────────────┐
│ n8n Cloud (public) │
│ │
│ ┌──────────────┐ │
│ │ Webhook │ │
│ │ Receives │ │
│ │ Data │ │
│ └──────┬───────┘ │
│ │ │
│ ↓ │
│ ┌──────────────┐ │
│ │ Claude API │ │
│ │ Call │ │
│ └──────┬───────┘ │
│ │ │
│ ↓ │
│ ┌──────────────┐ │
│ │ Return │ │
│ │ Results │ (synchronous response) │
│ └──────┬───────┘ │
└─────────┼────────────────────────────────────────┘
│
↓ HTTPS response
┌─────────────────────────────────────────────────┐
│ Your Computer (localhost) │
│ │
│ ┌──────────────┐ │
│ │ Backend │ │
│ │ Saves result │ │
│ │ to database │ │
│ └──────────────┘ │
└─────────────────────────────────────────────────┘
Key Point:
- Backend makes ONE request to n8n with ALL data
- n8n processes everything (including Claude API call)
- n8n returns result synchronously
- Backend NEVER needs to be publicly accessible
- No webhooks back to backend needed
cd backend
npm installDependencies added:
@anthropic-ai/sdkaxiospuppeteercheerio
- Go to https://console.anthropic.com/
- Create an account or sign in
- Navigate to API Keys
- Create a new API key
- Copy the key (starts with
sk-ant-api03-)
- Go to https://n8n.io/cloud
- Sign up for a free account
- Create a workspace
- In n8n, go to Credentials (left sidebar)
- Click + Add Credential
- Search for "Anthropic"
- Select Anthropic API
- Configure:
- Name:
Anthropic API(exact name!) - API Key: Your Claude API key
- Name:
- Click Save
- In n8n, go to Workflows
- Click + Add Workflow
- Click ⋯ (menu) → Import from File
- Upload
backend/n8n/workflows/evaluate-company.json - Repeat for the other 2 workflows:
generate-report.jsonre-evaluate-company.json
For each workflow:
- Open the workflow
- Click the Webhook node
- Verify the path:
evaluate-companygenerate-reportre-evaluate-company
- Click Activate (toggle in top right)
- Copy the Production URL
Example URL: https://your-instance.app.n8n.cloud/webhook/evaluate-company
From your workflow URLs, extract the base:
Full URL: https://your-instance.app.n8n.cloud/webhook/evaluate-company
Base URL: https://your-instance.app.n8n.cloud/webhook
Important:
- Do NOT include the workflow path (
evaluate-company) - Do NOT include trailing slash
Create or update backend/.env:
# Database (existing)
DB_HOST=localhost
DB_PORT=5432
DB_NAME=yc_company_eval
DB_USER=postgres
DB_PASSWORD=your_password
# JWT (existing)
JWT_SECRET=your_secret_key
JWT_EXPIRES_IN=7d
# Server (existing)
PORT=3000
NODE_ENV=development
# CORS (existing)
ALLOWED_ORIGINS=http://localhost:5173,http://localhost:3001
# ===== NEW: AI & n8n Configuration =====
# Claude API Key (from console.anthropic.com)
CLAUDE_API_KEY=sk-ant-api03-your-key-here
CLAUDE_MODEL=claude-3-5-sonnet-20241022
# n8n Webhook Base URL (from n8n cloud)
# Example: https://your-instance.app.n8n.cloud/webhook
# IMPORTANT: No trailing slash, no workflow path
N8N_WEBHOOK_BASE_URL=https://your-instance.app.n8n.cloud/webhookcd backend
npm run devLook for:
🚀 Server running on http://localhost:3000
📚 Health check: http://localhost:3000/health
curl http://localhost:3000/api/workflows/n8n-status \
-H "Authorization: Bearer YOUR_JWT_TOKEN"Expected response:
{
"success": true,
"data": {
"configured": true,
"webhookBaseUrl": "https://your-instance.app.n8n.cloud/webhook",
"availableWorkflows": [
"evaluate-company",
"re-evaluate-company",
"generate-report",
"batch-evaluate"
]
}
}First, create a company via your existing API or database.
curl -X POST http://localhost:3000/api/companies/1/workflows/evaluate \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"useN8n": true
}'This will:
- Fetch company data from database
- Send to n8n webhook with all required parameters
- n8n calls Claude API
- n8n returns evaluation
- Backend saves evaluation to database
- You receive the evaluation result
- Go to n8n → Executions (left sidebar)
- You should see your workflow execution
- Click on it to see detailed logs
- Verify each node executed successfully
// Frontend code
const response = await fetch('/api/companies/123/workflows/evaluate', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
useN8n: true // Use n8n workflow
})
});
const result = await response.json();
// result.data.evaluation contains the evaluationconst response = await fetch('/api/companies/123/workflows/generate-report', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
useN8n: true,
includeWebsiteScraping: true
})
});
const result = await response.json();
// result.data.report contains markdown report// Check if company has sufficient data
const checkResponse = await fetch('/api/companies/123/workflows/check-completeness', {
headers: { 'Authorization': `Bearer ${token}` }
});
const check = await checkResponse.json();
if (check.data.sufficient) {
// Proceed with evaluation
} else {
// Show user what data is missing
console.log('Missing:', check.data.missingRequired);
}Each company is evaluated on 6 metrics (scored 0-10):
-
Team Quality (0-10)
- Founder experience and track record
- Domain expertise
- Team composition and completeness
- Previous startup experience
-
Market Opportunity (0-10)
- Total addressable market (TAM)
- Market growth rate
- Timing and market readiness
- Competitive landscape
-
Product Innovation (0-10)
- Uniqueness of solution
- Technical difficulty and moat
- Competitive advantages
- IP and defensibility
-
Traction (0-10)
- Customer adoption metrics
- Revenue and growth rate
- User engagement
- Market validation
-
Business Model (0-10)
- Revenue model clarity
- Scalability potential
- Unit economics
- Path to profitability
-
Execution (0-10)
- Progress relative to stage
- Ability to iterate and pivot
- Operational efficiency
- Milestone achievement
Overall Score: Average of all 6 metrics (rounded to 1 decimal)
A company MUST have:
- ✅ Name
- ✅ Description
- ✅ Either website URL OR founders' LinkedIn URLs
For better evaluations, include:
- Sector/category
- Team size
- Funding amount
- Founded date
- Product details
Use the endpoint:
GET /api/companies/:id/workflows/check-completeness
This will tell you if evaluation can proceed and what's missing.
If you don't want to use n8n, you can use direct Claude API integration:
- Skip n8n Cloud setup
- Leave
N8N_WEBHOOK_BASE_URLempty in.env - Only set
CLAUDE_API_KEY
// Set useN8n to false
const response = await fetch('/api/companies/123/workflows/evaluate', {
method: 'POST',
body: JSON.stringify({
useN8n: false // Use direct Claude API
})
});The backend will use the direct Claude API client in backend/ai/claudeAPI.js.
When to use direct mode:
- Testing/development
- n8n is down
- You want to avoid external dependencies
- You're running backend publicly (can handle Claude API calls directly)
When to use n8n mode:
- Production (recommended)
- Backend runs on localhost
- You want visual workflow management
- You need detailed execution logs
Using claude-3-5-sonnet-20241022:
- Input: ~$3 per million tokens
- Output: ~$15 per million tokens
Typical usage per evaluation:
- Input tokens: ~2,000 (company data + prompt)
- Output tokens: ~1,500 (evaluation JSON)
- Cost per evaluation: ~$0.03
For 1,000 evaluations/month: ~$30
- Free tier: 20,000 workflow executions/month
- Starter: $20/month for 100,000 executions
- Pro: $50/month for 500,000 executions
For typical usage (1,000 evaluations/month), free tier is sufficient.
Total monthly cost estimate: $30-50 (mostly Claude API)
Cause: Environment variable not set or backend not restarted
Solution:
- Check
.envfile hasN8N_WEBHOOK_BASE_URL - Restart backend:
npm run dev - Test with:
GET /api/workflows/n8n-status
Cause: Workflow not activated or incorrect URL
Solution:
- Go to n8n → Workflows
- Verify workflow shows "Active" (green toggle)
- Check webhook path in workflow matches:
evaluate-company(notevaluate_companyorevaluateCompany)
- Ensure
N8N_WEBHOOK_BASE_URLhas no trailing slash
Cause: Claude returned invalid JSON or error
Solution:
- Check n8n execution logs (Executions → Click on execution)
- View Claude API node output
- Common causes:
- Invalid API key
- No API credits
- Rate limit hit
- Verify credentials in n8n: Credentials → Anthropic API
Cause: Claude API can take 30-60 seconds
Solution:
- This is normal for complex evaluations
- Default timeout is 5 minutes (300 seconds)
- If timing out, check:
- Network connectivity
- Claude API status
- n8n workflow hasn't paused on error
Cause: Company missing required fields
Solution:
- Use check-completeness endpoint:
GET /api/companies/:id/workflows/check-completeness
- Add missing data to company
- Retry evaluation
- Add "Evaluate Company" button to company detail page
- Show data completeness check before evaluation
- Display evaluation results with metrics
- Add re-evaluation prompt when data changes
- Show report generation progress
// components/CompanyEvaluation.jsx
import { useState } from 'react';
function CompanyEvaluation({ companyId }) {
const [loading, setLoading] = useState(false);
const [evaluation, setEvaluation] = useState(null);
const handleEvaluate = async () => {
setLoading(true);
try {
const response = await fetch(
`/api/companies/${companyId}/workflows/evaluate`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ useN8n: true })
}
);
const result = await response.json();
setEvaluation(result.data.evaluation);
} catch (error) {
console.error('Evaluation failed:', error);
} finally {
setLoading(false);
}
};
return (
<div>
<button onClick={handleEvaluate} disabled={loading}>
{loading ? 'Evaluating...' : 'Evaluate Company'}
</button>
{evaluation && (
<div>
<h2>Overall Score: {evaluation.overall_score}/10</h2>
{evaluation.metrics.map(metric => (
<div key={metric.name}>
<h3>{metric.name}: {metric.score}/10</h3>
<p>{metric.explanation}</p>
</div>
))}
</div>
)}
</div>
);
}Before going to production:
- Secure JWT secret in
.env - Production Claude API key with appropriate limits
- n8n workflows activated and tested
- Webhook authentication enabled (optional but recommended)
- Error handling tested (API failures, timeouts)
- Logging configured for all AI operations
- Monitoring set up for n8n workflow failures
- Rate limiting configured
- Cost tracking implemented
- Backup plan if n8n is down (direct API mode)
You now have:
✅ Backend AI integration - Direct Claude API client with retry logic ✅ n8n workflows - 3 production-ready workflows ✅ API endpoints - Complete workflow management API ✅ Scraping capability - YC company directory scraper ✅ Documentation - Comprehensive guides and examples ✅ Localhost-friendly - No need to expose backend publicly ✅ Flexible - Can use n8n or direct API mode ✅ Production-ready - Error handling, retries, monitoring
The system is designed so your backend stays on localhost while n8n Cloud handles the AI workflows. All data is passed in one request, no callbacks needed.
CLAUDE_API_KEY=sk-ant-api03-...
CLAUDE_MODEL=claude-3-5-sonnet-20241022
N8N_WEBHOOK_BASE_URL=https://your-instance.app.n8n.cloud/webhookPOST /api/companies/:id/workflows/evaluate
POST /api/companies/:id/workflows/generate-report
GET /api/workflows/n8n-status
AI_AUTOMATION_README.md- Main overview (this file)backend/n8n/N8N_SETUP_GUIDE.md- Detailed n8n setupbackend/n8n/README.md- Workflow quick reference
Questions or issues?
- Check the detailed setup guide:
backend/n8n/N8N_SETUP_GUIDE.md - Test n8n status:
GET /api/workflows/n8n-status - View n8n execution logs in the n8n Cloud UI
You're all set! 🎉
Start by testing an evaluation with your first company.