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

docs: record application foundation decision

davoodmehraban89 committed Oct 5, 2026 at 11:38 UTC 4672db1f8f58cfa5a925b069ab9065dfa5d63de1
1 file changed +33
docs/adr/0001-application-foundation.md new
+33
@@ -0,0 +1,33 @@
1 +# ADR-0001 — Application Foundation
2 +
3 +- Status: Accepted for Phase 1
4 +- Date: 2026-10-05
5 +
6 +## Decision
7 +Use a TypeScript-first modular monolith for the initial TreasuryFlow product, with Next.js 16 App Router for the web/application boundary and PostgreSQL as the transactional system of record. Keep financial domain rules in server-only modules independent of UI components. External banks, accounting sources, messaging and other providers are accessed only through typed adapter interfaces.
8 +
9 +## Rationale
10 +TreasuryFlow needs strong transactional consistency, explicit authorization and auditable domain behavior more than it needs early microservice distribution. A modular monolith minimizes distributed failure modes while preserving clear boundaries that can be extracted later if scale or regulation requires it.
11 +
12 +Current Next.js 16 security guidance requires authorization to be re-verified in Server Actions/Route Handlers and recommends server-only data-access boundaries. TreasuryFlow adopts that rule as a minimum; UI visibility never grants authority.
13 +
14 +## Initial technical baseline
15 +- Next.js 16 App Router
16 +- TypeScript strict mode
17 +- PostgreSQL
18 +- Schema/migration layer selected during the executable scaffold task; it must support versioned migrations, transactions and constraints.
19 +- Vitest for fast domain/unit tests unless scaffold verification identifies an incompatibility.
20 +- Playwright for critical E2E flows once the shell exists.
21 +- Container-ready deployment; Railway is staging-first, not a production lock-in.
22 +
23 +## Boundaries
24 +- `domain`: financial invariants and state transitions; no framework imports.
25 +- `application`: use cases, authorization orchestration and transaction boundaries.
26 +- `infrastructure`: persistence, queues, bank/accounting adapters and telemetry.
27 +- `web`: RTL Persian-first presentation and HTTP/Server Action boundaries.
28 +
29 +## Security consequences
30 +Every mutation is treated as an independent entry point and must authenticate, authorize and validate the target resource on the server. Maker-checker and payment-state rules live below the UI boundary.
31 +
32 +## Deferred
33 +Authentication provider, ORM/query builder, queue implementation and final production hosting are deliberately not locked until the Phase 1 scaffold spike proves compatibility and portability.