# Contributing

## Setup

```bash
git clone <repo-url>
cd ietf-draft-analyzer
pip install -e ".[test]"
```

You'll also need:
- **Anthropic API key**: Set `ANTHROPIC_API_KEY` in `.env` or environment
- **Ollama**: Running locally with `nomic-embed-text` model for embeddings

## Running Tests

```bash
pytest tests/ -v
```

Tests cover: JSON extraction, rating validation, FTS5 sanitization, database operations, data models, Obsidian export.

## Code Conventions

- **CLI**: Click commands in `cli.py` with `@click.option()` decorators. Use the `pass_cfg_db` decorator for config/db lifecycle.
- **Database**: Tables defined in `db.py` `ensure_tables()`, queries as methods on `Database`. Always use parameterized queries.
- **Reports**: Report types in `reports.py` `generate_report()`.
- **LLM calls**: Always cache via `llm_cache` table (prompt SHA-256 hash). Use `cheap=True` for bulk operations.
- **Output**: Use `rich` for console output.
- **Web UI**: Flask routes in `app.py`, data access in `data.py` with TypedDict return types, Jinja2 templates.

## Adding a New CLI Command

1. Add the command function in `cli.py` under the appropriate group
2. Use `@pass_cfg_db` for automatic config/db injection
3. Add `--dry-run` flag for commands that modify data
4. Use `rich` tables/panels for output

## Adding a New Report Type

1. Add the report function in `reports.py`
2. Register it in the `report` CLI group in `cli.py`
3. Output goes to `data/reports/`

## Adding a New Web UI Page

1. Create template in `src/webui/templates/`
2. Add data function in `data.py` (with TypedDict return type)
3. Add route in `app.py`
4. Add navigation link in `base.html`

## Linting

```bash
pip install ruff
ruff check src/ tests/ --select E,F,W --ignore E501
```

## Project Layout

See README.md for full project structure.
