# Policy Forge Pro Architecture

## Product layers
1. **Client:** responsive web/PWA; Capacitor shells for iOS/Android; Tauri shell for desktop.
2. **Identity & tenant layer:** organization workspaces, RBAC, SSO-ready user model.
3. **Jurisdiction engine:** country → federal → province/state/territory → regional/county → municipality/local authority graph.
4. **Authority registry:** verified government/regulator domains, category coverage, discovery hints and validation timestamps.
5. **Regulatory ingestion:** web discovery + official-source prioritization + metadata normalization + content hash/change detection.
6. **Requirement engine:** converts source passages into normalized obligations with mandatory/conditional/recommended classification, applicability, locator and confidence.
7. **Document engine:** template-aware drafting. Legal claims are restricted to researched requirements; uncertainty becomes `[VERIFY]`.
8. **Traceability:** stable clause IDs link every legal/guidance clause to source URL, locator, obligation and confidence.
9. **Governance:** immutable document versions, approval steps, status transitions, comments and audit log.
10. **Billing:** provider-neutral entitlements fed by Stripe, StoreKit, Google Play Billing and optional Microsoft Store purchases.
11. **Change monitoring:** source hashes and scheduled re-research identify changes and affected documents.

## Regulatory discovery algorithm
- Resolve the complete jurisdiction chain from the user's selected operating location.
- Pull verified authorities from the registry for each level and category.
- Search official domains first.
- Run a second discovery pass for authorities not yet in the registry (local bylaws, boards, commissions, delegated agencies).
- Validate that each source is owned/published by an official authority or is an incorporated-by-reference standard.
- Extract source metadata and exact locators.
- De-duplicate by canonical URL/publication number.
- Score evidence; low confidence becomes `VERIFY`.
- Store a content hash and next-check timestamp.

## Traceability contract
A generated clause claiming a legal obligation should never exist without one of:
- `legal_basis` trace to a stored requirement/source;
- `company_requirement` label; or
- `verify` label.

That invariant should be enforced server-side before a document can move to `approved`.
