# Development Guidelines

## Philosophy

**Build systems that run themselves, not features for users.** Focus on automation over manual work. Every line of code should multiply your earning potential or reduce operational overhead.

## Development Workflow

1. **Start Small**: Build minimum viable automation for each workflow
2. **Test Locally**: Use ngrok, Stripe CLI, and test accounts
3. **Iterate Fast**: Deploy to staging, test with real data patterns
4. **Automate Everything**: If you do it twice, build a workflow

## n8n Development Patterns

### Workflow Structure
```
TRIGGER → VALIDATE → TRANSFORM → ACTION → NOTIFY → ERROR_HANDLING
```

### Naming Conventions
- Workflows: `SNAKE_CASE-action-description` 
  - `typeform-qualification-to-pipedrive`
  - `stripe-webhook-to-invoicing`
- Nodes: `Verb-Noun` 
  - `Check-Stripe-Signature`
  - `Create-Notion-Page`

### Error Handling
- Always add error branches
- Log errors with context (lead ID, client name)
- Send notifications to you for critical failures
- Use webhook delays for retry (exponential backoff)

## Data Flow Rules

### Lead Flow
```
Typeform Submission → 
Validate Data → 
Create Pipedrive Deal → 
Check Scoring → 
Add to Notion Project → 
Send Welcome Email
```

### Booking Flow
```
Calendly Booking → 
Webhook to Pipedrive → 
Create/Clone Project Template → 
Send Confirmation → 
Add to Dashboard
```

### Financial Flow
```
Stripe Webhook → 
Validate Event → 
Update Project Status → 
Generate Next Invoice (if milestone complete) → 
Send to Client → 
Update Dashboard
```

## Anti-Patterns to Avoid

❌ Building custom booking systems (use Calendly)
❌ Building custom CRMs (use Pipedrive)
❌ Manual invoice creation
❌ Email sequences without tracking
❌ Dashboard that requires manual updates
❌ Projects that don't auto-archive
❌ Recurring tasks without automation

## Tool Integration Priorities

1. **Must Have Auto**: Stripe, Calendly, Pipedrive
2. **Should Have Auto**: Notion, SendGrid, GitHub
3. **Nice to Have Auto**: Slack, Discord, Telegram
4. **Manual When**: Client requires custom solution

## Performance Targets

- Dashboard data refresh: < 1 minute
- Webhook response time: < 2 seconds
- Email send confirmation: within 5 seconds
- n8n workflow completion: < 30 seconds
- Database query: < 100ms for reads

## Security First

- All webhooks must verify signatures
- Environment variables for all secrets
- No hardcoded credentials anywhere
- Stripe webhook signing key required
- Calendly webhook verification enabled
- Regular credential rotation schedule

## Backup Strategy

- Daily: Database dump to S3
- Weekly: Full system state backup
- Monthly: Test restore from backup
- Always: Code in Git (obviously)