- **Project**: AI information collection & distribution system using n8n workflows
# Cursor Rules for n8n-tweet Project
You are an expert JavaScript developer working on an n8n workflow automation project for AI content collection and Twitter posting. Follow these rules strictly:
## ๐ฏ Project Context
- **Project**: AI information collection & distribution system using n8n workflows
- **Language**: JavaScript ES6+
- **Framework**: n8n workflow automation
- **Testing**: Jest (TDD approach)
- **APIs**: X(Twitter) API v2, RSS/XML parsing
- **Infrastructure**: Docker, GitHub Actions
## ๐งช TDD Development Rules
### Test-First Approach
1. **ALWAYS write tests before implementation** (Red-Green-Refactor cycle)
2. **Write failing tests first**, then implement minimal code to pass
3. **Refactor only after tests pass**
4. **Maintain 85%+ test coverage** for all modules
5. **Use descriptive test names**: `describe("TwitterClient")` โ `it("should post tweet with rate limit handling")`
### Test Structure
```javascript
// Example test structure
describe('FeatureName', () => {
beforeEach(() => {
// Setup for each test
});
describe('when specific condition', () => {
it('should have expected behavior', async () => {
// Arrange
const input = 'test data';
// Act
const result = await functionUnderTest(input);
// Assert
expect(result).toEqual(expectedOutput);
});
});
});
```
## ๐ File Organization Rules
### Directory Structure
- `src/utils/` - Utility functions (logger, error-handler, rate-limiter)
- `src/filters/` - Content filtering logic
- `src/generators/` - Tweet generation
- `src/integrations/` - External API clients
- `src/monitoring/` - Health checks and metrics
- `tests/unit/` - Unit tests (match src/ structure)
- `tests/integration/` - Integration tests
- `config/` - Configuration files (JSON)
- `workflows/` - n8n workflow definitions
### Naming Conventions
- **Files**: kebab-case (`tweet-generator.js`)
- **Classes**: PascalCase (`TwitterClient`)
- **Functions**: camelCase (`generateTweet`)
- **Constants**: SCREAMING_SNAKE_CASE (`MAX_TWEET_LENGTH`)
- **Test files**: `.test.js` suffix (`twitter-client.test.js`)
## ๐ง Code Quality Rules
### JavaScript Best Practices
1. **Use ES6+ features**: async/await, destructuring, arrow functions
2. **Prefer const over let**, never use var
3. **Use template literals** for string interpolation
4. **Implement proper error handling** with try-catch blocks
5. **Use JSDoc comments** for all public functions
### Example Code Structure
```javascript
/**
* Generates optimized tweet from article content
* @param {Object} article - Article object with title, description, url
* @param {string} category - Content category for hashtag selection
* @returns {Promise<string>} Generated tweet text (โค280 chars)
*/
async function generateTweet(article, category) {
try {
// Implementation here
} catch (error) {
logger.error('Tweet generation failed', { article, category, error });
throw new Error(`Tweet generation failed: ${error.message}`);
}
}
```
### Error Handling Patterns
1. **Always catch async errors**
2. **Log errors with context**
3. **Use custom error classes** for different error types
4. **Provide meaningful error messages**
5. **Include error recovery mechanisms**
## ๐ฆ Twitter API Integration Rules
### Rate Limiting
- **Implement rate limiting** for all API calls
- **Use exponential backoff** for retries
- **Track API usage** and respect monthly limits
- **Cache responses** when appropriate
### Tweet Content Rules
- **280 character limit** enforcement
- **Automatic hashtag addition** based on category
- **URL shortening** consideration
- **Emoji usage** for engagement optimization
## ๐ n8n Workflow Rules
### Workflow Design
1. **Create modular workflows** with clear node separation
2. **Use proper error handling nodes**
3. **Implement webhook endpoints** for external triggers
4. **Add logging nodes** for monitoring
5. **Use environment variables** for sensitive data
### Node Configuration
- **Set appropriate timeouts** for HTTP requests
- **Configure retry policies** for failed operations
- **Use proper authentication** for API calls
- **Implement data validation** between nodes
## ๐ Monitoring & Logging Rules
### Logging Standards
```javascript
// Use structured logging
logger.info('RSS feed processed', {
feedUrl: url,
itemsFound: items.length,
itemsFiltered: filtered.length,
duration: Date.now() - startTime
});
```
### Health Checks
- **Implement health check endpoints**
- **Monitor API response times**
- **Track error rates**
- **Set up alerting** for failures
## ๐ Deployment & CI/CD Rules
### GitHub Actions
1. **Run tests on all PRs**
2. **Check test coverage** (must be โฅ85%)
3. **Run linting** (ESLint)
4. **Build Docker images** for production
5. **Deploy to staging** before production
### Docker Configuration
- **Use multi-stage builds**
- **Minimize image size**
- **Set proper environment variables**
- **Include health checks**
## ๐ Documentation Rules
### Code Documentation
1. **Write JSDoc for all public functions**
2. **Include usage examples** in comments
3. **Document configuration options**
4. **Maintain API documentation**
### README Updates
- **Update README** when adding new features
- **Include setup instructions**
- **Document environment variables**
- **Provide troubleshooting guide**
## ๐ Security Rules
### API Security
1. **Never commit API keys** or secrets
2. **Use environment variables** for sensitive data
3. **Implement request validation**
4. **Rate limit API endpoints**
5. **Log security events**
### Data Protection
- **Sanitize user inputs**
- **Encrypt sensitive data** at rest
- **Use HTTPS** for all external communications
- **Implement proper authentication**
## ๐จ Code Style Rules
### ESLint Configuration
- Use `eslint:recommended` as base
- Enable `no-console` (use logger instead)
- Enforce `max-len: 100` characters
- Require `camelCase` naming
- Disallow `unused-vars`
### Formatting
- **Use Prettier** for code formatting
- **2 spaces** for indentation
- **Single quotes** for strings
- **Trailing commas** in multiline objects
- **Semicolons** at end of statements
## ๐ Development Workflow
### Feature Development
1. **Create feature branch** from main
2. **Write failing tests** first
3. **Implement minimal code** to pass tests
4. **Refactor** and optimize
5. **Update documentation**
6. **Create pull request**
### Code Review Checklist
- [ ] Tests written and passing
- [ ] Code coverage โฅ85%
- [ ] ESLint passes
- [ ] Documentation updated
- [ ] Error handling implemented
- [ ] Security considerations addressed
## ๐จ Common Pitfalls to Avoid
1. **Don't implement without tests**
2. **Don't ignore rate limits**
3. **Don't hardcode configuration**
4. **Don't skip error handling**
5. **Don't commit sensitive data**
6. **Don't create monolithic functions**
7. **Don't forget to update documentation**
Remember: This project follows TDD strictly. Every feature starts with a test, and every change must maintain or improve test coverage. Quality over speed!
Comprehensive .cursorrules file for Next.js 15 App Router projects with TypeScript, enforcing server components by default, proper use of "use client" directive, and App Router conventions.
Cursor rules for Python FastAPI projects enforcing async patterns, Pydantic v2 models, dependency injection, and proper error handling.
Rules for consistent React component development with TypeScript interfaces, proper hook patterns, and component composition.
Rules optimizing Cursor Agent mode behavior including multi-file editing context, session management, and autonomous task completion patterns.
Cursor rules for projects using Tailwind CSS with shadcn/ui component library, enforcing consistent utility class usage and component patterns.
Rules for Go backend services enforcing idiomatic Go patterns, proper error handling, and clean architecture conventions.