# Sprint 22: Rules v1

> **Size**: XL | **Owner**: Backend + Client | **Prerequisites**: Sprint 16, Sprint 21
> **Phase**: 5 - Platform Evolution

---

## Validation Status (2025-12-31)

### ❌ NOT IMPLEMENTED

| Component | Status | Notes |
|-----------|--------|-------|
| Rules schema | ❌ Not implemented | `domain/rules/schema.py` does not exist |
| Rules evaluator | ❌ Not implemented | `domain/rules/evaluator.py` does not exist |
| Rules service | ❌ Not implemented | `application/services/rules_service.py` does not exist |
| Rules RPCs | ❌ Not implemented | No proto messages for rules |
| Rules UI | ❌ Not implemented | `client/src/pages/Rules.tsx` does not exist |

**Blockers**: Sprint 21 (MCP Config) prerequisite is incomplete.

**Downstream impact**: Sprint 23 (Analytics) depends on Rules schema for auditing.

---

## Objective

Automate recording, templates, and outputs without chaos. Rules define behavior at user/workspace/project/meeting levels.

---

## Decision: Backend-Evaluated

> **Decided**: Rules evaluated in Python backend. Enables audit trails, single source of truth, and consistent behavior. Client handles trigger detection, backend handles rule application.

---

## What Already Exists

| Asset | Location | Implication |
|-------|----------|-------------|
| `TriggerSettings` (23 fields) | `config/settings.py` | Precedent for rule config |
| `trigger_meeting_apps` list | Settings | App-based rules pattern |
| Summarization templates | Service | Template application exists |
| Export infrastructure | `infrastructure/export/` | Output destinations exist |

---

## Scope

| Task | Effort |
|------|--------|
| Rules schema + precedence | L |
| Domain event schema (inputs + audit) | M |
| Auto-record/transcribe criteria | M |
| Machine app inventory feed | M |
| Summary template rules | M |
| Output destination rules | M |
| Rules CRUD endpoints | M |
| Rules editor UI | L |

---

## Deliverables

- `src/noteflow/domain/rules/schema.py`
- `src/noteflow/domain/rules/evaluator.py`
- `src/noteflow/application/services/rules_service.py`
- `src/noteflow/domain/events/schema.py`
- Rules RPCs in proto
- `client/src/pages/Rules.tsx`

## Quality Gates

- [ ] `pytest tests/domain/test_rules.py` passes
- [ ] `pytest tests/application/test_rules_service.py` passes
- [ ] `npm run test` passes for frontend
- [ ] Meets `docs/sprints/QUALITY_STANDARDS.md` (lint + test quality thresholds)

---

## Post-Sprint

- Rule versioning
- Rule import/export
- Rule marketplace
