Contributing Guide

Thank you for considering contributing to the NSGG Backend project! This guide will help you understand our development process and standards.

Getting Started

  1. Fork the repository
  2. Clone your fork:
    git clone https://github.com/your-username/nsgg-main-backend.git
    
  3. Create a new branch:
    git checkout -b feature-name
    
  4. Set up your development environment following our Getting Started Guide

Development Process

1. Install Dependencies

pip install -r requirements/development.txt

2. Make Your Changes

  • Write clean, maintainable code
  • Follow our coding standards
  • Include tests for new features
  • Update documentation as needed

3. Commit Your Changes

Follow our commit message conventions:

type(scope): description

[optional body]

[optional footer]

Types: - feat: New feature - fix: Bug fix - docs: Documentation changes - style: Code style changes (formatting, etc.) - refactor: Code refactoring - test: Test changes - chore: Maintenance tasks

Example:

feat(products): add bulk creation endpoint

- Add bulk creation endpoint for products
- Implement validation for bulk requests
- Add tests for bulk creation

Closes #123

4. Push Your Changes

git push origin feature/your-feature-name

5. Create a Pull Request

  • Use our pull request template
  • Link related issues
  • Provide a clear description of changes
  • Include any necessary documentation
  • Ensure all tests pass

Code Standards

Python Style Guide

We follow PEP 8 with some modifications:

  • Line length: 100 characters
  • Use double quotes for strings
  • Use trailing commas in multi-line statements

Django Best Practices

  1. Models:

    class Product(models.Model):
        name = models.CharField(max_length=255)
        price = models.DecimalField(max_digits=10, decimal_places=2)
        created_at = models.DateTimeField(auto_now_add=True)
        updated_at = models.DateTimeField(auto_now=True)
    
        class Meta:
            ordering = ["-created_at"]
    
        def __str__(self):
            return self.name
    

  2. Views:

    class ProductViewSet(viewsets.ModelViewSet):
        queryset = Product.objects.all()
        serializer_class = ProductSerializer
        permission_classes = [IsAuthenticated]
        filter_backends = [DjangoFilterBackend]
        filterset_fields = ["category", "price"]
    

  3. Serializers:

    class ProductSerializer(serializers.ModelSerializer):
        class Meta:
            model = Product
            fields = ["id", "name", "price", "category"]
            read_only_fields = ["created_at", "updated_at"]
    

Testing Standards

  1. Test file organization:

    # test_views.py
    class TestProductAPI:
        def test_list_products(self, client):
            # Test implementation
    
        def test_create_product(self, client):
            # Test implementation
    

  2. Test naming:

    def test_create_product_with_invalid_data_returns_400():
        # Test implementation
    

Documentation

Docstrings

Use Google-style docstrings:

def calculate_total(items: List[OrderItem]) -> Decimal:
    """Calculate the total price for a list of order items.

    Args:
        items: List of OrderItem objects.

    Returns:
        Decimal: The total price of all items.

    Raises:
        ValueError: If any item has an invalid price.
    """

API Documentation

Document API endpoints using drf-spectacular:

@extend_schema(
    description="Create a new product",
    request=ProductSerializer,
    responses={201: ProductSerializer},
)
def create(self, request, *args, **kwargs):
    return super().create(request, *args, **kwargs)

Review Process

Pull Request Reviews

  1. Code quality
  2. Follows style guide
  3. No duplicate code
  4. Proper error handling

  5. Functionality

  6. Implements requirements
  7. Handles edge cases
  8. Includes error scenarios

  9. Testing

  10. Adequate test coverage
  11. Tests pass
  12. Tests are meaningful

  13. Documentation

  14. Updated as needed
  15. Clear and accurate
  16. Includes examples

Review Comments

  • Be constructive and respectful
  • Explain the reasoning
  • Provide examples when helpful

Release Process

  1. Version Bump
  2. Update version in __init__.py
  3. Update CHANGELOG.md

  4. Create Release Branch

    git checkout -b release/v1.0.0
    

  5. Create Release PR

  6. Include version changes
  7. Include CHANGELOG updates

  8. After Merge

  9. Tag the release
  10. Deploy to staging
  11. Deploy to production

Getting Help

  • Join our Slack channel
  • Check existing issues
  • Ask questions in discussions
  • Contact maintainers

Additional Resources