Contributing¶
Guidelines for contributing to Campaign Brain.
Development Setup¶
# Clone repository
git clone git@github.com:Nominate-AI/cbtenant.git
cd cbtenant
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Run tests
python -m pytest tests/
# Start development servers
./startit.sh
Code Style¶
Python¶
- Follow PEP 8
- Use type hints
- 4-space indentation
- Docstrings for all public functions
def create_tenant(name: str, slug: str) -> Tenant:
"""Create a new tenant instance.
Args:
name: Display name for the tenant
slug: URL-safe identifier
Returns:
Created Tenant object
Raises:
ValueError: If slug already exists
"""
...
Naming Conventions¶
| Type | Convention | Example |
|---|---|---|
| Classes | PascalCase | TenantConfig |
| Functions | snake_case | create_tenant |
| Variables | snake_case | tenant_id |
| Constants | UPPER_SNAKE | MAX_TENANTS |
Imports¶
# Standard library
import os
from pathlib import Path
# Third-party
from fastapi import FastAPI
from sqlalchemy import Column
# Local
from db.models import Tenant
from api.auth import get_current_user
Git Workflow¶
Branch Naming¶
feature/description- New featuresfix/description- Bug fixesdocs/description- Documentationrefactor/description- Code refactoring
Commit Messages¶
Types: feat, fix, docs, refactor, test, chore
Pull Requests¶
- Create feature branch
- Make changes
- Run tests
- Create PR with description
- Wait for review
- Merge after approval
Testing¶
Running Tests¶
# All tests
python -m pytest
# Specific file
python -m pytest tests/test_tenants.py
# With coverage
python -m pytest --cov=api
Writing Tests¶
def test_create_tenant(client, db):
"""Test tenant creation."""
response = client.post("/api/tenants", json={
"name": "Test Campaign",
"slug": "test-campaign"
})
assert response.status_code == 201
assert response.json()["name"] == "Test Campaign"
Documentation¶
- Update docs when changing features
- Use MkDocs for documentation
- Include code examples
- Add diagrams where helpful
Release Process¶
- Update VERSION file
- Update CHANGELOG
- Create git tag
- Push to GitHub
- Deploy to tenants