Contribution Guide¶
文档版本: 1.0.0
最后更新: 2025-08-19
Git 提交: c1aa5b0f
作者: Lincoln
Welcome Contributions¶
Thank you for your interest in the JAiRouter project! We welcome all forms of contributions, including but not limited to:
- 🐛 Bug reports and fixes
- ✨ New feature development
- 📚 Documentation improvements
- 🧪 Test case additions
- 💡 Feature suggestions and discussions
Development Environment Setup¶
System Requirements¶
- Java: 17 or higher
- Maven: 3.8+ (recommended to use the built-in Maven Wrapper)
- Git: 2.20+
- IDE: IntelliJ IDEA (recommended) or Eclipse
Environment Configuration¶
Clone the Project
Verify Java Version
Build the Project
Run Tests
Start the Application
IDE Configuration¶
IntelliJ IDEA¶
- Import Project
- File → Open → Select project root directory
Choose "Import as Maven project"
Configure Code Style
- File → Settings → Editor → Code Style
Import checkstyle.xml configuration from project root
Configure Maven
- File → Settings → Build → Build Tools → Maven
Set Maven home directory to
.mvn/wrapper
within the projectInstall Recommended Plugins
- CheckStyle-IDEA
- SpotBugs
- SonarLint
Development Workflow¶
1. Create Branch¶
# Create feature branch from main
git checkout main
git pull origin main
git checkout -b feature/your-feature-name
# Or create fix branch
git checkout -b fix/issue-number-description
2. Development Standards¶
Code Style¶
- Follow the project's Checkstyle configuration
- Use 4 spaces for indentation, not tabs
- Line length should not exceed 120 characters
- Classes and methods require complete Javadoc comments
Naming Conventions¶
- Class names: PascalCase (e.g.,
LoadBalancerFactory
) - Method names: camelCase (e.g., selectInstance)
- Constants: UPPER_SNAKE_CASE (e.g., DEFAULT_TIMEOUT)
- Package names: lowercase, dot-separated (e.g.,
org.unreal.modelrouter.adapter
)
Comment Standards¶
/**
* Load balancer factory class
*
* <p>Responsible for creating and managing different types of load balancer instances,
* supporting dynamic switching of load balancing strategies.
*
* @author Author Name
* @since 1.0.0
*/
public class LoadBalancerFactory {
/**
* Create load balancer based on configuration
*
* @param config Load balancing configuration
* @return Load balancer instance
* @throws IllegalArgumentException when configuration is invalid
*/
public LoadBalancer createLoadBalancer(LoadBalanceConfig config) {
// Implementation logic
}
}
3. Testing Requirements¶
Unit Tests¶
- New features must include corresponding unit tests
- Test coverage should be no less than 80%
- Test class naming format:
{ClassName}Test
@ExtendWith(MockitoExtension.class)
class LoadBalancerFactoryTest {
@Mock
private LoadBalanceConfig config;
@InjectMocks
private LoadBalancerFactory factory;
@Test
@DisplayName("Should create correct load balancer based on configuration")
void shouldCreateCorrectLoadBalancer() {
// Given
when(config.getType()).thenReturn("random");
// When
LoadBalancer balancer = factory.createLoadBalancer(config);
// Then
assertThat(balancer).isInstanceOf(RandomLoadBalancer.class);
}
}
Integration Tests¶
- Key features require integration tests
- Use
@SpringBootTest
for complete application context testing
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class UniversalControllerIntegrationTest {
@Autowired
private TestRestTemplate restTemplate;
@Test
void shouldHandleChatRequest() {
// Integration test logic
}
}
4. Commit Standards¶
Commit Message Format¶
Use Conventional Commits specification:
Types (type): - feat
: New feature - fix
: Bug fix - docs
: Documentation update - style
: Code formatting adjustments - refactor
: Code refactoring - test
: Test-related changes - chore
: Build process or auxiliary tool changes
Example:
feat(loadbalancer): Add consistent hash load balancing algorithm
- Implement virtual node-based consistent hash algorithm
- Support dynamic node addition and removal
- Add corresponding unit tests
Closes #123
5. Code Review¶
Submit Pull Request¶
Push Branch
Create Pull Request
- Create PR on GitHub
- Fill in detailed PR description
Link related Issues
PR Description Template
## Change Description Briefly describe the content and purpose of this change. ## Change Type - [ ] Bug fix - [ ] New feature - [ ] Documentation update - [ ] Code refactoring - [ ] Performance optimization ## Testing - [ ] Unit tests added - [ ] Integration tests added - [ ] Manual testing passed ## Checklist - [ ] Code follows project standards - [ ] Related documentation updated - [ ] Test coverage requirements met - [ ] No Checkstyle and SpotBugs warnings ## Related Issues Closes #issue-number
Code Review Focus Points¶
Reviewer Focus Areas: - Code logic correctness - Performance impact - Security considerations - Test completeness - Documentation updates
Common Issues: - Unhandled exceptions - Resource leaks - Concurrency safety issues - Unnecessary complexity
Development Guidance¶
Adding New Adapters¶
Create Adapter Class
Register Adapter
Add Tests
Adding New Load Balancing Strategies¶
Implement Interface
Register Strategy
Adding New Rate Limiting Algorithms¶
Implement Interface
Configuration Support
Release Process¶
Version Number Standards¶
Use Semantic Versioning specification:
- MAJOR: Incompatible API changes
- MINOR: Backward-compatible feature additions
- PATCH: Backward-compatible bug fixes
Release Checklist¶
- [ ] All tests pass
- [ ] Code quality checks pass
- [ ] Documentation updated
- [ ] CHANGELOG updated
- [ ] Version number updated
Community Participation¶
Reporting Issues¶
When reporting issues via GitHub Issues, please provide:
- Detailed problem description
- Reproduction steps
- Expected behavior
- Actual behavior
- Environment information (Java version, operating system, etc.)
- Related logs
Feature Suggestions¶
When submitting feature suggestions, please explain:
- Use case for the feature
- Expected implementation approach
- Impact on existing features
- Willingness to participate in development
Participating in Discussions¶
- Join project discussions
- Answer other users' questions
- Share usage experiences
- Provide improvement suggestions
Getting Help¶
If you encounter problems during development, you can get help through:
- Reviewing project documentation
- Searching existing Issues
- Creating new Issues
- Participating in community discussions
Thank you for your contributions! Every contribution makes JAiRouter better.