diff --git a/04_generated_documentation/00_process_control/ambiguity_register.md b/04_generated_documentation/00_process_control/ambiguity_register.md index bf788cc..8182ef0 100644 --- a/04_generated_documentation/00_process_control/ambiguity_register.md +++ b/04_generated_documentation/00_process_control/ambiguity_register.md @@ -19,3 +19,5 @@ Open requirements and architecture questions are tracked here (`AMB-xxx`). Unres | AMB-007 | 2026-10-11 | Stage 0B | What production availability, backup retention, RTO, and RPO targets are acceptable? | These targets determine hosting, data protection, recovery design, and support commitments. | Resolved: 99.9% monthly availability measured 24/7; RTO ≤4 hours; RPO ≤15 minutes; encrypted daily backups with point-in-time recovery and 35-day retention; quarterly restore exercises. Captured in `BRD-NFR-011`. | Resolved | Stakeholder, 2026-10-11 | | AMB-008 | 2026-10-11 | Stage 0B | What tenant count, active-user count, transaction volume, peak concurrency, and per-tenant limits must the platform support? | Stakeholder approved an initial envelope of 50 tenant firms, 25 named users per tenant, and 250 concurrent active users service-wide. The approved provisional planning scenario is 200 core business documents per tenant per operating day with a 5× peak-hour burst. Stakeholder accepted no fixed business-document quota; observe per-tenant use, provide configurable early warnings near the tested fair-share budget, and protect core transactions while using backpressure/temporary throttling for expensive reports or bulk exports under contention. Numeric fair-share budgets and alert thresholds still require architecture/load-test evidence and later pilot refinement. | Partially resolved: approved 50 tenant firms, up to 25 named users per tenant, 250 concurrent active users service-wide, and 50,000 ledger rows per tenant for report validation. The 200 documents/tenant/operating day and 5× peak-hour burst scenario has been accepted for load testing; set numeric fair-share budgets and alert thresholds from architecture/load-test evidence and refine them with pilot telemetry; see `BRD-NFR-004` and `BRD-NFR-012`. | Open | — | | AMB-009 | 2026-10-11 | Stage 7 | Which candidate architecture patterns should be adopted for the Stage 7 walking skeleton, and what evidence is required before full-breadth design? | The Stage 7 report proposes transaction-local PostgreSQL tenant context with RLS, server-verified UC-019 membership, append-only audit and a transactional outbox, Keycloak session/logout semantics, provider-neutral HA/deployment controls, and runtime validation. | Human lead approved the candidate modular-monolith/reference patterns as the Stage 7 design baseline (`DEC-021`) and authorized Stage 8/9 to proceed. Exact Keycloak session/logout contract, hosting and private-document storage providers, runtime proof, and load evidence remain open; no runtime validation is claimed. | Partially Resolved | Human lead, 2026-10-11 | +| AMB-010 | 2026-10-11 | Stage 9 | Which tax identifier types, jurisdiction-specific formats, applicability rules, and validation method must supplier/customer master data enforce? | `FR-MASTERDATA-002` requires tax IDs validated where applicable but does not specify formats, applicability, checksums, or whether external verification is required. These affect input rules and privacy/vendor integration scope. | LLD-008 preserves the source rule without assuming formats or a live tax-authority integration; resolve during qualified business/tax review before implementation. | Open | — | +| AMB-011 | 2026-10-11 | Stage 9 | What poison-event retention, replay approval, and operational recovery policy should govern permanently failing outbox consumers? | `DEC-021` approves durable outbox and idempotent consumers but does not set retention, alert escalation, replay authority, or payload redaction for permanently failing events. | Stage 9 isolates and surfaces poison events without silent deletion; exact retention and controlled replay process require an operational/security owner decision before production. | Open | — | diff --git a/04_generated_documentation/00_process_control/architecture_risk_register.md b/04_generated_documentation/00_process_control/architecture_risk_register.md index f9d351e..463915b 100644 --- a/04_generated_documentation/00_process_control/architecture_risk_register.md +++ b/04_generated_documentation/00_process_control/architecture_risk_register.md @@ -7,7 +7,7 @@ | **Last Updated** | 2026-10-11 | | **Version** | 2.0.0 | | **Last CR** | `CR-001` (UC-001 rebaseline retained) | -| **Stage Status** | Stage 6 scored; Stage 7 architecture review pending human-lead sign-off | +| **Stage Status** | Stage 6 complete; Stage 7 reference patterns approved by human lead (`DEC-021`) | ## 1. Scoring Scale and Dimensions @@ -61,4 +61,4 @@ A use case is Architecturally Significant if any dimension is 4–5 or it is in ## 4. Stage 7 State -Risk ranking complete. Candidate HLD/LLD/deployment and design-level walking-skeleton analysis are in `04_architecture_design/architecture_spike_report.md`, `hld.md`, `lld/LLD-001_auth_service.md`, `lld/LLD-002_tenant_context_and_isolation.md`, `lld/LLD-003_receiving_quality_inventory.md`, `lld/LLD-004_financial_controls.md`, `lld/LLD-005_reporting_and_events.md`, `lld/LLD-006_privacy_lifecycle.md`, and `deployment_spike.md`. Human-lead sign-off is pending. No runtime skeleton has been implemented or tested; the design report distinguishes scenario walkthrough evidence from runtime proof. +Risk ranking complete. Candidate HLD/LLD/deployment and design-level walking-skeleton analysis are in `04_architecture_design/architecture_spike_report.md`, `hld.md`, `lld/LLD-001_auth_service.md`, `lld/LLD-002_tenant_context_and_isolation.md`, `lld/LLD-003_receiving_quality_inventory.md`, `lld/LLD-004_financial_controls.md`, `lld/LLD-005_reporting_and_events.md`, `lld/LLD-006_privacy_lifecycle.md`, and `deployment_spike.md`. Human-lead design-baseline approval is recorded in `DEC-021`. No runtime skeleton has been implemented or tested; the design report distinguishes scenario walkthrough evidence from runtime proof. diff --git a/04_generated_documentation/00_process_control/checkpoints/checkpoint-014-stage-9-hld-lld.md b/04_generated_documentation/00_process_control/checkpoints/checkpoint-014-stage-9-hld-lld.md new file mode 100644 index 0000000..52e8421 --- /dev/null +++ b/04_generated_documentation/00_process_control/checkpoints/checkpoint-014-stage-9-hld-lld.md @@ -0,0 +1,23 @@ +# Checkpoint 014 — Stage 9 HLD/LLD and Gate 9.1 + +- **Checkpoint ID:** CKPT-014 +- **Date:** 2026-10-11 +- **Active Stage:** Stage 9 design complete; Gate 9.1 passed +- **Active Track:** Greenfield, India-first, multi-tenant Agriculture Trading Backoffice (ATB) +- **Active Skill:** up-hld-lld-generate + +## Completed +- Completed the HLD module ownership map for all 26 UCs / 54 FRs using Stage 7 approved patterns (`DEC-021`). +- Added LLD-007 through LLD-011 for market observations, trading master data, fleet/expense services, tenant policies, and privacy governance. Reconciled LLD-001–006 to Stage 8 SRS and Stage 9 contract references. All 54 FRs appear in an LLD Parent FR set. +- Authored shared endpoint-level API, PostgreSQL data/entity, and integration boundary designs; produced the Stage 9 human review brief. +- Added `AMB-010` for unresolved tax identifier applicability/formats/verification and `AMB-011` for poison-event retention/replay authority. No assumptions were presented as settled requirements. +- Deterministic Gate 9.1 passed: `python scripts/verify_traceability_gates.py --gate 9.1`; 0 Critical, 0 Major, 0 Minor. The master traceability graph now records 54 FR-to-SRS/HLD/LLD links. +- `git diff --check` passed. No product implementation, runtime, load or application tests were run. + +## Open Items +- Human review of `stage9_human_review_brief.md` and detailed design is still appropriate before baseline/implementation. +- `AMB-001`, `AMB-006`, `AMB-008`, `AMB-009`, `AMB-010`, and `AMB-011` remain open or partially resolved; runtime/load and legal evidence is pending. +- Iteration-01 remains Incomplete / Pending Construction; its prior Gate 14.1 blockers (dense QA workbook and Bruno collections) remain. + +## Exact Next Action +Review the Stage 9 design brief and proceed to Stage 10 `/up-iteration-plan` for the next vertical slice. Keep iteration-01 and all requirements in their recorded lifecycle states; do not claim implementation or runtime delivery. diff --git a/04_generated_documentation/00_process_control/checkpoints/checkpoint_index.md b/04_generated_documentation/00_process_control/checkpoints/checkpoint_index.md index 9100177..8772dd2 100644 --- a/04_generated_documentation/00_process_control/checkpoints/checkpoint_index.md +++ b/04_generated_documentation/00_process_control/checkpoints/checkpoint_index.md @@ -36,3 +36,4 @@ | CKPT-012 | 2026-10-11 | Stage 6 complete / Stage 7 human review | Scored all 26 UCs/54 FRs; 16 architecturally significant. Drafted candidate HLD, LLDs, deployment view, and spike report; design walkthrough only, no runtime proof. | AMB-009 human-lead disposition; runtime validation and Gate 9.1 remain pending; iteration-01 Gate 14.1 blockers unchanged. | Review architecture_spike_report.md; record Approve / Approve with changes / Defer for AMB-009. If approved, proceed to Stage 8 SRS derivation. | checkpoint-012-stage-6-7-architecture-spike.md | | CKPT-013 | 2026-10-11 | Stage 7 approved / Stage 8 derived | Human lead approved Stage 7 patterns (`DEC-021`); 54 FR-specific SRS records + 4 explicit cross-cutting NFRs authored and mapped. | Stage 9 HLD/LLD fan-out; Gate 9.1 follows Stage 9; runtime/load proof and AMB-001/006/008/009 evidence remain pending; Gate 14.1 blockers unchanged. | Run `/up-hld-lld-generate`, then `/up-traceability-gate 9.1`. | checkpoint-013-stage-7-approval-stage-8-srs.md | +| CKPT-014 | 2026-10-11 | Stage 9 complete / Gate 9.1 passed | HLD/LLD and shared API/database/integration design linked all 54 FRs; validator reports 0 Critical/Major/Minor. | Human design review; runtime/load/legal evidence; AMB-001/006/008/009/010/011; iteration-01 Gate 14.1 blockers persist. | Review Stage 9 brief, then run `/up-iteration-plan`. | checkpoint-014-stage-9-hld-lld.md | diff --git a/04_generated_documentation/00_process_control/master_context.md b/04_generated_documentation/00_process_control/master_context.md index 6221542..102cb5f 100644 --- a/04_generated_documentation/00_process_control/master_context.md +++ b/04_generated_documentation/00_process_control/master_context.md @@ -86,6 +86,6 @@ stack: ## 4. Active Stage & Next Actions -- **Current Stage:** Stage 7 architecture design baseline approved by human lead (`DEC-021`). Stage 8 SRS derivation is complete for 54 FRs in `03_requirements/SRS-001_stage8_system_requirements.md`. No runtime/load validation has been performed. +- **Current Stage:** Stage 7 architecture design baseline approved by human lead (`DEC-021`). Stage 8 SRS derivation is complete for 54 FRs in `03_requirements/SRS-001_stage8_system_requirements.md`. Stage 9 HLD/LLD and shared API/database/integration design are complete for all 54 FRs; Gate 9.1 passed with zero findings. No runtime/load validation has been performed. - **Active Iteration:** No iteration is in construction. Iteration-01 remains planned but Incomplete / Pending Construction; Gate 14.1 has two Critical findings (dense QA workbook and Bruno API collections missing). -- **Next:** Stage 9 `/up-hld-lld-generate` to complete HLD/LLD linkage for all FRs, then run Gate 9.1. Stage 7 runtime proof remains pending implementation/environment. Iteration-01 remains Incomplete / Pending Construction; Gate 14.1 has two Critical evidence findings (dense QA workbook and Bruno API collections). Carry `AMB-001`, `AMB-006`, `AMB-008`, `AMB-009` and `ASM-001`–`ASM-003` forward. +- **Next:** Stage 10 `/up-iteration-plan` to select a construction vertical slice now that Gate 5.1 and Gate 9.1 have passed. Review `stage9_human_review_brief.md` before baselining detailed design. Iteration-01 remains Incomplete / Pending Construction; its Gate 14.1 has two Critical evidence findings (dense QA workbook and Bruno API collections). Carry `AMB-001`, `AMB-006`, `AMB-008`–`AMB-011` and `ASM-001`–`ASM-003` forward. Runtime/load and legal evidence remain outstanding. diff --git a/04_generated_documentation/00_process_control/traceability_graph.md b/04_generated_documentation/00_process_control/traceability_graph.md index ee4fd4e..ee6236b 100644 --- a/04_generated_documentation/00_process_control/traceability_graph.md +++ b/04_generated_documentation/00_process_control/traceability_graph.md @@ -5,7 +5,7 @@ | **Governed Standard** | SEI-CMMI Level 3 (UP-AI v1.5) | | **Document Path** | `04_generated_documentation/00_process_control/traceability_graph.md` | | **Last Updated** | 2026-10-11 | -| **Version** | 1.1.0 | +| **Version** | 1.2.0 | | **Last CR** | `CR-001` | | **Gated By** | `up-traceability-gate`, `scripts/verify_traceability_gates.py` | @@ -21,7 +21,7 @@ - **Total User Stories (STORY-xxx):** 3 (historical references; downstream files missing from active worktree) - **Total Test Cases (TC-xxx):** 4 (historical references; downstream files missing from active worktree) - **Gate 5.1 Status:** **PASS WITH WARNINGS** (0 Critical; 2 justified Major source-parser warnings) -- **Gate 9.1 Status:** **Pending Stage 9 HLD/LLD fan-out** +- **Gate 9.1 Status:** **PASS** (2026-10-11; 0 Critical, 0 Major, 0 Minor) - **Gate 14.1 Status:** **Failed for iteration-01** (2 Critical construction-evidence findings; no FR Delivered) --- @@ -190,59 +190,69 @@ These artifacts are candidate Stage 7 spike outputs. They do not replace Stage 8 | Parent UC | Functional Requirement | System Requirement | Stage 7/9 Architecture Link | Status | |---|---|---|---|---| -| `UC-001` | `FR-AUTH-001` | `SRS-AUTH-001` | HLD-ATB / LLD-001, LLD-002 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-001` | `FR-AUTH-002` | `SRS-AUTH-002` | HLD-ATB / LLD-001, LLD-002 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-001` | `FR-AUTH-003` | `SRS-AUTH-003` | HLD-ATB / LLD-001, LLD-002 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-002` | `FR-MKT-001` | `SRS-MKT-001` | Stage 9 HLD/LLD pending | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-002` | `FR-MKT-002` | `SRS-MKT-002` | Stage 9 HLD/LLD pending | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-003` | `FR-MARKETTRENDANALYTICS-001` | `SRS-MARKETTRENDANALYTICS-001` | LLD-005 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-004` | `FR-PROCUREMENTCONTRACTS-001` | `SRS-PROCUREMENTCONTRACTS-001` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-004` | `FR-PROCUREMENTCONTRACTS-002` | `SRS-PROCUREMENTCONTRACTS-002` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-004` | `FR-PROCUREMENTCONTRACTS-003` | `SRS-PROCUREMENTCONTRACTS-003` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-004` | `FR-PROCUREMENTCONTRACTS-004` | `SRS-PROCUREMENTCONTRACTS-004` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-005` | `FR-INWARDRECEIVING-001` | `SRS-INWARDRECEIVING-001` | LLD-003 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-005` | `FR-INWARDRECEIVING-002` | `SRS-INWARDRECEIVING-002` | LLD-003 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-005` | `FR-INWARDRECEIVING-003` | `SRS-INWARDRECEIVING-003` | LLD-003 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-005` | `FR-INWARDRECEIVING-004` | `SRS-INWARDRECEIVING-004` | LLD-003 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-005` | `FR-INWARDRECEIVING-005` | `SRS-INWARDRECEIVING-005` | LLD-003 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-005` | `FR-INWARDRECEIVING-006` | `SRS-INWARDRECEIVING-006` | LLD-003 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-006` | `FR-QUALITYANDLOTCONTROL-001` | `SRS-QUALITYANDLOTCONTROL-001` | LLD-003 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-006` | `FR-QUALITYANDLOTCONTROL-002` | `SRS-QUALITYANDLOTCONTROL-002` | LLD-003 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-006` | `FR-QUALITYANDLOTCONTROL-003` | `SRS-QUALITYANDLOTCONTROL-003` | LLD-003 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-006` | `FR-QUALITYANDLOTCONTROL-004` | `SRS-QUALITYANDLOTCONTROL-004` | LLD-003 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-007` | `FR-WAREHOUSEINVENTORY-001` | `SRS-WAREHOUSEINVENTORY-001` | LLD-003 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-007` | `FR-WAREHOUSEINVENTORY-002` | `SRS-WAREHOUSEINVENTORY-002` | LLD-003 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-007` | `FR-WAREHOUSEINVENTORY-003` | `SRS-WAREHOUSEINVENTORY-003` | LLD-003 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-008` | `FR-SALESCONTRACTS-001` | `SRS-SALESCONTRACTS-001` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-008` | `FR-SALESCONTRACTS-002` | `SRS-SALESCONTRACTS-002` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-008` | `FR-SALESCONTRACTS-003` | `SRS-SALESCONTRACTS-003` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-009` | `FR-DISPATCHDELIVERY-001` | `SRS-DISPATCHDELIVERY-001` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-009` | `FR-DISPATCHDELIVERY-002` | `SRS-DISPATCHDELIVERY-002` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-009` | `FR-DISPATCHDELIVERY-003` | `SRS-DISPATCHDELIVERY-003` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-010` | `FR-FLEETREGISTRY-001` | `SRS-FLEETREGISTRY-001` | Stage 9 HLD/LLD pending | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-011` | `FR-CUSTOMERRECEIVABLES-001` | `SRS-CUSTOMERRECEIVABLES-001` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-011` | `FR-CUSTOMERRECEIVABLES-002` | `SRS-CUSTOMERRECEIVABLES-002` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-011` | `FR-CUSTOMERRECEIVABLES-003` | `SRS-CUSTOMERRECEIVABLES-003` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-011` | `FR-CUSTOMERRECEIVABLES-004` | `SRS-CUSTOMERRECEIVABLES-004` | LLD-004 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-012` | `FR-SUPPLIERPAYABLES-001` | `SRS-SUPPLIERPAYABLES-001` | Stage 9 HLD/LLD pending | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-013` | `FR-OPERATINGEXPENSES-001` | `SRS-OPERATINGEXPENSES-001` | Stage 9 HLD/LLD pending | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-014` | `FR-OPERATIONALALERTS-001` | `SRS-OPERATIONALALERTS-001` | LLD-005 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-015` | `FR-EXECUTIVEREPORTING-001` | `SRS-EXECUTIVEREPORTING-001` | LLD-005 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-015` | `FR-EXECUTIVEREPORTING-002` | `SRS-EXECUTIVEREPORTING-002` | LLD-005 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-016` | `FR-MASTERDATA-001` | `SRS-MASTERDATA-001` | Stage 9 HLD/LLD pending | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-016` | `FR-MASTERDATA-002` | `SRS-MASTERDATA-002` | Stage 9 HLD/LLD pending | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-017` | `FR-TENANTSECURITYAUDIT-001` | `SRS-TENANTSECURITYAUDIT-001` | LLD-002 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-017` | `FR-TENANTSECURITYAUDIT-003` | `SRS-TENANTSECURITYAUDIT-003` | LLD-002 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-018` | `FR-TENANTLIFECYCLE-001` | `SRS-TENANTLIFECYCLE-001` | LLD-002 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-019` | `FR-TENANTMEMBERSHIPCONTEXT-001` | `SRS-TENANTMEMBERSHIPCONTEXT-001` | LLD-002 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-019` | `FR-TENANTMEMBERSHIPCONTEXT-002` | `SRS-TENANTMEMBERSHIPCONTEXT-002` | LLD-002 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-020` | `FR-TENANTSUPPORTSECURITY-001` | `SRS-TENANTSUPPORTSECURITY-001` | LLD-002 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-020` | `FR-TENANTSUPPORTSECURITY-002` | `SRS-TENANTSUPPORTSECURITY-002` | LLD-002 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-021` | `FR-PRIVACYPURPOSECONSENT-001` | `SRS-PRIVACYPURPOSECONSENT-001` | Stage 9 HLD/LLD pending | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-022` | `FR-DATAPRINCIPALRIGHTS-001` | `SRS-DATAPRINCIPALRIGHTS-001` | Stage 9 HLD/LLD pending | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-023` | `FR-PRIVACYBREACHRESPONSE-001` | `SRS-PRIVACYBREACHRESPONSE-001` | LLD-006 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-024` | `FR-RETENTIONERASURE-001` | `SRS-RETENTIONERASURE-001` | LLD-006 | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-025` | `FR-PROCESSORGOVERNANCE-001` | `SRS-PROCESSORGOVERNANCE-001` | Stage 9 HLD/LLD pending | Stage 8 derived; Gate 9.1 pending Stage 9 | -| `UC-026` | `FR-TENANTOPERATINGPOLICIES-001` | `SRS-TENANTOPERATINGPOLICIES-001` | Stage 9 HLD/LLD pending | Stage 8 derived; Gate 9.1 pending Stage 9 | +| `UC-001` | `FR-AUTH-001` | `SRS-AUTH-001` | HLD-IAM / LLD-001 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-001` | `FR-AUTH-002` | `SRS-AUTH-002` | HLD-IAM / LLD-001 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-001` | `FR-AUTH-003` | `SRS-AUTH-003` | HLD-IAM / LLD-001 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-002` | `FR-MKT-001` | `SRS-MKT-001` | HLD-MARKET-DESK / LLD-007 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-002` | `FR-MKT-002` | `SRS-MKT-002` | HLD-MARKET-DESK / LLD-007 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-003` | `FR-MARKETTRENDANALYTICS-001` | `SRS-MARKETTRENDANALYTICS-001` | HLD-REPORTING / LLD-005 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-004` | `FR-PROCUREMENTCONTRACTS-001` | `SRS-PROCUREMENTCONTRACTS-001` | HLD-PROCUREMENT / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-004` | `FR-PROCUREMENTCONTRACTS-002` | `SRS-PROCUREMENTCONTRACTS-002` | HLD-PROCUREMENT / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-004` | `FR-PROCUREMENTCONTRACTS-003` | `SRS-PROCUREMENTCONTRACTS-003` | HLD-PROCUREMENT / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-004` | `FR-PROCUREMENTCONTRACTS-004` | `SRS-PROCUREMENTCONTRACTS-004` | HLD-PROCUREMENT / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-005` | `FR-INWARDRECEIVING-001` | `SRS-INWARDRECEIVING-001` | HLD-RECEIVING / LLD-003 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-005` | `FR-INWARDRECEIVING-002` | `SRS-INWARDRECEIVING-002` | HLD-RECEIVING / LLD-003 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-005` | `FR-INWARDRECEIVING-003` | `SRS-INWARDRECEIVING-003` | HLD-RECEIVING / LLD-003 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-005` | `FR-INWARDRECEIVING-004` | `SRS-INWARDRECEIVING-004` | HLD-RECEIVING / LLD-003 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-005` | `FR-INWARDRECEIVING-005` | `SRS-INWARDRECEIVING-005` | HLD-RECEIVING / LLD-003 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-005` | `FR-INWARDRECEIVING-006` | `SRS-INWARDRECEIVING-006` | HLD-RECEIVING / LLD-003 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-006` | `FR-QUALITYANDLOTCONTROL-001` | `SRS-QUALITYANDLOTCONTROL-001` | HLD-QUALITY / LLD-003 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-006` | `FR-QUALITYANDLOTCONTROL-002` | `SRS-QUALITYANDLOTCONTROL-002` | HLD-QUALITY / LLD-003 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-006` | `FR-QUALITYANDLOTCONTROL-003` | `SRS-QUALITYANDLOTCONTROL-003` | HLD-QUALITY / LLD-003 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-006` | `FR-QUALITYANDLOTCONTROL-004` | `SRS-QUALITYANDLOTCONTROL-004` | HLD-QUALITY / LLD-003 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-007` | `FR-WAREHOUSEINVENTORY-001` | `SRS-WAREHOUSEINVENTORY-001` | HLD-INVENTORY / LLD-003 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-007` | `FR-WAREHOUSEINVENTORY-002` | `SRS-WAREHOUSEINVENTORY-002` | HLD-INVENTORY / LLD-003 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-007` | `FR-WAREHOUSEINVENTORY-003` | `SRS-WAREHOUSEINVENTORY-003` | HLD-INVENTORY / LLD-003 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-008` | `FR-SALESCONTRACTS-001` | `SRS-SALESCONTRACTS-001` | HLD-SALES / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-008` | `FR-SALESCONTRACTS-002` | `SRS-SALESCONTRACTS-002` | HLD-SALES / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-008` | `FR-SALESCONTRACTS-003` | `SRS-SALESCONTRACTS-003` | HLD-SALES / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-009` | `FR-DISPATCHDELIVERY-001` | `SRS-DISPATCHDELIVERY-001` | HLD-DISPATCH / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-009` | `FR-DISPATCHDELIVERY-002` | `SRS-DISPATCHDELIVERY-002` | HLD-DISPATCH / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-009` | `FR-DISPATCHDELIVERY-003` | `SRS-DISPATCHDELIVERY-003` | HLD-DISPATCH / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-010` | `FR-FLEETREGISTRY-001` | `SRS-FLEETREGISTRY-001` | HLD-FLEET / LLD-009 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-011` | `FR-CUSTOMERRECEIVABLES-001` | `SRS-CUSTOMERRECEIVABLES-001` | HLD-RECEIVABLES / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-011` | `FR-CUSTOMERRECEIVABLES-002` | `SRS-CUSTOMERRECEIVABLES-002` | HLD-RECEIVABLES / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-011` | `FR-CUSTOMERRECEIVABLES-003` | `SRS-CUSTOMERRECEIVABLES-003` | HLD-RECEIVABLES / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-011` | `FR-CUSTOMERRECEIVABLES-004` | `SRS-CUSTOMERRECEIVABLES-004` | HLD-RECEIVABLES / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-012` | `FR-SUPPLIERPAYABLES-001` | `SRS-SUPPLIERPAYABLES-001` | HLD-PAYABLES / LLD-004 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-013` | `FR-OPERATINGEXPENSES-001` | `SRS-OPERATINGEXPENSES-001` | HLD-EXPENSES / LLD-009 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-014` | `FR-OPERATIONALALERTS-001` | `SRS-OPERATIONALALERTS-001` | HLD-EVENTS-ALERTS / LLD-005 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-015` | `FR-EXECUTIVEREPORTING-001` | `SRS-EXECUTIVEREPORTING-001` | HLD-REPORTING / LLD-005 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-015` | `FR-EXECUTIVEREPORTING-002` | `SRS-EXECUTIVEREPORTING-002` | HLD-REPORTING / LLD-005 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-016` | `FR-MASTERDATA-001` | `SRS-MASTERDATA-001` | HLD-MASTERDATA / LLD-008 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-016` | `FR-MASTERDATA-002` | `SRS-MASTERDATA-002` | HLD-MASTERDATA / LLD-008 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-017` | `FR-TENANTSECURITYAUDIT-001` | `SRS-TENANTSECURITYAUDIT-001` | HLD-ISOLATION-AUDIT / LLD-002 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-017` | `FR-TENANTSECURITYAUDIT-003` | `SRS-TENANTSECURITYAUDIT-003` | HLD-ISOLATION-AUDIT / LLD-002 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-018` | `FR-TENANTLIFECYCLE-001` | `SRS-TENANTLIFECYCLE-001` | HLD-TENANCY / LLD-002 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-019` | `FR-TENANTMEMBERSHIPCONTEXT-001` | `SRS-TENANTMEMBERSHIPCONTEXT-001` | HLD-TENANCY / LLD-002 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-019` | `FR-TENANTMEMBERSHIPCONTEXT-002` | `SRS-TENANTMEMBERSHIPCONTEXT-002` | HLD-TENANCY / LLD-002 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-020` | `FR-TENANTSUPPORTSECURITY-001` | `SRS-TENANTSUPPORTSECURITY-001` | HLD-ISOLATION-AUDIT / LLD-002 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-020` | `FR-TENANTSUPPORTSECURITY-002` | `SRS-TENANTSUPPORTSECURITY-002` | HLD-ISOLATION-AUDIT / LLD-002 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-021` | `FR-PRIVACYPURPOSECONSENT-001` | `SRS-PRIVACYPURPOSECONSENT-001` | HLD-PRIVACY-INCIDENT-LIFECYCLE / LLD-011 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-022` | `FR-DATAPRINCIPALRIGHTS-001` | `SRS-DATAPRINCIPALRIGHTS-001` | HLD-PRIVACY-INCIDENT-LIFECYCLE / LLD-011 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-023` | `FR-PRIVACYBREACHRESPONSE-001` | `SRS-PRIVACYBREACHRESPONSE-001` | HLD-PRIVACY-INCIDENT-LIFECYCLE / LLD-006 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-024` | `FR-RETENTIONERASURE-001` | `SRS-RETENTIONERASURE-001` | HLD-PRIVACY-INCIDENT-LIFECYCLE / LLD-006 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-025` | `FR-PROCESSORGOVERNANCE-001` | `SRS-PROCESSORGOVERNANCE-001` | HLD-PROCESSOR-GOVERNANCE / LLD-011 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | +| `UC-026` | `FR-TENANTOPERATINGPOLICIES-001` | `SRS-TENANTOPERATINGPOLICIES-001` | HLD-TENANT-POLICY / LLD-010 | Stage 9 design linked; Gate 9.1 passed 2026-10-11 | Cross-cutting NFRs `NFR-SEC-001`, `NFR-AUDIT-001`, `NFR-OPS-001`, and `NFR-CAP-001` each declare `parent_fr: cross-cutting` and explicitly enumerate the in-scope 54 FR IDs in `SRS-001_stage8_system_requirements.md`. + +## Gate 9.1 Check — 2026-10-11 (Stage 9 Full FR Set) + +| Check | Result | Evidence | +|---|---|---| +| FR-to-SRS linkage | Pass | 54/54 FRs resolve to unique FR-specific SRS records; four scoped cross-cutting NFRs carry explicit `parent_fr: cross-cutting`. | +| FR-to-HLD/LLD linkage | Pass | 54/54 FRs are listed in LLD Parent FRs and mapped to an HLD component in the Stage 9 traceability table. | +| Deterministic Gate 9.1 | **PASS** | `python scripts/verify_traceability_gates.py --gate 9.1`; 0 Critical, 0 Major, 0 Minor findings. | + +This is a traceability/design completeness gate, not runtime, load, legal, or security implementation evidence. diff --git a/04_generated_documentation/00_process_control/traceability_index.md b/04_generated_documentation/00_process_control/traceability_index.md index bf317b0..2f20791 100644 --- a/04_generated_documentation/00_process_control/traceability_index.md +++ b/04_generated_documentation/00_process_control/traceability_index.md @@ -29,3 +29,7 @@ $$\text{BRD-FR-xxx} \longrightarrow \text{UC-xxx} \longrightarrow \text{FR-xxx} ## Stage 8 SRS Traceability The complete 54-FR mapping, unique SRS IDs, and four explicitly scoped cross-cutting NFRs are maintained in [`SRS-001_stage8_system_requirements.md`](../03_requirements/SRS-001_stage8_system_requirements.md). Stage 7 candidate architecture patterns were approved as the design baseline by `DEC-021`; full Stage 9 HLD/LLD fan-out and Gate 9.1 remain pending. + +## Stage 9 Architecture Linkage + +The master graph maps all 54 FRs to their Stage 8 SRS, HLD component and LLD artifact. Gate 9.1 passed on 2026-10-11 with zero findings. Supporting contracts: [`hld.md`](../04_architecture_design/hld.md), [`api_design.md`](../04_architecture_design/api_design.md), [`database_design.md`](../04_architecture_design/database_design.md), and [`integration_design.md`](../04_architecture_design/integration_design.md). This is design/traceability evidence only; runtime and load validation remain pending. diff --git a/04_generated_documentation/04_architecture_design/api_design.md b/04_generated_documentation/04_architecture_design/api_design.md new file mode 100644 index 0000000..7dcb7cc --- /dev/null +++ b/04_generated_documentation/04_architecture_design/api_design.md @@ -0,0 +1,89 @@ +--- +id: API-DESIGN-001 +parent_ids: [HLD-ATB, UC-001, UC-002, UC-003, UC-004, UC-005, UC-006, UC-007, UC-008, UC-009, UC-010, UC-011, UC-012, UC-013, UC-014, UC-015, UC-016, UC-017, UC-018, UC-019, UC-020, UC-021, UC-022, UC-023, UC-024, UC-025, UC-026] +version: 1.0.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending +last_cr: none +--- + +# API Design — REST/OpenAPI Contracts + +| Field | Value | +|---|---| +| **Base path** | `/api/v1` for application APIs; identity protocol endpoints remain at Keycloak | +| **Transport** | HTTPS; JSON request/response except documented evidence-upload references | +| **AuthN/AuthZ** | Configured OIDC/JWT, role/action policy, verified tenant context before tenant data access (`DEC-021`) | +| **Error envelope** | `code`, safe `message`, `correlation_id`, field errors; no secrets or cross-tenant existence disclosure | +| **Idempotency** | Required for retryable financial, inventory, state-transition, tenant lifecycle, and evidence-finalization commands; scope key by verified tenant + operation | + +Paths and method groups below are Stage 9 contracts. Combined method notation (for example POST/GET/PATCH) represents separate operations on the resource. The application must enforce all FR rules and NFR scopes from the Stage 8 SRS. Exact field schemas, pagination limits, error codes and generated OpenAPI components are maintained during construction without changing these semantics. + +## Endpoint and component matrix + +| FR | Operation / endpoint | Contract summary | Authorization / boundary | HLD / LLD | +|---|---|---|---|---| +| `FR-AUTH-001` | `IdP OIDC authorization-code/PKCE flow; GET /api/v1/auth/session` | Integration / session validation; no credentials or token material are accepted as ordinary business resource fields. | OIDC identity or policy evaluation; no untrusted tenant selector | `HLD-IAM` / `LLD-001` | +| `FR-AUTH-002` | `Cross-cutting policy decision at each protected API command/query` | No standalone CRUD endpoint; evaluate role/action/resource permission and segregation rules. | Middleware/worker + RLS invariant; no endpoint | `HLD-IAM` / `LLD-001` | +| `FR-AUTH-003` | `POST /api/v1/auth/logout` | End application session; exact provider revocation semantics remain AMB-009. | OIDC identity or policy evaluation; no untrusted tenant selector | `HLD-IAM` / `LLD-001` | +| `FR-MKT-001` | `POST /api/v1/market-observations; GET /api/v1/market-observations` | Create/list by explicit tenant-scoped filters; enforce date, quantity, holiday and duplicate rules. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-MARKET-DESK` / `LLD-007` | +| `FR-MKT-002` | `PUT /api/v1/market-observations/{observation_id}/rates` | Atomically store min/modal/max; reject nonpositive or out-of-range modal rate. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-MARKET-DESK` / `LLD-007` | +| `FR-MARKETTRENDANALYTICS-001` | `GET /api/v1/market-analytics/trends` | Return requested intraday/20-day benchmark series within source FR response-time and data-scope rules. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-REPORTING` / `LLD-005` | +| `FR-PROCUREMENTCONTRACTS-001` | `GET /api/v1/procurement/price-variance` | Calculate against tenant policy and current market modal data; explain variance basis. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-PROCUREMENT` / `LLD-004` | +| `FR-PROCUREMENTCONTRACTS-002` | `POST /api/v1/procurement/contracts` | Create auction/direct-purchase sauda with source-defined commercial terms. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-PROCUREMENT` / `LLD-004` | +| `FR-PROCUREMENTCONTRACTS-003` | `PUT /api/v1/suppliers/{supplier_id}/credit-terms` | Set approved supplier credit days and return computed due date on related purchase. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-PROCUREMENT` / `LLD-004` | +| `FR-PROCUREMENTCONTRACTS-004` | `POST /api/v1/procurement/contracts/{contract_id}/levies:calculate` | Calculate/apportion configured cess and statutory levies without inventing rates. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-PROCUREMENT` / `LLD-004` | +| `FR-INWARDRECEIVING-001` | `POST /api/v1/receipts/gate-entries` | Create verified inbound vehicle/gate entry. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-RECEIVING` / `LLD-003` | +| `FR-INWARDRECEIVING-002` | `POST /api/v1/receipts/{receipt_id}/weighments` | Record gross/tare measurements and source. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-RECEIVING` / `LLD-003` | +| `FR-INWARDRECEIVING-003` | `POST /api/v1/receipts/{receipt_id}/net-quantity:calculate` | Compute tare deduction/final net quantity using approved policy/contract inputs. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-RECEIVING` / `LLD-003` | +| `FR-INWARDRECEIVING-004` | `POST /api/v1/receipts/{receipt_id}/shortage:assess` | Compare shortage against approved tolerance and capture disposition. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-RECEIVING` / `LLD-003` | +| `FR-INWARDRECEIVING-005` | `POST /api/v1/goods-receipts` | Post GRN, warehouse placement, lot/stock/audit/outbox atomically. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-RECEIVING` / `LLD-003` | +| `FR-INWARDRECEIVING-006` | `POST /api/v1/lots:generate` | Create unique lot/batch identity linked to its source receipt. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-RECEIVING` / `LLD-003` | +| `FR-QUALITYANDLOTCONTROL-001` | `POST /api/v1/lots/{lot_id}/inspections` | Record QC parameters with numeric bounds. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-QUALITY` / `LLD-003` | +| `FR-QUALITYANDLOTCONTROL-002` | `POST /api/v1/lots/{lot_id}/quality-adjustments:calculate` | Calculate contract/policy deduction and require authorization at the stated floor. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-QUALITY` / `LLD-003` | +| `FR-QUALITYANDLOTCONTROL-003` | `POST /api/v1/lots/{lot_id}/transitions` | Apply allowed QC transition; prevent allocation/dispatch while held. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-QUALITY` / `LLD-003` | +| `FR-QUALITYANDLOTCONTROL-004` | `POST /api/v1/lots/{lot_id}/lineage-operations` | Split/blend with exact parent/child quantity conservation and lineage. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-QUALITY` / `LLD-003` | +| `FR-WAREHOUSEINVENTORY-001` | `GET /api/v1/inventory/positions; POST /api/v1/inventory/adjustments` | Read derived double-entry positions; adjustment uses reason/approval and cannot create negative stock. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-INVENTORY` / `LLD-003` | +| `FR-WAREHOUSEINVENTORY-002` | `GET /api/v1/godowns/{godown_id}/capacity` | Return capacity, current MT and utilization with source warning threshold. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-INVENTORY` / `LLD-003` | +| `FR-WAREHOUSEINVENTORY-003` | `POST /api/v1/inventory/transfers` | Post a tenant-scoped transfer aggregate with paired movements and idempotency. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-INVENTORY` / `LLD-003` | +| `FR-SALESCONTRACTS-001` | `POST /api/v1/sales/contracts` | Create sales contract with actor authorization and source business constraints. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-SALES` / `LLD-004` | +| `FR-SALESCONTRACTS-002` | `GET /api/v1/customers/{customer_id}/credit-exposure; POST /api/v1/credit-checks` | Calculate exposure and credit decision under serialized/consistent transaction semantics. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-SALES` / `LLD-004` | +| `FR-SALESCONTRACTS-003` | `POST /api/v1/sales/contracts/{contract_id}/allocations` | Reserve eligible released stock atomically; reject QC-held or unavailable lots. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-SALES` / `LLD-004` | +| `FR-DISPATCHDELIVERY-001` | `GET /api/v1/dispatches/board` | Return eligible dispatch work and current blockers. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-DISPATCH` / `LLD-004` | +| `FR-DISPATCHDELIVERY-002` | `POST /api/v1/dispatches/{dispatch_id}/manifest` | Record outward weighment/manifest and transition dispatch under inventory/credit rules. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-DISPATCH` / `LLD-004` | +| `FR-DISPATCHDELIVERY-003` | `POST /api/v1/dispatches/{dispatch_id}/proof-of-delivery` | Record POD/tracking evidence and status; document storage provider remains unselected. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-DISPATCH` / `LLD-004` | +| `FR-FLEETREGISTRY-001` | `POST/GET/PATCH /api/v1/fleet/vehicles` | Maintain vehicle record; reject maintenance vehicles for dispatch assignment. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-FLEET` / `LLD-009` | +| `FR-CUSTOMERRECEIVABLES-001` | `GET /api/v1/receivables/ledger` | Query immutable receivable entries and tenant-scoped aging. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-RECEIVABLES` / `LLD-004` | +| `FR-CUSTOMERRECEIVABLES-002` | `GET /api/v1/receivables/credit-exposure; POST /api/v1/receivables/credit-evaluations` | Compute exposure and issue threshold alert from approved tenant policy. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-RECEIVABLES` / `LLD-004` | +| `FR-CUSTOMERRECEIVABLES-003` | `POST /api/v1/customers/{customer_id}/credit-overrides` | Authorize, justify, audit and time-scope partner override; preserve required lock state. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-RECEIVABLES` / `LLD-004` | +| `FR-CUSTOMERRECEIVABLES-004` | `POST /api/v1/receivables/receipts` | Record receipt in append-only financial ledger; bounced reversal uses compensating entry. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-RECEIVABLES` / `LLD-004` | +| `FR-SUPPLIERPAYABLES-001` | `GET /api/v1/payables/aging` | Derive payable aging from accepted GRNs and supplier credit days. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-PAYABLES` / `LLD-004` | +| `FR-OPERATINGEXPENSES-001` | `POST /api/v1/expenses/vouchers` | Create and post only balanced cash/bank expense voucher. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-EXPENSES` / `LLD-009` | +| `FR-OPERATIONALALERTS-001` | `GET /api/v1/alerts; PATCH /api/v1/alerts/{alert_id}/review` | List/review tenant-scoped alerts; notification channel is configurable and no provider is selected. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-EVENTS-ALERTS` / `LLD-005` | +| `FR-EXECUTIVEREPORTING-001` | `GET /api/v1/reports/executive-dashboard` | Return the requested KPI/source aggregates within the FR dashboard response target. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-REPORTING` / `LLD-005` | +| `FR-EXECUTIVEREPORTING-002` | `GET /api/v1/reports/trading-snapshots` | Return rolling 20-day daily ledger-derived management snapshot. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-REPORTING` / `LLD-005` | +| `FR-MASTERDATA-001` | `POST/GET/PATCH /api/v1/master-data/commodities; /varieties; /grades` | Maintain tenant-scoped catalogs; code uniqueness and active-stock delete restriction. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-MASTERDATA` / `LLD-008` | +| `FR-MASTERDATA-002` | `POST/GET/PATCH /api/v1/master-data/suppliers; /customers; /godowns` | Maintain tenant-scoped counterparty/location masters; tax ID details subject to AMB-010. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-MASTERDATA` / `LLD-008` | +| `FR-TENANTSECURITYAUDIT-001` | `Cross-cutting request/worker/data access enforcement` | No direct endpoint; verified tenant context plus PostgreSQL RLS on all tenant records. | Middleware/worker + RLS invariant; no endpoint | `HLD-ISOLATION-AUDIT` / `LLD-002` | +| `FR-TENANTSECURITYAUDIT-003` | `GET /api/v1/audit/events (authorized audit readers only)` | Read immutable events; filters and response fields follow UC permissions/privacy constraints. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-ISOLATION-AUDIT` / `LLD-002` | +| `FR-TENANTLIFECYCLE-001` | `POST /api/v1/platform/tenants; PATCH /api/v1/platform/tenants/{tenant_id}/status` | Platform-admin-only create/activate/suspend lifecycle commands with audit. | Platform administrator / operator role, control-plane boundary | `HLD-TENANCY` / `LLD-002` | +| `FR-TENANTMEMBERSHIPCONTEXT-001` | `POST/PATCH /api/v1/tenants/{tenant_id}/memberships` | Tenant-admin membership/role administration restricted to that verified tenant. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-TENANCY` / `LLD-002` | +| `FR-TENANTMEMBERSHIPCONTEXT-002` | `POST /api/v1/session/active-tenant; cross-cutting request resolver` | Validate chosen tenant membership/role on every API and worker operation; client ID alone grants nothing. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-TENANCY` / `LLD-002` | +| `FR-TENANTSUPPORTSECURITY-001` | `Cross-cutting API/worker/export/file/cache isolation` | No direct endpoint; resource ownership and tenant context enforced end to end. | Middleware/worker + RLS invariant; no endpoint | `HLD-ISOLATION-AUDIT` / `LLD-002` | +| `FR-TENANTSUPPORTSECURITY-002` | `POST /api/v1/platform/support-access/requests; POST /grants; POST /revocations` | Apply tenant-approved case access or urgent, reasoned, maximum one-hour break-glass grant and alert/notice requirements. | Tenant-admin approval or designated platform security admin with scoped support grant; separate control-plane authorization | `HLD-ISOLATION-AUDIT` / `LLD-002` | +| `FR-PRIVACYPURPOSECONSENT-001` | `POST/GET/PATCH /api/v1/privacy/purposes; POST /consent-events` | Maintain responsible-entity-scoped purposes/notices; record consent only when selected basis is consent; process withdrawal. | Responsible fiduciary privacy role; verified tenant or platform scope | `HLD-PRIVACY-INCIDENT-LIFECYCLE` / `LLD-011` | +| `FR-DATAPRINCIPALRIGHTS-001` | `POST /api/v1/privacy/requests; GET/PATCH /api/v1/privacy/requests/{request_id}` | Allow no-account intake, verify subject/scope, route to responsible fiduciary, track due date/disposition/evidence. | Public no-account intake creates an unverified case only; protected staff actions require the responsible fiduciary privacy role and verified scope | `HLD-PRIVACY-INCIDENT-LIFECYCLE` / `LLD-011` | +| `FR-PRIVACYBREACHRESPONSE-001` | `POST/GET/PATCH /api/v1/privacy/breaches` | Coordinate incident, impact, evidence, roles and notification tasks; statutory deadline values require approved legal configuration. | Responsible fiduciary privacy role; verified tenant or platform scope | `HLD-PRIVACY-INCIDENT-LIFECYCLE` / `LLD-006` | +| `FR-RETENTIONERASURE-001` | `POST /api/v1/privacy/retention-schedules; POST /api/v1/privacy/erasure-cases` | Resolve approved schedule/legal holds across stores, execute authorized lifecycle, produce non-sensitive evidence. | Responsible fiduciary privacy role; verified tenant or platform scope | `HLD-PRIVACY-INCIDENT-LIFECYCLE` / `LLD-006` | +| `FR-PROCESSORGOVERNANCE-001` | `POST/GET/PATCH /api/v1/platform/processors` | Operator-only processor inventory/due diligence; no live connector implied by inventory. | Platform administrator / operator role, control-plane boundary | `HLD-PROCESSOR-GOVERNANCE` / `LLD-011` | +| `FR-TENANTOPERATINGPOLICIES-001` | `POST/GET/PATCH /api/v1/tenant/policies; POST /confirmations` | Version tenant/scope/effective dates; authorized confirmation; block only impacted workflows while unreviewed. | Authenticated role from FR permission matrix; verified active tenant + RLS | `HLD-TENANT-POLICY` / `LLD-010` | + +## Shared request, response and failure rules + +- Tenant ID is resolved from authenticated membership; body/query tenant selectors only scope an already-authorized request. +- List endpoints require bounded pagination and deterministic sort; filters apply after tenant scope. Export/report jobs preserve tenant identity, actor, filter and purpose in the job record. +- State-changing requests carry an idempotency key when repeated delivery could duplicate a financial, inventory, lifecycle or privacy action. Duplicate keys return the original result or a typed conflict if payload differs. +- Validation failures identify a stable rule code and affected field without returning sensitive values. Authorization failures do not disclose whether another tenant’s resource exists. +- Concurrency conflicts return a retryable conflict only when the command is safe to retry; financial/stock conflicts require re-read/re-evaluation, not blind overwrite. +- `FR-TENANTSECURITYAUDIT-001` and `FR-TENANTSUPPORTSECURITY-001` are enforced across all endpoints, workers and data surfaces. +- Authentication/session endpoint details must respect `AMB-009`; browser token storage, exact callback and provider revocation timing are not asserted here. +- Privacy deadlines and retention behavior use approved configured rules; missing legal configuration does not silently substitute a guessed duration (`AMB-006`). diff --git a/04_generated_documentation/04_architecture_design/architecture_spike_report.md b/04_generated_documentation/04_architecture_design/architecture_spike_report.md index dfd7b71..b9d3b40 100644 --- a/04_generated_documentation/04_architecture_design/architecture_spike_report.md +++ b/04_generated_documentation/04_architecture_design/architecture_spike_report.md @@ -42,7 +42,7 @@ tests/ unit/ integration/ api/ browser/ smoke/ ``` -Domain modules depend on application ports; HTTP, SQLAlchemy, Keycloak and Valkey stay at adapters. Every write uses a transaction-scoped tenant context, authorization decision, idempotency key, audit write, and (when publishing) outbox row. Full repository structure is a candidate for lead review, not a claim that files/code already exist. +Domain modules depend on application ports; HTTP, SQLAlchemy, Keycloak and Valkey stay at adapters. Every write uses a transaction-scoped tenant context, authorization decision, idempotency key, audit write, and (when publishing) outbox row. The logical repository structure is an approved design pattern, not a claim that product files/code already exist. ## 3. End-to-End Walking-Skeleton Scenarios diff --git a/04_generated_documentation/04_architecture_design/database_design.md b/04_generated_documentation/04_architecture_design/database_design.md new file mode 100644 index 0000000..52123a7 --- /dev/null +++ b/04_generated_documentation/04_architecture_design/database_design.md @@ -0,0 +1,107 @@ +--- +id: DB-DESIGN-001 +parent_ids: [HLD-ATB, UC-001, UC-002, UC-003, UC-004, UC-005, UC-006, UC-007, UC-008, UC-009, UC-010, UC-011, UC-012, UC-013, UC-014, UC-015, UC-016, UC-017, UC-018, UC-019, UC-020, UC-021, UC-022, UC-023, UC-024, UC-025, UC-026] +version: 1.0.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending +last_cr: none +--- + +# Database Design — PostgreSQL / SQLAlchemy / Alembic + +## 1. Shared persistence rules + +- Tenant-owned rows include non-null `tenant_id`; tenant-scoped primary/foreign/unique constraints include tenant ownership to prevent cross-tenant references. Use transaction-local PostgreSQL context set only by the verified membership resolver; enable RLS `USING` and `WITH CHECK`. Application runtime roles do not own protected tables and do not have `BYPASSRLS`. +- Control-plane records (tenant directory, platform processor inventory, platform-operated privacy cases) use separately authorized tables/role policies; never grant ordinary tenant sessions broad control-plane access. +- Use UUID surrogate keys unless a business-readable identifier is explicitly defined (for example the `EXP-YYYYMM-xxx` expense number). `timestamptz` stores instants; business dates use `date` with explicit timezone policy at API boundary. +- Use exact numeric types, not binary floating point. Currency precision is 2 decimal places; weight/quantity precision follows source NFR (3 decimal places); rates and percentages use adequate exact numeric scale with source validation. Units are persisted explicitly where conversion is possible. +- Posted stock, receivable, payable and cash/bank journal entries are append-only. Corrections create linked reversal/adjustment entries. Mutable query projections carry source version/watermark and are rebuildable. +- Every migration adds FK/check/unique indexes and RLS policies with tenant tests; large-ledger query indexes follow measured access patterns. This design is not a migration-executed claim. + +## 2. Entity and constraint catalog + +| Domain / entity | FR scope | Key attributes / relationships | Principal constraints / access | +| Identity / Tenant / Membership | FR-AUTH-001–003; FR-TENANTLIFECYCLE-001; FR-TENANTMEMBERSHIPCONTEXT-001/002 | Tenant, external identity subject, active membership, role grants, status/effective timestamps | Tenant control-plane permissions separate; unique (tenant_id, subject); active verified membership required before RLS context. | +| MarketObservation | FR-MKT-001/002 | Market, commodity, variety, grade, business date, arrivals MT, stock MT, source, observed_at, holiday status, min/modal/max INR/Qtl | Tenant unique (market, commodity, variety, date); nonfuture date, arrivals >=0, holiday allows absent arrival; positive rates and min<=modal<=max. | +| MarketTrendProjection | FR-MARKETTRENDANALYTICS-001 | Date/commodity/market aggregates, source observation IDs, projection watermark | Read model only; tenant keyed; rebuildable and bounded to requested date/20-day domain. | +| ProcurementContract / SupplierTerms / Levy | FR-PROCUREMENTCONTRACTS-001–004 | Sauda mode, supplier, commodity, agreed rate/quantity, credit days/due date, levy type/base/rate/amount, modal comparison inputs | Credit days source-approved; configured values/levy rates not invented; contract and calculations tenant-owned. | +| GateEntry / Weighment / GoodsReceipt / Lot | FR-INWARDRECEIVING-001–006 | Vehicle/source, gross/tare, packaging tare, net MT, shortage, receipt/GRN identity, warehouse, lot/batch link | Net nonnegative and source formulas/tolerance; unique tenant GRN/lot IDs; atomic GRN/lot/stock/audit/outbox commit. | +| Inspection / QualityAdjustment / LotLineage | FR-QUALITYANDLOTCONTROL-001–004 | Inspection measures, officer, grade/status; base/penalty/adjusted rates; parent-child lot IDs and quantities | Percent 0..100; hold/release role FSM; held lot never allocated/dispatched; split quantities conserve parent. | +| Warehouse / StockJournal / StockPosition / Transfer / Audit | FR-WAREHOUSEINVENTORY-001–003 | Warehouse capacity; signed inbound/outbound movement; MT/bag units; transfer state; physical count/reason; derived balance | Balanced append-only journal, nonnegative positions; adjustment approval at stated threshold; paired transfer movements in one transaction. | +| SalesContract / CreditExposure / LotAllocation | FR-SALESCONTRACTS-001–003 | Customer, contract, quantity/rate, exposure inputs, credit decision, allocated lot/quantity/reservation | Serialize exposure and reservation; approved policy; no held/insufficient lot; idempotent command. | +| Dispatch / Manifest / ProofOfDelivery | FR-DISPATCHDELIVERY-001–003 | Eligible order/lot, vehicle, outward weighment, manifest, transit state, POD evidence reference | Only credit-cleared and QC-released allocatable stock; evidence ref tenant-owned; mutation/audit and inventory boundary transactional. | +| FleetVehicle | FR-FLEETREGISTRY-001 | Registration, make/model, payload MT, ownership, transporter, status, insurance/fitness expiry | Unique tenant registration; Maintenance cannot be assigned; no telematics integration table. | +| Receivable / Receipt / CreditLock / PayableProjection | FR-CUSTOMERRECEIVABLES-001–004; FR-SUPPLIERPAYABLES-001 | Customer/supplier ledger entries, receipt instrument/status, due date, exposure, lock/override, daily payable snapshot | Append-only financial journal; bounced receipt reversal linked and idempotent; payables derive from accepted GRN. | +| ExpenseVoucher / CashBankJournal | FR-OPERATINGEXPENSES-001 | Expense ID/date/category/amount/payee/link/payment mode/status and balanced debit-credit references | Currency exact 2 decimals; voucher balances before post; post corrections compensating only. | +| OperationalAlert / DashboardSnapshot | FR-OPERATIONALALERTS-001; FR-EXECUTIVEREPORTING-001/002 | Alert condition/source/version/status/created/reviewed; dashboard and daily snapshot values | Tenant key; event consumer idempotency; reporting read model reconciles to ledgers; performance targets remain FR-derived. | +| Commodity / Variety / Grade / Counterparty / Godown | FR-MASTERDATA-001/002 | Codes, labels, categories, units/standard bag weight; supplier/customer tax/contact/credit fields; godown capacity/location | Tenant-scoped unique codes; commodity with active stock cannot delete; tax-ID validation open AMB-010. | +| AuditEvent / OutboxEvent / IdempotencyRecord | Cross-cutting NFR-AUDIT-001; all governed commands | Actor, tenant, resource/action, timestamp, correlation, FR-specific reason/delta; aggregate/version/event payload/status; command scope key/hash/result | Mutation audit and outbox commit in source transaction; audit append-only; outbox at-least-once; idempotency uniqueness scoped by tenant/operation. | +| PrivacyPurpose / ConsentEvidence / RightsRequest | FR-PRIVACYPURPOSECONSENT-001; FR-DATAPRINCIPALRIGHTS-001 | Purpose/category/responsible role/basis/notice; consent/withdrawal evidence; principal reference, scope, request type, verification, deadline/disposition | Separate tenant Fiduciary from platform Fiduciary; consent events only if basis is consent; due dates from approved config; no-account intake. | +| BreachCase / RetentionSchedule / ErasureCase / ProcessorRecord | FR-PRIVACYBREACHRESPONSE-001; FR-RETENTIONERASURE-001; FR-PROCESSORGOVERNANCE-001 | Incident/affected scope/evidence refs/roles/notification status; approved purpose schedules/legal holds; deletion workflow; processor location/safeguard/diligence | Privacy case access restricted/audited; hold blocks applicable erase; exact statutory timing/retention open AMB-006; control-plane processor inventory separated. | +| TenantPolicyVersion | FR-TENANTOPERATINGPOLICIES-001 | Tenant/type/scope/value/unit/effective range/review actor/time/reason/prior value/version | No overlapping effective ranges for same scope; immutable versions; confirmed policy version referenced by governed transaction; unreviewed blocks only impacted flow. | + +## 3. Requirement-to-data ownership matrix + +| FR | SRS | Owning entity family | +|---|---|---| +| `FR-AUTH-001` | `SRS-AUTH-001` | See entity catalog row for this FR. | +| `FR-AUTH-002` | `SRS-AUTH-002` | See entity catalog row for this FR. | +| `FR-AUTH-003` | `SRS-AUTH-003` | See entity catalog row for this FR. | +| `FR-MKT-001` | `SRS-MKT-001` | See entity catalog row for this FR. | +| `FR-MKT-002` | `SRS-MKT-002` | See entity catalog row for this FR. | +| `FR-MARKETTRENDANALYTICS-001` | `SRS-MARKETTRENDANALYTICS-001` | See entity catalog row for this FR. | +| `FR-PROCUREMENTCONTRACTS-001` | `SRS-PROCUREMENTCONTRACTS-001` | See entity catalog row for this FR. | +| `FR-PROCUREMENTCONTRACTS-002` | `SRS-PROCUREMENTCONTRACTS-002` | See entity catalog row for this FR. | +| `FR-PROCUREMENTCONTRACTS-003` | `SRS-PROCUREMENTCONTRACTS-003` | See entity catalog row for this FR. | +| `FR-PROCUREMENTCONTRACTS-004` | `SRS-PROCUREMENTCONTRACTS-004` | See entity catalog row for this FR. | +| `FR-INWARDRECEIVING-001` | `SRS-INWARDRECEIVING-001` | See entity catalog row for this FR. | +| `FR-INWARDRECEIVING-002` | `SRS-INWARDRECEIVING-002` | See entity catalog row for this FR. | +| `FR-INWARDRECEIVING-003` | `SRS-INWARDRECEIVING-003` | See entity catalog row for this FR. | +| `FR-INWARDRECEIVING-004` | `SRS-INWARDRECEIVING-004` | See entity catalog row for this FR. | +| `FR-INWARDRECEIVING-005` | `SRS-INWARDRECEIVING-005` | See entity catalog row for this FR. | +| `FR-INWARDRECEIVING-006` | `SRS-INWARDRECEIVING-006` | See entity catalog row for this FR. | +| `FR-QUALITYANDLOTCONTROL-001` | `SRS-QUALITYANDLOTCONTROL-001` | See entity catalog row for this FR. | +| `FR-QUALITYANDLOTCONTROL-002` | `SRS-QUALITYANDLOTCONTROL-002` | See entity catalog row for this FR. | +| `FR-QUALITYANDLOTCONTROL-003` | `SRS-QUALITYANDLOTCONTROL-003` | See entity catalog row for this FR. | +| `FR-QUALITYANDLOTCONTROL-004` | `SRS-QUALITYANDLOTCONTROL-004` | See entity catalog row for this FR. | +| `FR-WAREHOUSEINVENTORY-001` | `SRS-WAREHOUSEINVENTORY-001` | See entity catalog row for this FR. | +| `FR-WAREHOUSEINVENTORY-002` | `SRS-WAREHOUSEINVENTORY-002` | See entity catalog row for this FR. | +| `FR-WAREHOUSEINVENTORY-003` | `SRS-WAREHOUSEINVENTORY-003` | See entity catalog row for this FR. | +| `FR-SALESCONTRACTS-001` | `SRS-SALESCONTRACTS-001` | See entity catalog row for this FR. | +| `FR-SALESCONTRACTS-002` | `SRS-SALESCONTRACTS-002` | See entity catalog row for this FR. | +| `FR-SALESCONTRACTS-003` | `SRS-SALESCONTRACTS-003` | See entity catalog row for this FR. | +| `FR-DISPATCHDELIVERY-001` | `SRS-DISPATCHDELIVERY-001` | See entity catalog row for this FR. | +| `FR-DISPATCHDELIVERY-002` | `SRS-DISPATCHDELIVERY-002` | See entity catalog row for this FR. | +| `FR-DISPATCHDELIVERY-003` | `SRS-DISPATCHDELIVERY-003` | See entity catalog row for this FR. | +| `FR-FLEETREGISTRY-001` | `SRS-FLEETREGISTRY-001` | See entity catalog row for this FR. | +| `FR-CUSTOMERRECEIVABLES-001` | `SRS-CUSTOMERRECEIVABLES-001` | See entity catalog row for this FR. | +| `FR-CUSTOMERRECEIVABLES-002` | `SRS-CUSTOMERRECEIVABLES-002` | See entity catalog row for this FR. | +| `FR-CUSTOMERRECEIVABLES-003` | `SRS-CUSTOMERRECEIVABLES-003` | See entity catalog row for this FR. | +| `FR-CUSTOMERRECEIVABLES-004` | `SRS-CUSTOMERRECEIVABLES-004` | See entity catalog row for this FR. | +| `FR-SUPPLIERPAYABLES-001` | `SRS-SUPPLIERPAYABLES-001` | See entity catalog row for this FR. | +| `FR-OPERATINGEXPENSES-001` | `SRS-OPERATINGEXPENSES-001` | See entity catalog row for this FR. | +| `FR-OPERATIONALALERTS-001` | `SRS-OPERATIONALALERTS-001` | See entity catalog row for this FR. | +| `FR-EXECUTIVEREPORTING-001` | `SRS-EXECUTIVEREPORTING-001` | See entity catalog row for this FR. | +| `FR-EXECUTIVEREPORTING-002` | `SRS-EXECUTIVEREPORTING-002` | See entity catalog row for this FR. | +| `FR-MASTERDATA-001` | `SRS-MASTERDATA-001` | See entity catalog row for this FR. | +| `FR-MASTERDATA-002` | `SRS-MASTERDATA-002` | See entity catalog row for this FR. | +| `FR-TENANTSECURITYAUDIT-001` | `SRS-TENANTSECURITYAUDIT-001` | See entity catalog row for this FR. | +| `FR-TENANTSECURITYAUDIT-003` | `SRS-TENANTSECURITYAUDIT-003` | See entity catalog row for this FR. | +| `FR-TENANTLIFECYCLE-001` | `SRS-TENANTLIFECYCLE-001` | See entity catalog row for this FR. | +| `FR-TENANTMEMBERSHIPCONTEXT-001` | `SRS-TENANTMEMBERSHIPCONTEXT-001` | See entity catalog row for this FR. | +| `FR-TENANTMEMBERSHIPCONTEXT-002` | `SRS-TENANTMEMBERSHIPCONTEXT-002` | See entity catalog row for this FR. | +| `FR-TENANTSUPPORTSECURITY-001` | `SRS-TENANTSUPPORTSECURITY-001` | See entity catalog row for this FR. | +| `FR-TENANTSUPPORTSECURITY-002` | `SRS-TENANTSUPPORTSECURITY-002` | See entity catalog row for this FR. | +| `FR-PRIVACYPURPOSECONSENT-001` | `SRS-PRIVACYPURPOSECONSENT-001` | See entity catalog row for this FR. | +| `FR-DATAPRINCIPALRIGHTS-001` | `SRS-DATAPRINCIPALRIGHTS-001` | See entity catalog row for this FR. | +| `FR-PRIVACYBREACHRESPONSE-001` | `SRS-PRIVACYBREACHRESPONSE-001` | See entity catalog row for this FR. | +| `FR-RETENTIONERASURE-001` | `SRS-RETENTIONERASURE-001` | See entity catalog row for this FR. | +| `FR-PROCESSORGOVERNANCE-001` | `SRS-PROCESSORGOVERNANCE-001` | See entity catalog row for this FR. | +| `FR-TENANTOPERATINGPOLICIES-001` | `SRS-TENANTOPERATINGPOLICIES-001` | See entity catalog row for this FR. | + +## 4. Indexing and retention boundaries + +- All tenant unique indexes include `tenant_id`; all tenant joins validate matching ownership. +- Index common filters by tenant plus business date/status/foreign key. Composite indexes for reports are chosen against the 50,000-row/tenant validation scenario and measured plans, not speculative blanket indexes. +- Do not hard-code privacy durations. `RetentionSchedule` must reference purpose/category, approving fiduciary, effective period, legal-hold rule, and review evidence; `AMB-006` blocks concrete values. +- Object/evidence references carry tenant, purpose and sensitivity tags as applicable; physical storage provider and backup/erasure contract remain undecided (`AMB-009`). +- RLS policy, constraints, and migrations require PostgreSQL integration tests across reused connections and direct SQL paths before the FRs can advance implementation status. diff --git a/04_generated_documentation/04_architecture_design/hld.md b/04_generated_documentation/04_architecture_design/hld.md index 56ca3ce..453f46f 100644 --- a/04_generated_documentation/04_architecture_design/hld.md +++ b/04_generated_documentation/04_architecture_design/hld.md @@ -1,7 +1,8 @@ --- id: HLD-ATB -version: 2.0.0 -status: Reviewed — Stage 7 design baseline; runtime validation pending +parent_ids: [UC-001, UC-002, UC-003, UC-004, UC-005, UC-006, UC-007, UC-008, UC-009, UC-010, UC-011, UC-012, UC-013, UC-014, UC-015, UC-016, UC-017, UC-018, UC-019, UC-020, UC-021, UC-022, UC-023, UC-024, UC-025, UC-026] +version: 3.0.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending last_cr: CR-001 --- @@ -10,63 +11,70 @@ last_cr: CR-001 | Field | Value | |---|---| | **System** | Agriculture Trading Backoffice (ATB) | -| **Pattern** | FastAPI modular monolith, tenant isolation through PostgreSQL RLS | +| **Pattern** | FastAPI modular monolith with React/TypeScript client; PostgreSQL tenant RLS | | **Technology authority** | `tech-profile.yaml` | -| **Architecture status** | Stage 7 design baseline approved; runtime and production operations proof remain pending | -| **Stage 7 focus** | UC-001, UC-005, UC-006, UC-007, UC-011, UC-014, UC-017, UC-019, UC-020 | +| **Architecture baseline** | Stage 7 patterns approved by human lead (`DEC-021`) | +| **Stage 9 status** | Full-breadth module ownership and service boundaries designed; runtime validation pending | +| **Requirements scope** | 26 UCs, 54 FRs; Stage 8 SRS catalog | -## 1. Logical Architecture +## 1. Deployment and Trust Boundary -```mermaid -graph TD - Browser[React + TypeScript SPA] -->|OIDC PKCE / HTTPS| IdP[Keycloak] - Browser -->|JWT bearer / HTTPS| Edge[Ingress / TLS] - Edge --> API[FastAPI modular monolith] - API --> IAM[Identity validation + role policy] - API --> Tenant[Membership/context resolver] - API --> Domain[Receiving / Quality / Inventory / Finance] - API --> PG[(PostgreSQL + RLS + audit + outbox)] - Worker[Background worker] --> PG - Worker --> Stream[Valkey Streams / cache] - Worker --> Notify[Messaging adapter] - API --> ObjectStore[Private document storage] - Ops[Telemetry / alerting] <-- API - Ops <-- Worker -``` +React SPA communicates with the FastAPI API over HTTPS and uses the configured Keycloak OIDC/PKCE identity flow. The API validates the configured JWT bearer credentials. Exact session termination/revocation semantics remain open under `AMB-009`; no token algorithm, lifetime or revocation SLA is invented here. Tenant membership and role are resolved server-side before a transaction-local PostgreSQL tenant context is established. RLS policies scope every tenant-owned row. A client tenant selector never confers authorization. -The API and worker are separately scaled processes from one modular-monolith codebase. PostgreSQL is the source of truth for business state, audit records, and pending events. Valkey is an acceleration/delivery component only; loss of Valkey must not lose committed business transactions. Object storage is a candidate dependency for POD and other uploaded documents; provider and retention controls require review because the technology profile does not select a storage provider. +The API, outbox publisher, and workers run as separately scalable processes from one modular-monolith codebase. PostgreSQL is the authoritative source for domain state, financial/stock ledgers, audit, and outbox. Valkey is used for cache and event delivery only; it is not the source of truth. Object storage is behind a tenant-aware document port; production provider, region, encryption configuration, and retention behavior remain unselected. Hosting provider and topology sizing remain provider-neutral. -## 2. Module Boundaries +## 2. Module and UC Ownership -| Module | Owning use cases in Stage 7 scope | Owns | Must not own | +| HLD Component | Owning UCs / FR scope | Responsibility and boundary | LLD | |---|---|---|---| -| Identity & authorization | UC-001 | OIDC session establishment, authorization decision, logout contract | Membership lifecycle or trusted tenant selection | -| Tenant control plane | UC-018, UC-019 | Tenant lifecycle, memberships, verified active context | Tenant-owned business records | -| Tenant isolation & audit | UC-017, UC-020 | RLS enforcement, cross-resource isolation, governed mutation history, support access | Ordinary feature authorization policy | -| Receiving | UC-005 | Gate/weighment records, GRN posting, inward lot identity | QC release decision or stock read model | -| Quality | UC-006 | Inspection evidence, QC state transitions, lot lineage | Client-side-only state enforcement | -| Inventory | UC-007 | Append-only stock movements, position projection, reconciliation | Direct mutation of posted ledger history | -| Finance | UC-011 (with UC-004/008/009/012 at Stage 9) | Receivables, credit lock, receipt and reversal | External payment execution; none is specified in the BRD | -| Operational events | UC-014 (with UC-003/015 at Stage 9) | Reliable event delivery, alert evaluation, reporting projections | Source-of-truth business state | +| `HLD-IAM` | UC-001 / FR-AUTH-001–003 | OIDC session validation, authorization policy, logout application contract; membership is owned separately | LLD-001 | +| `HLD-TENANCY` | UC-018/019 / FR-TENANTLIFECYCLE-001, FR-TENANTMEMBERSHIPCONTEXT-001/002 | Tenant control-plane lifecycle, membership administration, verified active context | LLD-002 | +| `HLD-ISOLATION-AUDIT` | UC-017/020 / tenant isolation, audit and privileged support FRs | RLS wrapper, tenant ownership for async/export/file/cache paths, append-only mutation audit, controlled support access | LLD-002 | +| `HLD-MARKET-DESK` | UC-002 / FR-MKT-001/002 | Manual APMC observation, arrival, price range and modal rate capture | LLD-007 | +| `HLD-REPORTING` | UC-003/015 / analytics and dashboard FRs | Read models and tenant-scoped reports; no authoritative ledger writes | LLD-005 | +| `HLD-PROCUREMENT` | UC-004 / procurement contract, credit terms and levy FRs | Sauda, supplier terms, modal-price comparison, configured levy computation | LLD-004 | +| `HLD-RECEIVING` | UC-005 / inward receipt and GRN FRs | Gate entry, manual weighment, calculation and atomic GRN posting | LLD-003 | +| `HLD-QUALITY` | UC-006 / QC inspection, hold/release, lineage FRs | Quality measures, state machine, quality calculation, lot lineage | LLD-003 | +| `HLD-INVENTORY` | UC-007 / stock, capacity and transfer FRs | Append-only double-entry movement ledger and derived positions | LLD-003 | +| `HLD-SALES` | UC-008 / contract, credit check, allocation FRs | Sales contract and atomic eligible-lot reservation | LLD-004 | +| `HLD-DISPATCH` | UC-009 / dispatch, manifest, delivery FRs | Eligible dispatch transitions, manual outward weighment, POD references | LLD-004 | +| `HLD-FLEET` | UC-010 / FR-FLEETREGISTRY-001 | Tenant fleet master and maintenance assignment exclusion | LLD-009 | +| `HLD-RECEIVABLES` | UC-011 / receivable, credit, receipt FRs | Immutable receivable events, exposure/lock, receipt and compensating reversal | LLD-004 | +| `HLD-PAYABLES` | UC-012 / FR-SUPPLIERPAYABLES-001 | Accepted-GRN payable projection and aging; no payment execution connector | LLD-004 | +| `HLD-EXPENSES` | UC-013 / FR-OPERATINGEXPENSES-001 | Balanced operational-expense vouchers and cash/bank ledger link | LLD-009 | +| `HLD-EVENTS-ALERTS` | UC-014 / FR-OPERATIONALALERTS-001 | Transactional outbox, idempotent event consumption, alert lifecycle | LLD-005 | +| `HLD-MASTERDATA` | UC-016 / FR-MASTERDATA-001/002 | Tenant-scoped commodity, grade, supplier, customer and godown reference data | LLD-008 | +| `HLD-PRIVACY-INCIDENT-LIFECYCLE` | UC-021–024 / purpose, rights, breach, retention FRs | Fiduciary-scoped privacy records, evidence, legal holds and controlled lifecycle | LLD-006, LLD-011 | +| `HLD-PROCESSOR-GOVERNANCE` | UC-025 / FR-PROCESSORGOVERNANCE-001 | Operator-controlled processor/subprocessor inventory and due diligence | LLD-011 | +| `HLD-TENANT-POLICY` | UC-026 / FR-TENANTOPERATINGPOLICIES-001 | Effective-dated tenant policy, business-owner confirmation, workflow gating | LLD-010 | -## 3. Trust and Transaction Boundaries +Bounded contexts may share the same deployment and PostgreSQL cluster; ownership boundaries are enforced in application modules and transaction/repository interfaces. Cross-context state changes use explicit commands/events, not direct mutation of another module's tables. -1. Keycloak authenticates the user through configured OIDC/PKCE. The API validates the configured JWT bearer token; algorithm, lifetime and logout revocation semantics remain explicit security-design decisions. -2. The application resolves the active tenant through server-side membership and role checks (UC-019). A client-supplied tenant identifier or token claim alone is never trusted as authorization. -3. Each tenant database unit of work begins a transaction, sets transaction-local tenant context from the verified resolver, then performs queries under PostgreSQL RLS. Missing context fails closed. No request-scoped context may leak through a pooled connection. -4. A GRN, lot, stock movements, audit record and outbox event commit atomically. A QC Hold lot cannot be allocated or dispatched, even if a client bypasses the UI. -5. Financial correction uses compensating ledger entries and immutable history; it does not rewrite a posted receipt. Event consumers are idempotent. +## 3. Standard Command, Query and Transaction Template -These are candidate architecture patterns for lead review, not newly approved product requirements. +1. API dependency validates identity and resolves role and active tenant membership; system/platform administration uses a distinct control-plane authorization policy. +2. Command schema validates format and source-defined invariants; idempotency key is required for retryable posting/state-changing operations. +3. Application service opens a PostgreSQL transaction, sets verified tenant context transaction-locally, then reads/writes under RLS and applicable constraints. +4. A business transition, its immutable audit record, and any outbox record commit atomically. Financial and stock history is corrected with compensating entries. +5. Queries use tenant-filtered repository contracts and bounded pagination. Report projections are rebuildable from authoritative records and do not silently replace the ledger source. +6. Worker consumers validate tenant/resource ownership in the job payload, establish their own tenant context, and process at least once with idempotent effects. They never inherit ambient request state. -## 4. Operational Constraints to Prove +## 4. Cross-Context Patterns -- 50 tenant firms, up to 25 named users per tenant, and 250 concurrent active users; run the accepted 5× peak-hour load scenario (BRD-NFR-012 / AMB-008). -- Tenant reports across at least 50,000 ledger rows meet the 1-second report target (BRD-NFR-004). -- Core financial conversions preserve 3-decimal weight and 2-decimal currency precision (BRD-NFR-001). -- Tenant isolation fails closed for API, DB, exports, files, cache, jobs, and support paths (BRD-NFR-006/010). -- Availability/recovery evidence must meet BRD-NFR-011. No provider or instance size is selected in this spike. +- **Isolation and audit:** Approved Stage 7 `DEC-021` patterns; detailed controls in LLD-002 and `database_design.md`. +- **Outbox/events:** PostgreSQL outbox is durable source; Valkey Streams is delivery transport; retries are at-least-once, consumers are idempotent. No exactly-once claim. +- **Ledger integrity:** Stock, receivables and cash/bank postings are append-only balanced journals; current positions/exposure are derived or transactionally maintained projections with reconciliation. +- **Policy:** Effective-dated tenant values are versioned; an unreviewed value blocks only affected risk-sensitive operations. +- **Privacy:** Purpose, responsible fiduciary, tenant/platform scope and sensitivity remain separate metadata; legal deadlines/retention durations are configurable approved inputs, not constants (`AMB-006`). +- **External services:** Keycloak is configured for identity. No weighbridge or payment execution integration is added; messaging channel and document-storage production providers remain unselected (`AMB-009`). -## 5. Design Status +## 5. Quality and Operational Constraints -This HLD is a Stage 7 candidate. The design walkthrough is recorded in `architecture_spike_report.md`; runtime integration, RLS, failure-injection, and load validation have not run because the repository has no product application implementation or deployment environment yet. Do not mark it Validated or Baseline until the human lead accepts the decisions and required evidence is produced. +- Availability ≥99.9% monthly; RTO ≤4 h; RPO ≤15 min; encrypted daily PITR backups retained 35 days and quarterly restore exercises (`BRD-NFR-011`). +- Capacity validation envelope: 50 tenants, up to 25 named users/tenant, 250 concurrent active users; report validation at 50,000 ledger rows/tenant; provisional load scenario 200 documents/tenant/operating day with 5× peak-hour burst. No fixed document quota; fair-share thresholds require test evidence (`BRD-NFR-004`, `BRD-NFR-012`, `AMB-008`). +- Reports obey FR-specific targets, including dashboard ≤1.5 s and sub-second 20-day report where stated; Stage 13+ load evidence is still required. +- Currency/weight precision, privacy handling, and OWASP ASVS v5.0.0 Level 2 trace to source NFRs; exact applicability and legal schedule remain reviewable under `AMB-006`. + +## 6. Design Status and Review Points + +This document completes the Stage 9 logical decomposition; supporting endpoint, entity/constraint, and adapter contracts are in `api_design.md`, `database_design.md`, and `integration_design.md`. It is a design artifact, not implemented/runtime validation. Before construction, confirm the endpoint and entity contracts at Gate 9.1. Provider deployment choices, exact Keycloak logout contract, tax identifier validation, privacy legal timing/retention, and load-derived fairness thresholds remain open as recorded ambiguities. diff --git a/04_generated_documentation/04_architecture_design/integration_design.md b/04_generated_documentation/04_architecture_design/integration_design.md new file mode 100644 index 0000000..8ba6204 --- /dev/null +++ b/04_generated_documentation/04_architecture_design/integration_design.md @@ -0,0 +1,52 @@ +--- +id: INT-DESIGN-001 +parent_ids: [HLD-ATB, UC-001, UC-005, UC-009, UC-014, UC-017, UC-018, UC-019, UC-020, UC-021, UC-022, UC-023, UC-024, UC-025] +version: 1.0.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending +last_cr: none +--- + +# Integration Design — Identity, Events and External Boundaries + +| Field | Value | +|---|---| +| **Architecture basis** | Approved Stage 7 patterns (`DEC-021`) | +| **Configured adapters** | Keycloak identity, payment sandbox, messaging sandbox in `tech-profile.yaml` | +| **Production provider status** | Keycloak configured; messaging/object-storage deployment choices not selected; payment gateway not in current FR scope | + +## 1. Keycloak OIDC identity provider + +- **Purpose / owning FRs:** OIDC authentication and session requirements (`FR-AUTH-001`, `FR-AUTH-003`); role policy enforcement is local and tenant membership is resolved by UC-019. +- **Flow:** Browser initiates the configured OIDC authorization-code flow with PKCE against the configured Keycloak realm/client. The application accepts a session only after validating issuer, audience/client, signature using provider metadata/JWKS, time claims and required authentication result. Exact allowed algorithm/lifetime and refresh/logout/revocation requirements remain for security review under `AMB-009`; no custom target is introduced. +- **Data boundary:** Do not place credentials or raw tokens in logs, audit payloads, URL analytics, or outbox events. Map stable provider subject to internal identity; resolve active tenant membership server-side on every request. Provider roles alone never establish tenant access. +- **Failure:** Invalid token or identity-provider/JWKS inability fails closed for protected operations; emit safe operational telemetry with correlation, not token values. Session/logout contract is detailed with Keycloak behavior before implementation. +- **Sandbox:** Use deterministic identity mock declared in `tech-profile.yaml` for offline tests; do not treat it as production IdP evidence. + +## 2. Transactional outbox and Valkey Streams + +- **Purpose:** Deliver business notifications/projections without losing an event after its source transaction commits; applies to receiving/inventory, finance and operational alert/reporting events. +- **Write:** In the same PostgreSQL transaction as the business state and audit record, append outbox row with tenant, event ID, aggregate ID/version, event type/schema version, occurred time, and minimal payload. Commit is the durability boundary. +- **Publish:** Worker claims pending rows, publishes using stable event ID to Valkey Streams, then marks delivery progress. Retry uses backoff and does not discard committed events. Valkey loss delays delivery but cannot lose source rows. +- **Consume:** Consumer deduplicates event ID in an inbox/idempotency table and applies its projection/alert transition once logically. Delivery guarantee is at least once; ordering is per aggregate/version where required. Poison events are isolated and surfaced for operator review; no silent deletion. +- **Tenant context:** Worker derives and validates tenant ownership from the persisted event envelope, sets transaction-local context, and uses RLS. It never trusts ambient API request context. + +## 3. Messaging provider boundary + +`FR-OPERATIONALALERTS-001` does not establish a production channel/provider or exact SMS/email timing. Define a `NotificationPort` with deterministic request/result and delivery status; connect the configured notification sandbox in offline tests. Production adapter, consent/notice requirements, retry and channel escalation remain unselected until product/channel decisions are approved. Failed delivery remains pending/failed and visible; never convert acceptance into a false “delivered” state. + +## 4. Explicitly absent/unselected connectors + +| Boundary | Stage 9 disposition | Reason / governing item | +|---|---|---| +| Physical weighbridge | No device connector; manual entry contract only | Current inward/outward FRs capture measurements, no device protocol (`RISK-005`, `RISK-009`). | +| Payment gateway | Not used for customer receipt capture or supplier payment execution | Current FRs record receipts and payables; they do not authorize payment execution. Payment sandbox remains unused until approved scope. | +| APMC/market feed | No live market feed; manual observation source is stored | `FR-MKT-001/002` require user-entered observation. | +| Object/document storage | Port and tenant/evidence metadata only; production provider, region, encryption/key management, lifecycle and signed-URL behavior unselected | POD, privacy and incident evidence require private storage; resolve provider controls under `AMB-009` before implementation. | +| Processor/subprocessor systems | Inventory only; no live integration | `FR-PROCESSORGOVERNANCE-001` manages due diligence and assistance records, not API connectivity. | + +## 5. Operational/security requirements + +- Secrets are managed outside source and database content; rotation and access are restricted by deployment policy (provider-neutral until deployment selection). +- Correlate API command, audit event, outbox event and delivery attempt without logging personal payloads, credentials, access tokens or unnecessary identity attributes. +- External failures must not partially commit a business command. Persist domain state and outbox atomically; async delivery failure is observable/retryable. +- Provider outage and retry behavior require deterministic sandbox/failure-injection tests during Construction. Design consistency is not runtime proof. diff --git a/04_generated_documentation/04_architecture_design/lld/LLD-001_auth_service.md b/04_generated_documentation/04_architecture_design/lld/LLD-001_auth_service.md index a19fae4..a68937e 100644 --- a/04_generated_documentation/04_architecture_design/lld/LLD-001_auth_service.md +++ b/04_generated_documentation/04_architecture_design/lld/LLD-001_auth_service.md @@ -1,7 +1,8 @@ --- id: LLD-001 -version: 2.0.0 -status: Reviewed — Stage 7 design baseline; runtime validation pending +parent_ids: [UC-001, UC-019] +version: 2.1.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending last_cr: CR-001 --- @@ -12,24 +13,26 @@ last_cr: CR-001 | **Component** | Identity & Access Management | | **Parent UCs** | UC-001; tenant context delegated to UC-019 (LLD-002) | | **Parent FRs** | FR-AUTH-001, FR-AUTH-002, FR-AUTH-003 | -| **Status** | Candidate; human-lead review pending | +| **Status** | Stage 9 detailed design; runtime/security validation pending | -## 1. Boundary and Candidate API Shape +## 1. Boundary and API Shape The module establishes authenticated application sessions and evaluates the BRD-FR-040 role permission matrix. Tenant membership/active-tenant resolution is performed by LLD-002. This module does not own RLS schema policies, tenant provisioning, cross-tenant support access, or a super-admin bypass. -| Method | Candidate route | Purpose | Contract status | -|---|---|---|---| -| POST | `/api/v1/auth/token` | Complete configured OIDC authorization-code/PKCE callback | Candidate; confirm at Stage 8/9 | -| POST | `/api/v1/auth/logout` | End the active application session | Candidate; endpoint and Keycloak operation need security review | -| GET | `/api/v1/auth/me` | Return authenticated subject and current role/context summary | Candidate; tenant fields only from verified LLD-002 context | +| Operation | Endpoint / boundary | Purpose | +|---|---|---| +| OIDC Authorization Code + PKCE | Browser ↔ configured Keycloak endpoints | Authenticate using configured identity provider; the provider callback is handled by the configured OIDC client flow, not a custom credential endpoint. | +| GET | `/api/v1/auth/session` | Return whether the application session is authenticated and the minimal current subject/context summary. | +| POST | `/api/v1/auth/logout` | End the active application session; exact Keycloak revocation mechanics remain AMB-009. | +| Policy decision | Protected API operation middleware/service | Enforce role/action/resource and segregation rules; no general-purpose authorization CRUD endpoint. | + Refresh endpoint, token lifetime, signing algorithm, refresh-token storage, revocation latency, and provider-session behavior are not fixed by UC-001 or `tech-profile.yaml`; do not treat earlier sample values as requirements. ## 2. Authentication Request Flow 1. React client starts Keycloak OIDC Authorization Code + PKCE. -2. Callback handler exchanges the authorization response using the configured client; the server validates issuer, audience, expiry, signature/JWKS and nonce/state according to approved security settings. +2. The configured OIDC client completes the authorization response and validates issuer, audience, time claims, signature/JWKS and state/nonce according to approved security settings. 3. Establish an application session using the configured JWT bearer-token approach. Reject malformed, invalid, expired or unauthenticated sessions. 4. For a tenant operation, call the membership/context resolver described in LLD-002 and apply the role/action policy. No client-supplied role or tenant identifier grants access. 5. Logout ends the application session and subsequent protected operations using that session are denied; exact IdP revocation mechanics and timing are open design decisions. @@ -56,4 +59,14 @@ Input is authenticated subject, verified tenant context (when the resource is te | Logout then reuse ended session | Protected action denied; no specific revocation latency asserted | | Tenant selector forged or membership inactive | LLD-002 rejects before tenant-scoped data access | -**Runtime validation:** pending implementation and approved security settings. This document is a Stage 7 candidate, not proof of an executed walking skeleton. +**Runtime validation:** pending implementation and approved security settings. This is a Stage 9 design contract, not proof of an executed walking skeleton. + +## Stage 9 SRS Traceability + +| Parent FR | SRS | HLD component | +|---|---|---| +| `FR-AUTH-001` | `SRS-AUTH-001` | `HLD-IAM` | +| `FR-AUTH-002` | `SRS-AUTH-002` | `HLD-IAM` | +| `FR-AUTH-003` | `SRS-AUTH-003` | `HLD-IAM` | + +Detailed API, entity and integration contracts are in the Stage 9 shared design documents. diff --git a/04_generated_documentation/04_architecture_design/lld/LLD-002_tenant_context_and_isolation.md b/04_generated_documentation/04_architecture_design/lld/LLD-002_tenant_context_and_isolation.md index 66930c3..e83710b 100644 --- a/04_generated_documentation/04_architecture_design/lld/LLD-002_tenant_context_and_isolation.md +++ b/04_generated_documentation/04_architecture_design/lld/LLD-002_tenant_context_and_isolation.md @@ -1,7 +1,8 @@ --- id: LLD-002 -version: 1.0.0 -status: Reviewed — Stage 7 design baseline; runtime validation pending +parent_ids: [UC-001, UC-017, UC-018, UC-019, UC-020] +version: 1.1.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending last_cr: none --- @@ -21,7 +22,7 @@ last_cr: none 4. Authorization evaluates the action/resource against the BRD-FR-040 permission matrix. The resolver returns an immutable request context `(subject_id, tenant_id, role_ids, correlation_id)` for that request. 5. No active membership or suspended tenant returns a deny result; no fallback to a platform-wide tenant context. -## 2. PostgreSQL RLS Contract (Candidate) +## 2. PostgreSQL RLS Contract - Every tenant-owned table has a non-null `tenant_id` and tenant-leading lookup/index keys where appropriate. - Set context only inside an open transaction, using a parameterized call equivalent to `set_config('app.tenant_id', :tenant_id, true)`. The final `true` makes the setting transaction-local and protects pooled connections. @@ -55,3 +56,20 @@ For a governed business mutation, append an audit entry in the same transaction | Ordinary support identity requests tenant data without approved grant | Denied and audited | **Runtime validation:** pending implementation and isolated PostgreSQL environment; this contract is not yet proven by execution. + +## Stage 9 SRS Traceability + +| Parent FR | SRS | HLD component | +|---|---|---| +| `FR-AUTH-001` | `SRS-AUTH-001` | `HLD-IAM` | +| `FR-AUTH-002` | `SRS-AUTH-002` | `HLD-IAM` | +| `FR-AUTH-003` | `SRS-AUTH-003` | `HLD-IAM` | +| `FR-TENANTSECURITYAUDIT-001` | `SRS-TENANTSECURITYAUDIT-001` | `HLD-ISOLATION-AUDIT` | +| `FR-TENANTSECURITYAUDIT-003` | `SRS-TENANTSECURITYAUDIT-003` | `HLD-ISOLATION-AUDIT` | +| `FR-TENANTLIFECYCLE-001` | `SRS-TENANTLIFECYCLE-001` | `HLD-TENANCY` | +| `FR-TENANTMEMBERSHIPCONTEXT-001` | `SRS-TENANTMEMBERSHIPCONTEXT-001` | `HLD-TENANCY` | +| `FR-TENANTMEMBERSHIPCONTEXT-002` | `SRS-TENANTMEMBERSHIPCONTEXT-002` | `HLD-TENANCY` | +| `FR-TENANTSUPPORTSECURITY-001` | `SRS-TENANTSUPPORTSECURITY-001` | `HLD-ISOLATION-AUDIT` | +| `FR-TENANTSUPPORTSECURITY-002` | `SRS-TENANTSUPPORTSECURITY-002` | `HLD-ISOLATION-AUDIT` | + +Detailed API, entity and integration contracts are in the Stage 9 shared design documents. diff --git a/04_generated_documentation/04_architecture_design/lld/LLD-003_receiving_quality_inventory.md b/04_generated_documentation/04_architecture_design/lld/LLD-003_receiving_quality_inventory.md index fc767c9..6fe6ac2 100644 --- a/04_generated_documentation/04_architecture_design/lld/LLD-003_receiving_quality_inventory.md +++ b/04_generated_documentation/04_architecture_design/lld/LLD-003_receiving_quality_inventory.md @@ -1,7 +1,8 @@ --- id: LLD-003 -version: 1.0.0 -status: Reviewed — Stage 7 design baseline; runtime validation pending +parent_ids: [UC-005, UC-006, UC-007] +version: 1.1.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending last_cr: none --- @@ -11,7 +12,7 @@ last_cr: none |---|---| | **Parent UCs** | UC-005, UC-006, UC-007 | | **Parent FRs** | FR-INWARDRECEIVING-001, FR-INWARDRECEIVING-002, FR-INWARDRECEIVING-003, FR-INWARDRECEIVING-004, FR-INWARDRECEIVING-005, FR-INWARDRECEIVING-006; FR-QUALITYANDLOTCONTROL-001, FR-QUALITYANDLOTCONTROL-002, FR-QUALITYANDLOTCONTROL-003, FR-QUALITYANDLOTCONTROL-004; FR-WAREHOUSEINVENTORY-001, FR-WAREHOUSEINVENTORY-002, FR-WAREHOUSEINVENTORY-003 | -| **Status** | Candidate; design review pending | +| **Status** | Stage 9 detailed design; runtime validation pending | ## 1. Component Contracts @@ -46,3 +47,23 @@ A godown transfer is modeled as one transfer aggregate with origin deduction, in - Outbox worker outage leaves committed source event pending for retry; repeated delivery has one logical effect. **Runtime validation:** pending; scenario results in the spike report are design reasoning, not executed test results. + +## Stage 9 SRS Traceability + +| Parent FR | SRS | HLD component | +|---|---|---| +| `FR-INWARDRECEIVING-001` | `SRS-INWARDRECEIVING-001` | `HLD-RECEIVING` | +| `FR-INWARDRECEIVING-002` | `SRS-INWARDRECEIVING-002` | `HLD-RECEIVING` | +| `FR-INWARDRECEIVING-003` | `SRS-INWARDRECEIVING-003` | `HLD-RECEIVING` | +| `FR-INWARDRECEIVING-004` | `SRS-INWARDRECEIVING-004` | `HLD-RECEIVING` | +| `FR-INWARDRECEIVING-005` | `SRS-INWARDRECEIVING-005` | `HLD-RECEIVING` | +| `FR-INWARDRECEIVING-006` | `SRS-INWARDRECEIVING-006` | `HLD-RECEIVING` | +| `FR-QUALITYANDLOTCONTROL-001` | `SRS-QUALITYANDLOTCONTROL-001` | `HLD-QUALITY` | +| `FR-QUALITYANDLOTCONTROL-002` | `SRS-QUALITYANDLOTCONTROL-002` | `HLD-QUALITY` | +| `FR-QUALITYANDLOTCONTROL-003` | `SRS-QUALITYANDLOTCONTROL-003` | `HLD-QUALITY` | +| `FR-QUALITYANDLOTCONTROL-004` | `SRS-QUALITYANDLOTCONTROL-004` | `HLD-QUALITY` | +| `FR-WAREHOUSEINVENTORY-001` | `SRS-WAREHOUSEINVENTORY-001` | `HLD-INVENTORY` | +| `FR-WAREHOUSEINVENTORY-002` | `SRS-WAREHOUSEINVENTORY-002` | `HLD-INVENTORY` | +| `FR-WAREHOUSEINVENTORY-003` | `SRS-WAREHOUSEINVENTORY-003` | `HLD-INVENTORY` | + +Detailed API, entity and integration contracts are in the Stage 9 shared design documents. diff --git a/04_generated_documentation/04_architecture_design/lld/LLD-004_financial_controls.md b/04_generated_documentation/04_architecture_design/lld/LLD-004_financial_controls.md index 04a5dfd..5ef970b 100644 --- a/04_generated_documentation/04_architecture_design/lld/LLD-004_financial_controls.md +++ b/04_generated_documentation/04_architecture_design/lld/LLD-004_financial_controls.md @@ -1,7 +1,8 @@ --- id: LLD-004 -version: 1.0.0 -status: Reviewed — Stage 7 design baseline; runtime validation pending +parent_ids: [UC-004, UC-008, UC-009, UC-011, UC-012] +version: 1.1.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending last_cr: none --- @@ -11,7 +12,7 @@ last_cr: none |---|---| | **Parent UCs** | UC-004, UC-008, UC-009, UC-011, UC-012 | | **Parent FRs** | FR-PROCUREMENTCONTRACTS-001, FR-PROCUREMENTCONTRACTS-002, FR-PROCUREMENTCONTRACTS-003, FR-PROCUREMENTCONTRACTS-004; FR-SALESCONTRACTS-001, FR-SALESCONTRACTS-002, FR-SALESCONTRACTS-003; FR-DISPATCHDELIVERY-001, FR-DISPATCHDELIVERY-002, FR-DISPATCHDELIVERY-003; FR-CUSTOMERRECEIVABLES-001, FR-CUSTOMERRECEIVABLES-002, FR-CUSTOMERRECEIVABLES-003, FR-CUSTOMERRECEIVABLES-004; FR-SUPPLIERPAYABLES-001 | -| **Status** | Candidate; design review pending | +| **Status** | Stage 9 detailed design; runtime validation pending | ## 1. Financial Consistency Rules @@ -22,11 +23,11 @@ last_cr: none - A Partner override is an explicit authorized command with mandatory justification and an immutable audit event; it does not mutate the historical lock decision. - No external payment execution API is assumed; the BRD currently records received instruments and statuses. -## 2. Candidate Data/Command Shape +## 2. Data/Command Shape `PartyLedgerEntry(tenant_id, party_id, source_type, source_id, entry_type, debit, credit, currency, effective_at, reversal_of, idempotency_key)`; account/tenant uniqueness is enforced in the database. `CreditControl` stores the sanctioned limit and lock state/version. Derived outstanding/exposure values must be reconciled to the immutable journal and not maintained as an independent source of truth. -Commands: `ConfirmSalesOrder`, `RecordReceipt`, `MarkReceiptBounced`, `OverrideCreditLock`. Each command carries tenant context from LLD-002, actor, correlation id and idempotency key. Endpoint shape and source documents are to be derived at Stage 8/9. +Commands: `ConfirmSalesOrder`, `RecordReceipt`, `MarkReceiptBounced`, `OverrideCreditLock`. Each command carries tenant context from LLD-002, actor, correlation id and idempotency key. Endpoint and source-document contract is detailed in `api_design.md`; transaction/entity mapping is in `database_design.md`. ## 3. Validation Cases @@ -37,3 +38,25 @@ Commands: `ConfirmSalesOrder`, `RecordReceipt`, `MarkReceiptBounced`, `OverrideC - Every financial write is tenant-isolated and has an attributable audit record. **Runtime validation:** pending implementation, schema, and load/concurrency evidence. + +## Stage 9 SRS Traceability + +| Parent FR | SRS | HLD component | +|---|---|---| +| `FR-PROCUREMENTCONTRACTS-001` | `SRS-PROCUREMENTCONTRACTS-001` | `HLD-PROCUREMENT` | +| `FR-PROCUREMENTCONTRACTS-002` | `SRS-PROCUREMENTCONTRACTS-002` | `HLD-PROCUREMENT` | +| `FR-PROCUREMENTCONTRACTS-003` | `SRS-PROCUREMENTCONTRACTS-003` | `HLD-PROCUREMENT` | +| `FR-PROCUREMENTCONTRACTS-004` | `SRS-PROCUREMENTCONTRACTS-004` | `HLD-PROCUREMENT` | +| `FR-SALESCONTRACTS-001` | `SRS-SALESCONTRACTS-001` | `HLD-SALES` | +| `FR-SALESCONTRACTS-002` | `SRS-SALESCONTRACTS-002` | `HLD-SALES` | +| `FR-SALESCONTRACTS-003` | `SRS-SALESCONTRACTS-003` | `HLD-SALES` | +| `FR-DISPATCHDELIVERY-001` | `SRS-DISPATCHDELIVERY-001` | `HLD-DISPATCH` | +| `FR-DISPATCHDELIVERY-002` | `SRS-DISPATCHDELIVERY-002` | `HLD-DISPATCH` | +| `FR-DISPATCHDELIVERY-003` | `SRS-DISPATCHDELIVERY-003` | `HLD-DISPATCH` | +| `FR-CUSTOMERRECEIVABLES-001` | `SRS-CUSTOMERRECEIVABLES-001` | `HLD-RECEIVABLES` | +| `FR-CUSTOMERRECEIVABLES-002` | `SRS-CUSTOMERRECEIVABLES-002` | `HLD-RECEIVABLES` | +| `FR-CUSTOMERRECEIVABLES-003` | `SRS-CUSTOMERRECEIVABLES-003` | `HLD-RECEIVABLES` | +| `FR-CUSTOMERRECEIVABLES-004` | `SRS-CUSTOMERRECEIVABLES-004` | `HLD-RECEIVABLES` | +| `FR-SUPPLIERPAYABLES-001` | `SRS-SUPPLIERPAYABLES-001` | `HLD-PAYABLES` | + +Detailed API, entity and integration contracts are in the Stage 9 shared design documents. diff --git a/04_generated_documentation/04_architecture_design/lld/LLD-005_reporting_and_events.md b/04_generated_documentation/04_architecture_design/lld/LLD-005_reporting_and_events.md index b0fd798..7715fe7 100644 --- a/04_generated_documentation/04_architecture_design/lld/LLD-005_reporting_and_events.md +++ b/04_generated_documentation/04_architecture_design/lld/LLD-005_reporting_and_events.md @@ -1,7 +1,8 @@ --- id: LLD-005 -version: 1.0.0 -status: Reviewed — Stage 7 design baseline; runtime validation pending +parent_ids: [UC-003, UC-014, UC-015, UC-005] +version: 1.1.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending last_cr: none --- @@ -11,13 +12,13 @@ last_cr: none |---|---| | **Parent UCs** | UC-003, UC-014, UC-015; consumes events from UC-005–012 | | **Parent FRs** | FR-MARKETTRENDANALYTICS-001; FR-OPERATIONALALERTS-001; FR-EXECUTIVEREPORTING-001, FR-EXECUTIVEREPORTING-002 | -| **Status** | Candidate; design review pending | +| **Status** | Stage 9 detailed design; runtime validation pending | ## 1. Source-of-Truth and Event Delivery - Domain mutations write a versioned outbox row in the same transaction as the business state and audit record. The outbox is the durable source; Valkey Streams is a delivery/cache mechanism configured in `tech-profile.yaml`. - A worker publishes eligible outbox records, records delivery attempts, and retries transient failures with bounded backoff. Consumers use `(tenant_id, event_id)` for idempotency and preserve tenant context for each read/write. -- If Valkey or the messaging adapter is unavailable, source transactions may commit; delivery is delayed and observable, not silently dropped. Dead-letter/manual replay policy and retention require lead review. +- If Valkey or the messaging adapter is unavailable, source transactions may commit; delivery is delayed and observable, not silently dropped. Poison-event retention and manual replay authorization remain open under AMB-011; events are isolated and surfaced, never silently discarded. - Alert evaluation is based on source events plus periodic reconciliation so a missed event cannot permanently suppress an active alert. Only channels supported by approved messaging configuration are enabled. ## 2. Read Models and Performance @@ -34,3 +35,14 @@ last_cr: none - Rebuilt report summary matches the source ledger within defined freshness and exact financial/quantity precision. **Runtime validation:** pending offline sandbox, load profile, and implementation. + +## Stage 9 SRS Traceability + +| Parent FR | SRS | HLD component | +|---|---|---| +| `FR-MARKETTRENDANALYTICS-001` | `SRS-MARKETTRENDANALYTICS-001` | `HLD-REPORTING` | +| `FR-OPERATIONALALERTS-001` | `SRS-OPERATIONALALERTS-001` | `HLD-EVENTS-ALERTS` | +| `FR-EXECUTIVEREPORTING-001` | `SRS-EXECUTIVEREPORTING-001` | `HLD-REPORTING` | +| `FR-EXECUTIVEREPORTING-002` | `SRS-EXECUTIVEREPORTING-002` | `HLD-REPORTING` | + +Detailed API, entity and integration contracts are in the Stage 9 shared design documents. diff --git a/04_generated_documentation/04_architecture_design/lld/LLD-006_privacy_lifecycle.md b/04_generated_documentation/04_architecture_design/lld/LLD-006_privacy_lifecycle.md index bec1041..a54cfe4 100644 --- a/04_generated_documentation/04_architecture_design/lld/LLD-006_privacy_lifecycle.md +++ b/04_generated_documentation/04_architecture_design/lld/LLD-006_privacy_lifecycle.md @@ -1,7 +1,8 @@ --- id: LLD-006 -version: 1.0.0 -status: Reviewed — Stage 7 design baseline; runtime validation pending +parent_ids: [UC-023, UC-024] +version: 1.1.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending last_cr: none --- @@ -9,9 +10,9 @@ last_cr: none | Field | Value | |---|---| -| **Parent UCs** | UC-023, UC-024 (interfaces to UC-021/022/025) | +| **Parent UCs** | UC-023, UC-024 | | **Parent FRs** | FR-PRIVACYBREACHRESPONSE-001; FR-RETENTIONERASURE-001 | -| **Status** | Candidate; legal/security review pending | +| **Status** | Stage 9 detailed design; legal/runtime validation pending | ## 1. Privacy-Safe Architecture Boundaries @@ -29,3 +30,12 @@ last_cr: none - Incident evidence access creates a separate audit entry and excludes secrets from service telemetry. **Runtime/legal validation:** pending qualified legal review, approved schedules and implementation. + +## Stage 9 SRS Traceability + +| Parent FR | SRS | HLD component | +|---|---|---| +| `FR-PRIVACYBREACHRESPONSE-001` | `SRS-PRIVACYBREACHRESPONSE-001` | `HLD-PRIVACY-INCIDENT-LIFECYCLE` | +| `FR-RETENTIONERASURE-001` | `SRS-RETENTIONERASURE-001` | `HLD-PRIVACY-INCIDENT-LIFECYCLE` | + +Detailed API, entity and integration contracts are in the Stage 9 shared design documents. diff --git a/04_generated_documentation/04_architecture_design/lld/LLD-007_market_observations.md b/04_generated_documentation/04_architecture_design/lld/LLD-007_market_observations.md new file mode 100644 index 0000000..b4bb3cc --- /dev/null +++ b/04_generated_documentation/04_architecture_design/lld/LLD-007_market_observations.md @@ -0,0 +1,47 @@ +--- +id: LLD-007 +parent_ids: [UC-002] +version: 1.0.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending +last_cr: none +--- + +# LLD-007 — Market Observations & Daily Mandi Rates + +| Field | Value | +|---|---| +| **Parent UCs** | UC-002 | +| **Parent FRs** | FR-MKT-001, FR-MKT-002 | +| **Stage 8 SRS** | SRS-MKT-001, SRS-MKT-002 | +| **Architecture reference** | `DEC-021`; approved Stage 7 template | +| **Status** | Stage 9 detailed design; runtime validation pending | + +## 1. Aggregate and invariants + +`MarketObservation` is the tenant-scoped daily record keyed by market yard, commodity, variety, and observation date. It stores grade, arrival quantity (MT), internal stock position (MT), source, observed-at timestamp, and status. A tenant-scoped unique constraint prevents duplicate yard/commodity/variety/date records. `Closed / Mandi Holiday` is an explicit status that permits arrival quantity to be absent when no observation is available; it is not represented as a fabricated zero arrival. Observation dates after the business current date and negative arrivals are rejected; zero is valid. + +Price range and modal rate are fields of the daily observation. Rates use INR per quintal and must each be positive, with `min_rate <= modal_rate <= max_rate`; the service returns the violated arithmetic predicate in validation errors. + +## 2. Command/query boundaries + +- `MarketObservationService.record(...)` validates tenant, actor role, required fields, date, status, and unique key before inserting. +- `MarketObservationService.set_rates(...)` validates the three-rate invariant and updates the rate set atomically; concurrent updates use row versioning. +- `MarketObservationQuery.list(...)` filters by tenant and explicit date/market/commodity criteria; sorting and page limits are explicit in the API design. +- The domain records user-entered source and timestamp; no external APMC data feed is assumed. + +## 3. Persistence, audit and events + +Use PostgreSQL RLS and transaction-local tenant context. Record create/update as immutable audit events in the same transaction. Emit `market.observation.recorded` and `market.observation.rates_changed` through the transactional outbox only after the mutation is committed. A uniqueness conflict returns a duplicate-observation validation response without a second row or event. + +## 4. FR coverage + +`FR-MKT-001` maps to create/list observation operations. `FR-MKT-002` maps to the atomic rate-capture operation. Analytics in `FR-MARKETTRENDANALYTICS-001` read this source through the reporting design in LLD-005; no duplicate source of truth is created. + +## Stage 9 SRS Traceability + +| Parent FR | SRS | HLD component | +|---|---|---| +| `FR-MKT-001` | `SRS-MKT-001` | `HLD-MARKET-DESK` | +| `FR-MKT-002` | `SRS-MKT-002` | `HLD-MARKET-DESK` | + +Detailed API, entity and integration contracts are in the Stage 9 shared design documents. diff --git a/04_generated_documentation/04_architecture_design/lld/LLD-008_trading_master_data.md b/04_generated_documentation/04_architecture_design/lld/LLD-008_trading_master_data.md new file mode 100644 index 0000000..01d4b51 --- /dev/null +++ b/04_generated_documentation/04_architecture_design/lld/LLD-008_trading_master_data.md @@ -0,0 +1,40 @@ +--- +id: LLD-008 +parent_ids: [UC-016] +version: 1.0.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending +last_cr: none +--- + +# LLD-008 — Commodity, Counterparty & Godown Master Data + +| Field | Value | +|---|---| +| **Parent UCs** | UC-016 | +| **Parent FRs** | FR-MASTERDATA-001, FR-MASTERDATA-002 | +| **Stage 8 SRS** | SRS-MASTERDATA-001, SRS-MASTERDATA-002 | +| **Architecture reference** | `DEC-021`; approved Stage 7 template | +| **Status** | Stage 9 detailed design; runtime validation pending | + +## 1. Ownership and records + +This module owns tenant-scoped reference records for `Commodity`, `CommodityVariety`, `QualityGrade`, `Supplier`, `Customer`, and `Godown`. Commodity code is unique within a tenant. Commodity deletion is rejected while active stock-ledger references exist; inactive reference records remain resolvable by historical transactions. Supplier, customer, and godown codes are unique within their tenant/entity type. All business references include tenant ownership and are protected by RLS. + +Supplier credit days are restricted to the source-defined values 7, 15, and 21. Customer credit limit uses INR. Godown capacity uses MT. GSTIN/PAN validation is applied where relevant, but identifier applicability, accepted formats, and external verification expectations are unresolved under new `AMB-010`; no live tax-authority connector is assumed. + +## 2. API and lifecycle + +Create/read/update and deactivate operations are separated by resource. Deletes are soft deactivation where the FR bars deletion or historical transactions reference the record. Authorization uses the UC-001 role matrix within the verified tenant context. Master-data updates publish versioned outbox events so downstream caches/read models can invalidate; consumers are idempotent. + +## 3. Constraints and audit + +Enforce tenant-scoped unique constraints in PostgreSQL in addition to application checks. Validate enum, code, capacity, and credit-day rules at the application boundary and database constraint where representable. Tax identifier validation behavior must remain configurable until `AMB-010` is resolved. Audit changes with actor, tenant, prior/new values, timestamp, and reason when provided by the command. + +## Stage 9 SRS Traceability + +| Parent FR | SRS | HLD component | +|---|---|---| +| `FR-MASTERDATA-001` | `SRS-MASTERDATA-001` | `HLD-MASTERDATA` | +| `FR-MASTERDATA-002` | `SRS-MASTERDATA-002` | `HLD-MASTERDATA` | + +Detailed API, entity and integration contracts are in the Stage 9 shared design documents. diff --git a/04_generated_documentation/04_architecture_design/lld/LLD-009_fleet_and_expense.md b/04_generated_documentation/04_architecture_design/lld/LLD-009_fleet_and_expense.md new file mode 100644 index 0000000..317ee7f --- /dev/null +++ b/04_generated_documentation/04_architecture_design/lld/LLD-009_fleet_and_expense.md @@ -0,0 +1,38 @@ +--- +id: LLD-009 +parent_ids: [UC-010, UC-013] +version: 1.0.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending +last_cr: none +--- + +# LLD-009 — Fleet Registry & Operating Expense Services + +| Field | Value | +|---|---| +| **Parent UCs** | UC-010, UC-013 | +| **Parent FRs** | FR-FLEETREGISTRY-001, FR-OPERATINGEXPENSES-001 | +| **Stage 8 SRS** | SRS-FLEETREGISTRY-001, SRS-OPERATINGEXPENSES-001 | +| **Architecture reference** | `DEC-021`; approved Stage 7 template | +| **Status** | Stage 9 detailed design; runtime validation pending | + +## 1. Fleet registry + +`FleetVehicle` stores registration number, make/model, payload capacity (MT), ownership type, transporter name, operational status, insurance expiry where supplied, and fitness expiry. Registration number is unique within the owning tenant. Only eligible active vehicles may be assigned to a dispatch; status `Maintenance` is a hard rejection at both assignment and dispatch confirmation, including concurrent assignment checks. No live telematics or carrier API is specified. + +## 2. Expense voucher + +`ExpenseVoucher` records ID, date, category, amount INR, payee/vendor, optional consignment/sauda link, payment mode, and status. Category is limited to the FR-defined classes. Posting is an atomic double-entry cash/bank journal transaction: debit the selected expense account and credit the selected cash/bank account for equal currency amounts. An unbalanced or invalid account mapping cannot post. Draft/edit and post commands are distinct; a posted voucher is corrected through a compensating entry, not silent history rewrite. + +## 3. Boundaries and audit + +Both components use the verified tenant context and RLS. Fleet and voucher writes are auditable and idempotent where command retries are possible. Expense posting records the linked ledger transaction ID; no payment processor is invoked. Fleet status change emits an outbox event only where dispatch eligibility/read models consume it. + +## Stage 9 SRS Traceability + +| Parent FR | SRS | HLD component | +|---|---|---| +| `FR-FLEETREGISTRY-001` | `SRS-FLEETREGISTRY-001` | `HLD-FLEET` | +| `FR-OPERATINGEXPENSES-001` | `SRS-OPERATINGEXPENSES-001` | `HLD-EXPENSES` | + +Detailed API, entity and integration contracts are in the Stage 9 shared design documents. diff --git a/04_generated_documentation/04_architecture_design/lld/LLD-010_tenant_operating_policy.md b/04_generated_documentation/04_architecture_design/lld/LLD-010_tenant_operating_policy.md new file mode 100644 index 0000000..bdfd438 --- /dev/null +++ b/04_generated_documentation/04_architecture_design/lld/LLD-010_tenant_operating_policy.md @@ -0,0 +1,37 @@ +--- +id: LLD-010 +parent_ids: [UC-026] +version: 1.0.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending +last_cr: none +--- + +# LLD-010 — Effective-Dated Tenant Operating Policies + +| Field | Value | +|---|---| +| **Parent UCs** | UC-026 | +| **Parent FRs** | FR-TENANTOPERATINGPOLICIES-001 | +| **Stage 8 SRS** | SRS-TENANTOPERATINGPOLICIES-001 | +| **Architecture reference** | `DEC-021`; approved Stage 7 template | +| **Status** | Stage 9 detailed design; runtime validation pending | + +## 1. Policy model + +`TenantPolicy` versions a policy by tenant, policy type, applicable scope (commodity/grade/contract where relevant), unit, effective-from/to, review status, and source/version. Candidate seed values are never treated as approved business rules. A tenant Partner/Managing Director or delegated authorized business owner confirms or edits all applicable values before each affected risk-sensitive workflow is enabled. A missing or unreviewed policy blocks only the affected workflow. + +## 2. Read/write semantics + +Policy mutation is effective-dated and append-only by version. Updates require an authorized tenant role and reason; audit stores actor, timestamp, reason, previous value, and new value. Transaction commands resolve the policy version effective at the business event time and persist its version ID on the governed transaction where the FR requires later explainability. Tenant RLS prevents cross-tenant policy visibility or effect. + +## 3. Validation and eventing + +Reject overlapping effective intervals for the same tenant/type/scope unless the interval boundary is non-overlapping. Numeric type, unit and range must follow the owning FR/approved tenant value; no global operating threshold is invented. Policy confirmation/change emits an outbox event for affected services. Missing policy produces a typed `policy_not_reviewed` business denial; unrelated tenant workflows remain available. + +## Stage 9 SRS Traceability + +| Parent FR | SRS | HLD component | +|---|---|---| +| `FR-TENANTOPERATINGPOLICIES-001` | `SRS-TENANTOPERATINGPOLICIES-001` | `HLD-TENANT-POLICY` | + +Detailed API, entity and integration contracts are in the Stage 9 shared design documents. diff --git a/04_generated_documentation/04_architecture_design/lld/LLD-011_privacy_governance.md b/04_generated_documentation/04_architecture_design/lld/LLD-011_privacy_governance.md new file mode 100644 index 0000000..29dc060 --- /dev/null +++ b/04_generated_documentation/04_architecture_design/lld/LLD-011_privacy_governance.md @@ -0,0 +1,47 @@ +--- +id: LLD-011 +parent_ids: [UC-021, UC-022, UC-025] +version: 1.0.0 +status: Draft — Stage 9 design; Gate 9.1 passed, review pending +last_cr: none +--- + +# LLD-011 — Privacy Purpose, Rights & Processor Governance + +| Field | Value | +|---|---| +| **Parent UCs** | UC-021, UC-022, UC-025 | +| **Parent FRs** | FR-PRIVACYPURPOSECONSENT-001, FR-DATAPRINCIPALRIGHTS-001, FR-PROCESSORGOVERNANCE-001 | +| **Stage 8 SRS** | SRS-PRIVACYPURPOSECONSENT-001, SRS-DATAPRINCIPALRIGHTS-001, SRS-PROCESSORGOVERNANCE-001 | +| **Architecture reference** | `DEC-021`; approved Stage 7 template | +| **Status** | Stage 9 detailed design; runtime validation pending | + +## 1. Ownership and trust boundary + +The privacy governance module keeps tenant Data Fiduciary processing records separate from ATB operator processing records. A tenant administrator/reviewer can access only that tenant’s purpose, notice, request, and assistance records. Operator-only processor inventory and platform-processing records use a distinct control-plane authorization path; this is not a general cross-tenant support grant. The service covers natural persons without app accounts through an intake path that does not require a general customer/supplier portal login. + +## 2. Processing purpose and consent + +`ProcessingPurpose` stores purpose ID, data category, responsible entity/role, processing basis, notice version, accountable contact, and current state. `ConsentEvidence` is created only when the responsible Data Fiduciary has selected consent as the applicable basis; it stores notice evidence, timestamp, status, and withdrawal timestamp. A verified withdrawal causes the affected consent-dependent processing to be restricted, subject to an applicable legal retention obligation. Consent is not used as a default basis. + +## 3. Data Principal request case + +`RightsRequest` records request ID, principal reference, tenant/platform scope, request type, identity-verification evidence reference, responsible Data Fiduciary, received/due/resolved timestamps, disposition, and response evidence reference. Intake, verification, routing, response and completion are explicit states. Route to the responsible party; require a verified subject/scope match before disclosure or action. Due dates use an approved statutory/contractual rule input; do not hard-code deadlines while `AMB-006` remains open. Fail closed on ambiguous tenant/subject matching and preserve an auditable exception path. + +## 4. Processor/subprocessor records + +`ProcessorRecord` stores processor/subprocessor identity, processing purpose, data categories, location, contract/safeguard reference, due-diligence status, and incident/request assistance record. Review and assistance actions are attributable to an operator role and linked to applicable tenant instructions/contractual safeguards. This is an inventory and governance capability; it does not itself create a live integration with each listed processor. + +## 5. Data minimization and evidence + +Store evidence references and minimum metadata needed for review; do not duplicate complete identity documents or breach payloads without a scoped requirement. Privacy-case access is audited. Tenant-owned personal data remains under RLS. Exact retention periods, statutory deadlines and additional legal obligations stay unresolved under `AMB-006`; these are configurable/approved inputs, not constants in the domain model. + +## Stage 9 SRS Traceability + +| Parent FR | SRS | HLD component | +|---|---|---| +| `FR-PRIVACYPURPOSECONSENT-001` | `SRS-PRIVACYPURPOSECONSENT-001` | `HLD-PRIVACY-INCIDENT-LIFECYCLE` | +| `FR-DATAPRINCIPALRIGHTS-001` | `SRS-DATAPRINCIPALRIGHTS-001` | `HLD-PRIVACY-INCIDENT-LIFECYCLE` | +| `FR-PROCESSORGOVERNANCE-001` | `SRS-PROCESSORGOVERNANCE-001` | `HLD-PROCESSOR-GOVERNANCE` | + +Detailed API, entity and integration contracts are in the Stage 9 shared design documents. diff --git a/04_generated_documentation/04_architecture_design/stage9_human_review_brief.md b/04_generated_documentation/04_architecture_design/stage9_human_review_brief.md new file mode 100644 index 0000000..31e2731 --- /dev/null +++ b/04_generated_documentation/04_architecture_design/stage9_human_review_brief.md @@ -0,0 +1,32 @@ +--- +id: ARCH-REVIEW-009 +parent_ids: [HLD-ATB, API-DESIGN-001, DB-DESIGN-001, INT-DESIGN-001] +version: 1.0.0 +status: Draft — Stage 9 review brief; Gate 9.1 pending +last_cr: none +--- + +# Stage 9 Design Review Brief + +## Core problem and completed design + +Stage 8 produced one SRS for each of the 54 FRs. Stage 9 now assigns all 26 use cases to HLD components and LLD contracts, and provides explicit REST, PostgreSQL entity/constraint, and integration boundaries. The eight previously unmodeled low-risk use cases are covered by LLD-007 through LLD-011, applying the Stage 7 approved modular-monolith, tenant-context, RLS, audit and outbox patterns. + +## Decisions and trade-offs + +- Keep one modular-monolith codebase and separate bounded contexts; PostgreSQL remains authoritative, Valkey handles cache/stream delivery, and outbox consumers are at-least-once/idempotent. +- Use tenant-scoped uniqueness, RLS and transaction-local verified tenant context. Tenant/platform privacy records and control-plane administration remain separately authorized. +- Use append-only stock/financial journals and compensating corrections. Do not infer payment execution or physical weighbridge integration. +- Keep provider-neutral hosting and document storage because the project profile has not selected providers. + +## Assumptions and security boundaries + +All authenticated tenant operations resolve membership server-side. Background jobs re-establish and verify tenant context. Application runtime roles cannot bypass RLS. Legal timing/retention, tax-ID specifics, exact logout/session revocation, messaging provider/channel and object-storage controls remain open under `AMB-006`, `AMB-009`, and `AMB-010`. Design documents do not claim runtime or load proof. + +## Targeted review points + +1. Confirm proposed API paths/resource boundaries and public no-account privacy request intake boundary. +2. Review separation of tenant Data Fiduciary records from operator control-plane/processor governance records. +3. Confirm tax identifier validation scope and allowed formats (new `AMB-010`), and poison-event retention/replay authority (new `AMB-011`). +4. Confirm the balanced expense voucher ledger relationship and use of compensating entries. +5. Confirm which design choices require adjustment before Gate 9.1. diff --git a/prompts/20261011T074829Z-session-greenfield-bootstrap.md b/prompts/20261011T074829Z-session-greenfield-bootstrap.md index 629d855..12a4248 100644 --- a/prompts/20261011T074829Z-session-greenfield-bootstrap.md +++ b/prompts/20261011T074829Z-session-greenfield-bootstrap.md @@ -375,3 +375,11 @@ Approved Stage 7 and asked to proceed. ## 2026-10-11T13:37:52Z — Assistant — Action summary Recorded the Stage 7 human-lead approval as DEC-021 and updated AMB-009 to partially resolved. Marked the Stage 7 architecture report and candidate design artifacts reviewed as the design baseline while retaining runtime/load and provider/session details as open evidence/design items. Derived `04_generated_documentation/03_requirements/SRS-001_stage8_system_requirements.md` with one unique SRS record per each of the 54 FRs, mandatory `parent_fr` and `parent_uc`, and four cross-cutting NFRs whose `parent_fr: cross-cutting` scopes explicitly enumerate all 54 FRs. Updated the single traceability graph, traceability index, master context, checkpoint index, and created CKPT-013. Validation passed for 54/54 unique FR↔SRS mappings, parent links, NFR scopes, and graph links; `git diff --check` passed. Gate 9.1 was not run because Stage 9 HLD/LLD fan-out is the next stage and the gate follows Stage 9. No product code, runtime, or load tests were run. + +## 2026-10-11T14:10:20Z — User + +Asked to proceed with `/up-hld-lld-generate`. + +## 2026-10-11T14:10:20Z — Assistant — Action summary + +Expanded the approved Stage 7 architecture into a full Stage 9 HLD for all 26 UCs and 54 FRs. Added LLD-007 through LLD-011 for the remaining market observation, master data, fleet/expense, tenant policy, and privacy governance modules; reconciled LLD-001 through LLD-006 with Stage 8 SRS links and Stage 9 shared contracts. Added `api_design.md` with 54 endpoint/component rows, `database_design.md` with entity/constraint and FR ownership matrices, `integration_design.md`, and `stage9_human_review_brief.md`. Logged unresolved tax identifier validation and poison-event retention/replay as AMB-010/011 instead of assuming behavior. Updated the master graph/index, master context, risk-register status, and saved CKPT-014. Final consistency validation confirmed exact coverage of all 54 FRs in LLD Parent FRs, 54 well-formed API mappings, and 54 matching graph links. Ran `python scripts/verify_traceability_gates.py --gate 9.1`: PASS, 0 Critical/Major/Minor. `git diff --check` passed. No product code, runtime, load, or application tests were run. Next process action recorded: review the Stage 9 brief and run `/up-iteration-plan`; preserve iteration-01 as Incomplete / Pending Construction with its existing Gate 14.1 blockers.