4.3 KiB
4.3 KiB
ComfyUI Custom Node Development Rules
This document outlines the development standards and best practices for creating custom nodes for ComfyUI with AI assistance.
Project Structure
custom_nodes/your_node_name/
├── __init__.py # Node registration
├── node_implementation.py # Main Python implementation
├── js/
│ ├── main.js # Frontend implementation
│ └── widget_implementations.js
├── .vscode/
│ └── settings.json # VSCode settings
├── .eslintrc.json # JavaScript linting rules
├── .prettierrc # Code formatting rules
├── .editorconfig # Editor configuration
├── setup.cfg # Python linting configuration
├── .gitignore # Git exclusion patterns
└── README.md # Documentation
Development Guidelines
Python (Backend)
-
Node Structure:
- Define nodes as classes with clear
INPUT_TYPES,RETURN_TYPES, andFUNCTIONmethods - Keep node implementations focused on a single responsibility
- Use descriptive variable names and add docstrings
- Define nodes as classes with clear
-
Type Annotation:
- Use type hints to improve code readability and AI assistance quality
- Annotate function parameters and return values
-
Error Handling:
- Implement proper error handling with meaningful error messages
- Validate user inputs before processing
JavaScript (Frontend)
-
Widget Integration:
- Follow ComfyUI's widget patterns for consistency
- Implement proper event handling and update mechanisms
-
Naming Conventions:
- Use camelCase for variables and functions
- Use PascalCase for class names
- Prefix private functions with underscore (_)
-
DOM Manipulation:
- Use ComfyUI's built-in methods when possible
- Avoid direct DOM manipulation where possible
AI-Assisted Development Tips
-
Clear Prompting:
- Provide context about ComfyUI architecture in your prompts
- Reference existing implementations for similar functionality
- Specify dependencies and environment constraints
-
Code Review:
- Always review AI-generated code before implementation
- Test edge cases that AI might have missed
- Verify all imports and dependencies are properly handled
-
Iterative Development:
- Break complex features into smaller, manageable tasks for AI
- Implement core functionality first, then add refinements
- Maintain a clear record of implementation steps
Testing Custom Nodes
-
Manual Testing:
- Test nodes in various workflows and with different inputs
- Verify error handling works as expected
- Test compatibility with different ComfyUI versions
-
Documentation:
- Create clear usage examples
- Document any special requirements or limitations
- Include screenshots or GIFs demonstrating functionality
Publishing Guidelines
-
Pre-release Checklist:
- Remove debug console logs
- Ensure proper error handling
- Verify compatibility with latest ComfyUI version
- Check for hardcoded paths or values
-
Documentation:
- Provide clear installation instructions
- Include usage examples and screenshots
- List dependencies and requirements
- Explain widget behavior and functionality
-
Distribution:
- Include license information
- Create a proper README with installation and usage instructions
- Consider providing sample workflows demonstrating your nodes
Linting and Formatting Tools
This project uses the following tools for code quality:
- ESLint: JavaScript code quality
- Prettier: Code formatting
- Flake8/autopep8: Python code quality and formatting
- EditorConfig: Consistent editor settings
Configure your editor to use these tools for the best development experience.
Version Control Best Practices
-
Commit Messages:
- Use clear, descriptive commit messages
- Reference issues or feature requests when applicable
-
Branching:
- Use feature branches for new functionality
- Create hotfix branches for critical fixes
-
Pull Requests:
- Include screenshots or videos demonstrating functionality
- List any breaking changes
- Tag relevant reviewers