Skip to content

Development Guide

This guide covers development workflows, coding standards, and best practices for AIEO.

Development Environment Setup

Prerequisites

  • Python 3.9+
  • Node.js 18+
  • Docker and Docker Compose
  • Git

Initial Setup

  1. Clone and install:

    git clone https://github.com/your-username/aieo.git
    cd aieo
    ./scripts/install.sh
    

  2. Configure environment:

    cp env.example .env
    # Edit .env with your API keys
    

  3. Start services:

    docker-compose up -d
    

Lightweight Setup (Scoring Engine Only)

If you only need the scoring engine (e.g., for batch auditing URLs), you can skip Docker, PostgreSQL, and Redis entirely:

python3 -m venv venv
source venv/bin/activate
pip install httpx beautifulsoup4 markdown html2text

This is sufficient to run run_audit.py and use the ScoringEngine and ContentParser classes directly from backend/app/services/.

Optional: Enable entity density scoring with spaCy:

pip install spacy
python -m spacy download en_core_web_sm

Without spaCy, entity density (Pattern 2, worth 15 points max) scores 0 for all content. All other 9 patterns work without any external services.

Development Workflow

Backend Development

  1. Activate virtual environment:

    cd backend
    source venv/bin/activate
    

  2. Run development server:

    uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
    

  3. Run tests:

    pytest
    

  4. Format code:

    black backend/
    

  5. Lint code:

    ruff check backend/
    

Frontend Development

  1. Install dependencies:

    cd frontend
    npm install
    

  2. Run development server:

    npm run dev
    

  3. Build for production:

    npm run build
    

  4. Run tests:

    npm test
    

CLI Development

  1. Install in development mode:

    cd cli
    pip install -e .
    

  2. Test commands:

    aieo audit --help
    

Code Standards

Python

  • Style: PEP 8
  • Type hints: Required for public APIs
  • Line length: 100 characters
  • Formatter: Black
  • Linter: Ruff
  • Docstrings: Google style

Example:

def score_content(content: str, format: str = "markdown") -> Dict[str, Any]:
    """
    Score content against AIEO patterns.

    Args:
        content: Content to score
        format: Content format ('markdown' or 'html')

    Returns:
        Dictionary with score, grade, and gaps
    """
    ...

TypeScript/React

  • Style: ESLint + Prettier
  • Type safety: Strict TypeScript
  • Components: Functional with hooks
  • Naming: PascalCase for components, camelCase for functions

Example:

interface AuditResult {
  score: number;
  grade: string;
  gaps: Gap[];
}

export function AuditPage() {
  const [result, setResult] = useState<AuditResult | null>(null);
  ...
}

Testing

Backend Tests

cd backend
pytest                    # Run all tests
pytest tests/test_scoring_engine.py  # Run specific test
pytest -v                # Verbose output
pytest --cov=app         # With coverage

Frontend Tests

cd frontend
npm test                 # Run tests
npm test -- --watch      # Watch mode
npm test -- --coverage   # With coverage

Integration Tests

python tools/testing/comprehensive_test.py

Database Migrations

Create Migration

cd backend
alembic revision --autogenerate -m "description"

Apply Migrations

alembic upgrade head

Rollback

alembic downgrade -1

API Development

Adding New Endpoint

  1. Create endpoint in app/api/v1/:

    @router.post("/aieo/new-endpoint")
    async def new_endpoint(
        request: NewRequest,
        api_key: str = Depends(verify_api_key),
    ):
        ...
    

  2. Add request/response models:

    class NewRequest(BaseModel):
        field: str
    

  3. Update API documentation:

  4. Endpoints auto-document at /docs
  5. Add examples in docstrings

Debugging

Backend Debugging

# Run with debug logging
uvicorn app.main:app --reload --log-level debug

# Use Python debugger
import pdb; pdb.set_trace()

Frontend Debugging

  • Use React DevTools
  • Browser DevTools
  • Console logging

Database Debugging

# Connect to database
docker-compose exec postgres psql -U aieo -d aieo

# View logs
docker-compose logs postgres

Git Workflow

Branch Naming

  • feature/ - New features
  • fix/ - Bug fixes
  • docs/ - Documentation
  • refactor/ - Refactoring
  • test/ - Tests

Commit Messages

Use Conventional Commits:

feat: add comparison table detection
fix: resolve scoring edge case
docs: update API documentation
refactor: improve content parser
test: add integration tests

Pull Request Process

  1. Create feature branch
  2. Make changes
  3. Write/update tests
  4. Update documentation
  5. Ensure tests pass
  6. Create PR with description
  7. Address review comments
  8. Merge after approval

Performance Optimization

Backend

  • Use async/await for I/O operations
  • Cache expensive operations
  • Optimize database queries
  • Use connection pooling

Frontend

  • Code splitting
  • Lazy loading
  • Memoization
  • Optimize re-renders

Common Tasks

Run Batch Audit on URL List

The quickest way to audit multiple URLs:

  1. Add URLs to sites.txt (one per line)
  2. Run the standalone audit script:
    source venv/bin/activate
    python run_audit.py
    
  3. Results are saved to a temp directory as JSON files (one per site + summary.json)

Add New Pattern

  1. Update scoring_engine.py
  2. Add detection logic
  3. Update weight in _calculate_total_score()
  4. Add gap info in _generate_gaps()
  5. Update tests
  6. Update documentation (PATTERNS.md, CLI.md scoring table)

Add New Service

  1. Create service file in app/services/
  2. Add tests
  3. Integrate with API
  4. Update documentation

Update Dependencies

# Backend
cd backend
pip list --outdated
pip install --upgrade package

# Frontend
cd frontend
npm outdated
npm update package

Troubleshooting

Common Issues

Backend won't start: - Check database connection - Verify environment variables - Check port availability

Frontend build fails: - Clear node_modules and reinstall - Check Node.js version - Verify dependencies

Tests fail: - Check test database setup - Verify environment variables - Check for port conflicts

Resources

Getting Help

  • Check existing issues
  • Review documentation
  • Ask in discussions
  • Open an issue with details