generated from john/python-template
5.4 KiB
5.4 KiB
System Architecture (Version 4)
This document describes the V4 architecture changes for expanded Document-Person relationship management.
V4 extends V3 with role extensibility, assisted suggestion review, and role-policy enforcement while preserving the existing transcription execution topology.
Architecture Objectives
- Keep V3 transcription pipeline behavior stable unless relationship evidence extraction requires additive integration.
- Support many people per role for each document.
- Support extensible relationship roles without hardcoding UI and API behavior to two values.
- Support non-canonical suggestion intake with explicit human promotion to canonical asserted links.
- Enforce role exclusivity policy consistently at service and persistence boundaries.
- Preserve auditability for suggestion provenance and review actions.
Runtime Topology
V4 keeps the existing runtime shape:
- FastAPI + NiceGUI web app process.
- Async service layer with SQLModel/SQLAlchemy persistence.
- Existing worker execution path for transcription jobs.
Additive V4 components:
- Relationship policy evaluator (exclusivity checks).
- Suggestion lifecycle service (propose/list/accept/reject).
- Optional suggestion extraction adapter (rule/NLP or LLM-backed).
^^^mermaid flowchart LR U[Browser User] --> UI[NiceGUI Pages] UI --> API[FastAPI Routes] API --> DS[Document Service] API --> SS[Suggestion Service] DS --> PE[Policy Evaluator] SS --> PE DS --> DB[(Relational DB)] SS --> DB W[Async Worker Engine] --> DB W --> E[Optional Suggestion Extraction] E --> SS ^^^
Layer Responsibilities
UI Layer (src/transcription/ui/**)
- Render per-role grouped relationships for document and person views.
- Provide multi-select role assignment controls in document create/edit flows.
- Provide suggestion review controls (accept/reject) for pending suggestions.
- Surface policy conflict errors from API/service layer clearly.
API Layer (src/transcription/api/**)
- Expose role-aware and state-aware read contracts.
- Expose suggestion lifecycle write contracts.
- Return deterministic validation/conflict errors for exclusivity and duplicate semantics.
- Evolve endpoints additively, with explicit deprecations and short-lived transition windows.
Service Layer (src/transcription/services/**)
- Implement set-based relationship sync (delta add/remove) to avoid destructive replacement behavior.
- Apply policy evaluator before persistence commits.
- Orchestrate suggestion acceptance/rejection transitions.
- Ensure accepted suggestions result in asserted link creation/confirmation.
Policy Evaluator (New logical component)
- Evaluate role exclusivity matrix for
(document_id, person_id)writes. - Provide deterministic conflict reason payloads suitable for UI/API display.
- Stay stateless and reusable across create/update/sync code paths.
Persistence Layer (src/transcription/db/**)
- Store asserted links and suggestion records according to selected schema option.
- Persist provenance metadata for suggestion records.
- Enforce uniqueness and support performant role/state filtering.
Core V4 Workflows
1) Manual Relationship Management
- User opens document edit view.
- UI loads asserted links grouped by role.
- User adds/removes people per role.
- Service computes delta and runs policy checks.
- Persistence applies adds/removes atomically.
2) Assisted Suggestion Review
- Suggestion records are created (
pending) by extraction logic or manual propose action. - UI displays pending suggestions with evidence metadata.
- User accepts or rejects each suggestion.
- Accept path creates/confirms asserted relationship and marks suggestion
accepted. - Reject path marks suggestion
rejected.
3) Exclusivity Conflict Handling
- Incoming write attempts role assignment.
- Policy evaluator checks role pair conflicts for same
(document_id, person_id). - If conflict exists, write is rejected with structured conflict details.
- UI presents actionable message without partial updates.
Invariants
- Suggested links are never canonical until accepted.
- Asserted links must satisfy exclusivity rules.
- Relationship mutations are set-based and deterministic.
- Relationship views remain consistent between document detail and person detail pages.
- Existing V3 links remain valid under asserted semantics after migration.
Backward Compatibility
- V3 author/recipient links are interpreted as asserted links in V4.
- Existing document and person flows continue to function where unaffected by new role/state dimensions.
- During development revisions, the current API contract is authoritative; long-lived legacy runtime compatibility layers are not required.
Observability and Auditability
- Persist suggestion provenance fields sufficient for operator review.
- Record review decision outcomes (
accepted/rejected) with timestamps and reviewer identity where available. - Emit structured service-level logs for exclusivity conflicts and review actions.
Test Strategy Additions
- Service tests for delta sync and exclusivity matrix enforcement.
- API tests for role/state filtering and suggestion transitions.
- UI tests for multi-role selection and suggestion review interactions.
- Migration tests for V3-to-V4 asserted mapping and conflict scans.