Treasury & Bank Transfer Management System — سامانه مدیریت خزانه‌داری و حواله‌های بانکی

docs: define TreasuryFlow phase 1 foundation

davoodmehraban89 committed Oct 5, 2026 at 11:37 UTC 8f5e49034d455beb2d13bd378c1b97d19a61f6b6
1 file changed +73
docs/specs/PHASE_1_FOUNDATION_SPEC.md new
+73
@@ -0,0 +1,73 @@
1 +# TreasuryFlow — Phase 1 Foundation Specification
2 +
3 +## Status
4 +ACTIVE — Phase 1
5 +
6 +## Product mission
7 +TreasuryFlow is a Persian-first treasury and bank-transfer management system for controlled creation, approval, submission, tracking and reconciliation of financial transfers in Iran-aware operating environments.
8 +
9 +## Non-negotiable invariants
10 +1. A maker cannot approve their own payment.
11 +2. An approval is bound to an immutable payment version; changing amount, payer, beneficiary, IBAN or material reference invalidates prior approval.
12 +3. Every logical payment has an idempotency identity. Duplicate submission is prevented at the backend and database boundary.
13 +4. An ambiguous bank outcome is `UNKNOWN`/`NEEDS_REVIEW`; it is never automatically retried.
14 +5. `SUBMITTED`, `ACCEPTED`, `SETTLED`, `FAILED` and `REJECTED` are distinct states.
15 +6. Sensitive actions are server-authorized; hiding UI controls is not authorization.
16 +7. Audit evidence is append-only from the application perspective and records actor, action, entity, time, reason and before/after digests where applicable.
17 +8. Monetary values are stored and calculated in IRR. Toman is presentation-only and must be explicitly labelled.
18 +9. Bank credentials and secrets never live in source control or client-visible configuration.
19 +10. External services are adapters, not architectural dependencies. Production must remain portable to an internal or Iran-accessible deployment environment.
20 +
21 +## Iran rules pack
22 +- IBAN: `IR` plus 24 digits, checksum validation using ISO 13616 mod-97.
23 +- Persian normalization: Arabic/Persian Yeh and Kaf normalization, digit normalization and controlled whitespace normalization before matching/search.
24 +- Time: persisted as an absolute instant; operational display uses `Asia/Tehran`; Persian calendar is a presentation concern.
25 +- Transfer limits, cutoff windows and bank capabilities are effective-dated configuration, not hard-coded constants.
26 +- Unstable connectivity must not convert uncertainty into a resend.
27 +
28 +## Primary actors
29 +- Maker: creates and edits drafts; cannot approve own payment.
30 +- Checker: reviews evidence and approves/rejects within granted authority.
31 +- Treasury Manager: manages operational rules, limits and emergency stop subject to policy.
32 +- System Administrator: manages technical configuration and identity capabilities; administration does not imply financial approval authority.
33 +- Auditor: read/export evidence only.
34 +
35 +## Core domain
36 +- PaymentRequest
37 +- PaymentVersion
38 +- Beneficiary
39 +- BankAccount
40 +- Approval
41 +- BankSubmission
42 +- BankReceipt
43 +- PayaBatch
44 +- ReconciliationItem
45 +- AuditEvent
46 +- IntegrationSource
47 +- LimitProfile
48 +
49 +## Payment lifecycle
50 +`DRAFT -> VALIDATED -> AWAITING_APPROVAL -> APPROVED -> QUEUED -> SUBMITTED -> ACCEPTED/PENDING -> SETTLED`
51 +
52 +Terminal/exception branches include `REJECTED`, `FAILED`, `CANCELLED` (only where legally/technically supported), `UNKNOWN`, and `NEEDS_REVIEW`.
53 +
54 +No transition out of `UNKNOWN` may create a new submission without an explicit reviewed decision and idempotency-safe reconciliation of the previous attempt.
55 +
56 +## Phase 1 deliverables
57 +- Repository operating rules and five-phase roadmap.
58 +- Architecture decision records for stack, data authority, adapters and deployment portability.
59 +- Domain/state/security specifications.
60 +- UI information architecture and design tokens suitable for direct coded UI.
61 +- Engineering baseline with strict TypeScript, linting, tests and CI.
62 +- Initial deployable shell for staging; no live-bank credentials or production money movement.
63 +- Threat model and acceptance gate.
64 +
65 +## Phase 1 acceptance gate
66 +Phase 1 is complete only when:
67 +- architecture and domain contracts are versioned in the repository;
68 +- the application shell builds and tests successfully in CI;
69 +- critical invariants have executable tests;
70 +- the first RTL application shell can be deployed to staging;
71 +- no live banking action exists;
72 +- security/threat-model review has no unresolved critical issue;
73 +- the repository contains an explicit handoff/state document for Phase 2.