This page mirrors the real ARCHITECTURE.md from the repository root — kept in sync automatically by .github/workflows/docs-sync.yml on every push that changes it, not a hand-maintained copy (see that workflow and scripts/sync_docs.py for exactly why a GitHub Action does this instead of a plain Jekyll tag — Jekyll's own include/include_relative tags refuse any path containing .., so neither can reach a file one directory above docs/ directly). Prefer reading the real file itself? It's directly on GitHub.

GARBATI Core Banking: Platform Architecture

Status: Draft v0. Proposed boundaries, not final. Each “Proposed” item needs your confirmation or change before it goes in the decisions log (Section 8).

This document is the map. It says which service owns which kind of truth and who may call whom. Each service keeps its own docs/DESIGN.md for the detail; this file never repeats it.


1. Purpose and principles

GARBATI is an open-source core banking platform for Sharia-compliant microfinance institutions, built in tranches (one service at a time, each designed before it is coded).

  1. One kind of truth, one owner. Every fact has exactly one service that is allowed to say what is true. Other services ask; they never keep their own copy.
  2. Money truth lives only in LedgerApi. No other service stores balances or posts entries.
  3. Fail closed. If a service cannot establish a positive answer, the operation stops.
  4. Decisions and effects are separate. A service that decides (is this allowed? what fee applies?) does not do (move money). Money moves only through LedgerApi, called by the orchestrator.
  5. Design before code. Every service starts as a questions-only skeleton, then adversarial review, then a decisions log.

2. Service map (Proposed)

Service Owns (source of truth) Does NOT own Status
LedgerApi Accounts, entries, balances, idempotency, ledger audit Customers, products, fees, limits Built, deployed
IdentityApi (Garbati.IdentityApi) Customer identity, KYC status and tier, mandates (who may operate which account, including joint accounts with configurable multi-holder approval), suspension, reversal authorization Product rules, fees, tax, standing orders, transaction flow v1 fully built across 4 PRs: Customer, KYC, Mandates, single-holder and joint-account (M-of-N) grant issuance, and reversal authorization all merged. Reversal is callable only by a trusted “ops channel” that doesn’t exist yet (same “no consumer yet” pattern as the account-freeze outbox). Key rotation/compromise tooling beyond the basic Production guard not yet built. docs/DESIGN.md
ProductApi (Product & Pricing) Product catalog, account-to-product binding, product rules (minimum balance, allowed operations), fee and tax rules, limit definitions. Sharia product rules live here Executing anything; storing money; customer identity v1 (minimal) foundation built and merged (T-045, 24 Oct 2026): Product/ProductLimitPolicy/AccountProductBinding real and working (limits still placeholder values pending compliance confirmation, same as KycTierPolicy); FeeRule/ProfitSharingTerms exist as real tables but are deliberately unseeded, pending a qualified scholar’s sign-off (research/sharia-product-rules.md) — a fee quote always returns an explicit NoFeeConfigured today. QA-approved, no blockers. Now wired to OrchestratorApi for account opening (T-046, 25 Oct 2026) — step 5 of Section 10’s sequence. Deployed to Azure (T-048, 27 Oct 2026), live and smoke-tested; the transfer-time fee-quote call remains deliberately unwired (no real FeeRule content to ask for yet). docs/DESIGN.md
OrchestratorApi (Transaction Orchestrator) The ordered steps of each customer operation; decision binding (decisionId); in-flight operation state; account-opening flow Any truth of its own about customers, products or balances v1 (minimal) built and merged: account opening (4-step sequence, resumable) and a plain transfer (authorization-then-post), calling the real IdentityApi/LedgerApi contracts. No fee, no reversal, no real Channel auth (known gap, Section 1.6) — matches the deliberately minimal design. docs/DESIGN.md
ScheduleApi (Standing Orders) Recurring instructions and their run history Moving money (it submits requests to the orchestrator like any channel) Built, tested, merged (T-071, 10 Nov 2026); not yet deployed to Azure. docs/DESIGN.md
Financing services (Murabaha, etc.) Financing contracts and schedules Ledger postings Later tranche
Channel/Gateway Customer login, sessions, API for apps Everything above Later tranche
StaffIdentityApi Staff accounts, roles (Teller/CustomerServiceOfficer/Supervisor/ComplianceOfficer/RiskOfficer/Auditor/Administrator), who is logging in as a bank employee and what they’re permitted to do Customer identity/KYC/mandates (that’s IdentityApi’s job — staff and customers are deliberately separate identity domains, D-13); any money/customer truth v1 foundation built and merged (T-032): entities, all 8 endpoints, the one-time Administrator seed. Deployed to Azure (T-048, 27 Oct 2026) — garbati-staffidentityapi, live and smoke-tested. docs/DESIGN.md
OpsApi (ops console backend-for-frontend) The staff-facing login session (cookie-based); holds the real service API keys for IdentityApi/OrchestratorApi/LedgerApi/StaffIdentityApi server-side, never exposed to the browser; proxies/aggregates calls for the ops console UI Any truth of its own — same “orchestrates, doesn’t own” role OrchestratorApi plays for customer-facing flows, but for staff-facing ones v1 fully built (T-033 foundation + T-034 workflows): sessions, cascade revocation, all 4 downstream clients, every endpoint group including both maker-checker workflows — both OpsReversalRequest and (since T-047, 26 Oct 2026) OpsCustomerEditRequest are now fully executable end to end, mirroring the same try/catch → outcome pattern. Deployed to Azure (T-048, 27 Oct 2026) — garbati-opsapi, live and smoke-tested, with real production API keys issued by StaffIdentityApi/IdentityApi/LedgerApi/OrchestratorApi (not dev placeholders). docs/DESIGN.md
Ops console (React + TypeScript frontend) Nothing — a pure client of OpsApi Everything; never talks to IdentityApi/OrchestratorApi/LedgerApi/StaffIdentityApi directly, never holds a real service credential Design v1 ratified (T-029); not yet built, depends on OpsApi being built first. docs/DESIGN.md

3. Dependency rules

Channels / ScheduleApi
        |
        v
  OrchestratorApi  ----> IdentityApi   (who may do this?)
        |          ----> ProductApi    (what rules, fees, tax, limits apply?)
        v
    LedgerApi      (only the orchestrator posts money)

3.1 Ops console (staff-facing, separate from the customer path above, D-13):

Ops console (browser)
        |
        v
      OpsApi  ----> StaffIdentityApi   (who is this staff member, what role?)
        |     ----> IdentityApi        (customer/KYC/mandate lookups and actions)
        |     ----> OrchestratorApi    (account opening, transfers, reversals)
        |     ----> LedgerApi          (balance/transaction lookups)

4. End-to-end flows

4.1 Customer transfer. Channel authenticates the customer, then calls the orchestrator. The orchestrator asks IdentityApi for an authorization decision, asks ProductApi for rules, fees, tax and limits, and builds the full set of postings (the transfer, the fee, the tax). It posts them to LedgerApi with the decisionId bound to the exact request. The fee and tax are ordinary legs of the same chain (P-14), paid to system income and tax accounts. A transaction with no fee or tax is a chain of one leg.

4.2 Account opening. Orchestrator runs: create customer (Identity), wait for KYC, choose product (Product), create ledger account (Ledger), attach mandate (Identity), bind product (Product). If a later step fails, earlier steps are retried or reversed explicitly; no half-opened account stays silently valid.

4.3 Standing order. ScheduleApi fires on schedule and submits an ordinary request to the orchestrator, with idempotency key derived from the standing order id and the run date. A repeated trigger therefore cannot pay twice.

4.4 Fee. ProductApi computes the amount. The orchestrator posts it. ProductApi never touches the ledger.

5. Shared conventions (every service follows these)

6. Repository layout

One repository per service, each with README.md and docs/DESIGN.md. This repo (or a garbati-platform repo) holds only this file, the service map, and cross-service contracts.

garbati-platform/        ARCHITECTURE.md, contracts/, ADRs
LedgerApi/               docs/DESIGN.md   (exists)
Garbati.IdentityApi/     docs/DESIGN.md   (exists)
Garbati.OrchestratorApi/ docs/DESIGN.md   (exists)
Garbati.StaffIdentityApi/docs/DESIGN.md   (exists)
Garbati.OpsApi/          docs/DESIGN.md   (exists)
Garbati.ProductApi/      docs/DESIGN.md   (exists — design only, not yet built)
garbati-ops-console/     docs/DESIGN.md   (exists — design only, not yet built)

7. Build order — updated to reflect what’s actually happened, 24 Oct 2026 (originally “Proposed”)

  1. LedgerApi — built, deployed, live on Azure.
  2. IdentityApi — built across 4 PRs (customer/KYC, mandates, joint-approval, reversal authorization), deployed, live on Azure. BVN/NIN storage and real KYC-tier evidence enforcement added since (T-044, D-26).
  3. OrchestratorApi — v1 (minimal) built: account opening, plain transfer, reversal. Deployed, live on Azure. Fee integration still waiting on ProductApi, per its own original minimal scope.
  4. StaffIdentityApi and OpsApi (the ops-console initiative, D-13, independent of 1-3) — both fully built, tested, and deployed, live on Azure (T-048, 27 Oct 2026). The ops console frontend itself (garbati-ops-console, T-062, 2 Nov 2026) is now built and merged too — login, role-gated nav, all 8 v1 screens, verified by real HTTP calls against a live backend. Not yet deployed to Azure (that wiring, into OpsApi’s existing Web App per the frontend’s own design doc Section 7, is a separate step) — the whole D-13 initiative’s code is otherwise complete.
  5. ProductApi — v1 (minimal) foundation built and merged (T-009 design, T-045 build, 24 Oct 2026): the real, mechanical parts (catalog, account-binding, limits) are built and QA-approved. Fee/profit-sharing content remains deliberately unseeded, pending a qualified scholar’s sign-off (research/sharia-product-rules.md) — not blocked entirely on that sign-off, but not inventing rules in its absence either. Deployed to Azure (T-048, 27 Oct 2026) — garbati-productapi, live and smoke-tested; OrchestratorApi’s BindProduct step (T-046) now calls it with a real production key, not a dev placeholder.
  6. ScheduleApi — built and merged (T-071, 10 Nov 2026), targeting full Fineract-equivalent standing-instruction functionality (StandingInstruction/StandingInstructionRun, all 7 endpoints, a plain-BackgroundService scheduler, both downstream clients). Not yet deployed to Azure — real infrastructure provisioning is a separate task, same precedent as T-048 for every other service. Financing services, Channel/Gateway remain “later tranche,” none designed yet, in that order of likely priority (matching D-1’s original “channel doesn’t exist yet” framing).

Deployment guidance: design these as separate services, but you do not need separate deployments on day one. Each deployed service costs money and needs its own database, pipeline and monitoring. Start with Ledger and Identity deployed separately (their data sensitivity justifies it). Start Product and Orchestrator as separate projects inside one deployable, with the same boundaries enforced in code, and split them later if there is a reason.

8. Platform decisions log

# Decision Options considered Proposed choice Why Status
P-1 Transaction flow owner Channels call each service / Ledger calls Identity / separate orchestrator Separate OrchestratorApi One place enforces step order; the ledger stays independent; fixes the “nothing forces the gate” gap in Identity review Decided (owner, D-2, 16 Oct 2026; matches the orchestration-based Saga pattern — research/architecture-patterns-p1-p6.md)
P-2 Where product rules, fees, tax live Inside IdentityApi / inside Orchestrator / separate ProductApi Separate ProductApi Identity answers “who”, product answers “what rules”; they change for different reasons and on different schedules Decided (owner, D-2, 16 Oct 2026; matches decide/execute separation seen in core-banking product-engine-vs-ledger splits — research/architecture-patterns-p1-p6.md)
P-3 Standing orders Inside Identity / inside Orchestrator / separate ScheduleApi Separate ScheduleApi that calls the orchestrator Scheduling needs its own run history and retry logic; money still moves only through the orchestrator Decided (owner, D-2, 16 Oct 2026; matches the Scheduler/Agent/Supervisor pattern — research/architecture-patterns-p1-p6.md). Retry-on-failure resolved, D-33, 10 Nov 2026: no auto-retry — see Section 9. Design v1 ratified, Garbati.ScheduleApi/docs/DESIGN.md
P-4 Who computes vs who posts Product posts fees / orchestrator posts Product computes, orchestrator posts Keeps “money moves only via the ledger” absolute Decided (owner, D-2, 16 Oct 2026; same decide/execute split as P-2, applied per step — research/architecture-patterns-p1-p6.md)
P-5 Cross-service data Shared DB / copies / API calls only API calls only, no shared DB, no cross-service FK Services stay independently changeable Decided (owner, D-2, 16 Oct 2026; matches the standard database-per-service pattern — research/architecture-patterns-p1-p6.md)
P-6 Deployment shape One service per deployment / modular monolith for new services Separate design, minimal deployables initially Solo developer and budget Decided (owner, D-2, 16 Oct 2026; matches Fowler’s “Monolith First” / modular-monolith guidance — research/architecture-patterns-p1-p6.md; later split not guaranteed easy, depends on keeping P-5’s no-shared-database discipline intact in practice)
P-7 Where account numbers are created Move creation into IdentityApi / keep in LedgerApi Keep in LedgerApi; the orchestrator runs the account-opening sequence (Section 10) Only the ledger can guarantee its own account-number uniqueness; Identity would need ledger write access, so a breach of Identity could open accounts Decided
P-8 Aggregate limits In orchestrator / in ledger / separate limits service Orchestrator, using reserve, then confirm or release, with one atomic counter update Orchestrator is the single gate every operation passes; Product owns the limit definitions Decided (owner), mechanism proposed
P-9 Fee and tax timing Separate linked transactions / same ledger transaction Same all-or-nothing unit as the transfer, built as a chain of legs committed in one database transaction (P-14); if the fee leg fails, the whole chain fails and is retried No state where the transfer succeeded but the fee did not Decided (owner); shape Decided (owner), option B
P-10 Reversal of fees and tax Reverse principal only / reverse everything Reversing a chain reverses every leg, last leg first, in one database transaction. A single leg of a chain cannot be reversed on its own Nobody can refund the principal and keep the fee Decided (owner)
P-11 Product changes Edit in place / versioned Immutable published versions; each account binds to a version; every fee records the version used; moving accounts to a new version is an explicit audited step A past fee can always be explained Decided (owner)
P-12 Decision binding Shared signing key / Identity signs, ledger verifies a public key / ledger confirms online with Identity IdentityApi signs a decision token with a private key. The orchestrator verifies it, then the ledger verifies it again locally with the public key. Expiry 30 seconds, single use No call from the ledger to Identity, so no added latency and no new dependency. The orchestrator cannot forge a decision. IdentityApi stays the source of truth for authorization, LedgerApi for financial transactions Decided (owner); stale-window cost in Section 9
P-13 Create-account idempotency None / client key with request hash Idempotency key plus request hash on POST /api/accounts A retried account-opening step must not create a second account Decided (owner, D-2, 16 Oct 2026) — built, LedgerApi decision #43 (merged PR #24, 14 Oct 2026)
P-14 Shape of multi-part transactions One transaction with many entries (A) / chain of ordinary two-entry legs committed together (B) B: a chain of legs. Each leg is a normal two-entry transaction (principal, fee, tax). All legs commit in one database transaction or none do. A transaction with no fee or tax is a chain of one leg Keeps the tested guarantee of one debit and one credit per transaction, keeps POST /api/transfers unchanged, and lets reversal reuse the existing single-leg logic. Statements show one line per leg Decided (owner); details in Section 12
P-15 Staff/ops identity vs. customer identity Bounded context inside IdentityApi / new dedicated StaffIdentityApi New dedicated service (StaffIdentityApi), built the low-cost way (P-6) — separate project/database, not necessarily a separate deployment day one Workforce identity (staff, provisioned by an admin, least-privilege/audit) and customer identity (CIAM, self-registered, KYC-gated) are treated as distinct domains almost everywhere real core-banking platforms were checked; merging staff credentials into IdentityApi’s database would share blast radius with regulated customer PII Decided (owner, D-13, 19 Oct 2026, after T-026 research — research/staff-ops-identity-patterns.md)

9. Open questions

10. Account opening sequence (orchestrator-run)

All 5 steps now built and merged (T-046, 25 Oct 2026) — step 5 (“bind product version”) was the one gap in this sequence from the day this table was first written, waiting on ProductApi to exist. The ProductCode it binds to is a hardcoded {JurisdictionCode}-{SAV|CUR}-STD placeholder mapping (same “demo stub” honesty as the account-opening flow’s existing DemoKycTier stub, not a real product- selection design) — an AccountType/JurisdictionCode with no matching seeded product fails this step cleanly (Status = Failed, a plain reason), which is the correct failure mode today, not a bug.

Step Service If it fails
1. Create customer (pending) IdentityApi Nothing else exists; retry
2. KYC verified IdentityApi Stop; customer stays pending
3. Create ledger account (idempotency key) LedgerApi Retry with the same key; never creates a second account
4. Attach mandate IdentityApi Account exists but cannot be used (no mandate); retry
5. Bind product version ProductApi Same; retry
6. Mark opening complete Orchestrator The operation record shows the current step

11. Required LedgerApi amendments

  1. Request hash and per-client idempotency (from the external review): Done, LedgerApi decisions #42 and #44 (merged 6 and 15 October 2026).
  2. Idempotency on POST /api/accounts (P-13): Done, LedgerApi decision #43 (merged 14 October 2026). Keys are 1-128 characters of letters, digits, -, _, ., : (decision #44).
  3. Chains of legs (P-9, P-10, P-14): a new chain endpoint posts an ordered list of legs in one database transaction. Every leg is still an ordinary two-entry transaction, so the “exactly one debit and one credit” rule is not amended. TransferService is split into a core that posts one leg inside a database transaction owned by the caller, and the existing wrapper. ReversalService keeps its single-leg logic and gains a chain reversal that loops over the legs. Done, LedgerApi decision #45 (built on feat/ledger-chains, merged as LedgerApi PR #26 on 15 Oct 2026 and PR #27 on 15 Oct 2026, ahead of this task board’s QA step; independently QA-reviewed and approved 16 Oct 2026, qa/reports/T-001.md; owner-ratified 16 Oct 2026). Detail in Section 12.
  4. Fee-income and tax-payable system accounts per currency, seeded like the funding accounts (decision #25). Done, LedgerApi decision #46 (merged as LedgerApi PR #28, 16 Oct 2026; QA-approved, qa/reports/PR-28.md). The accounts exist and are configured (FeeIncome:Accounts, TaxPayable:Accounts), but nothing routes a Fee/Tax leg to them yet — decision #45’s chain validation still only checks AccountClass == System. Wiring a specific fee-income/tax-payable account into a transaction is future ProductApi/OrchestratorApi work.
  5. Token verification (P-12): the ledger verifies an IdentityApi-signed decision token locally before posting a customer-originated transaction, and stores the decisionId under a unique constraint. This amends decision #34 narrowly: the ledger still calls nobody and stores nothing about identity. Proposed as decision #47.

12. Chain model for LedgerApi (draft of decision #45)

12.1 What it is, in plain words

A chain is a list of legs that the ledger posts together. Each leg is a normal LedgerApi transaction: one debit entry, one credit entry. The chain is the envelope that says “these legs belong together, and they either all happen or none do.”

Transaction Legs
Transfer, no fee 1: Principal
Transfer with a fee 2: Principal, Fee
Transfer with a fee and tax on the fee 3: Principal, Fee, Tax

The ledger does not work out fees or tax and does not know which products have them. ProductApi computes, the orchestrator builds the list of legs, and the ledger posts exactly the list it is given (P-4).

12.2 Why all-or-nothing still holds

Each leg is posted inside one database transaction that the chain owns. If any leg fails, the database throws away every leg, exactly as it throws away the two entries of today’s single transfer. Atomicity comes from the one database transaction, not from there being one transaction row. Legs are never committed one at a time.

12.3 Data shape

12.4 Rules the ledger enforces on every chain

  1. At least one leg, at most 10.
  2. Sequences are 1..N with no gaps. Leg 1 is the only Principal leg.
  3. Every leg amount is greater than zero. A zero fee means no fee leg, and no fee means no tax leg. The caller never sends a zero leg.
  4. Every leg uses the same currency, and each amount respects that currency’s decimal places (the existing rule).
  5. Fee and Tax legs must credit a System account (fee-income or tax-payable). The ledger checks the account class, not the amount.
  6. One balance check per paying account, up front. For each customer account that pays any leg, the total of everything it pays across the chain (principal plus fee plus tax) must not exceed its balance. This gives one clear error (“Insufficient balance”) instead of a principal that passes and a fee that fails. System accounts keep the existing overdraft floor.
  7. The existing status rules apply per leg (source must be Active, destination must not be Blocked).

12.5 Locking

Before posting anything, the ledger locks every account that is debited by any leg with SELECT ... FOR UPDATE, in one fixed order (ascending account number), once for the whole chain. The fixed order stops two chains that touch the same accounts from waiting on each other forever (deadlock). Credited accounts are not locked, as today.

12.6 Failure and retry

12.7 Request hash

SHA-256 of the JSON of the ordered legs: for each leg, debit account, credit account, amount (normalised with G29) and purpose. Narration is excluded, as in decision #44.

12.8 Reversal

12.9 Audit

In the same database transaction as the postings: one audit row per leg (so existing audit queries keep working) and one audit row for the chain as a whole.

12.10 Token (P-12)

The token binds the principal leg and the idempotency key (debit account, principal amount, currency, hash of the exact customer request). The ledger stores decision_id on the chain under a unique constraint. Fee and tax legs are added by the orchestrator from ProductApi’s rules and are not covered by the token; the reconciliation job in Section 9 checks them.

12.11 Code changes (outline)

  1. Split TransferService: PostLegAsync runs the checks and writes one leg inside a database transaction supplied by the caller. A rejected leg throws a business exception; it does not commit. The existing TransferAsync becomes a thin wrapper that opens the database transaction, calls PostLegAsync once and keeps today’s behaviour and responses.
  2. New ChainService that validates rules 1 to 6, locks accounts (12.5), calls PostLegAsync for each leg in order, and handles 12.6.
  3. ReversalService: extract the single-leg reversal into a method that runs inside the caller’s database transaction; add ReverseChainAsync; make the old endpoint refuse chain legs.
  4. One EF migration for the new table and three columns, with a migration test like the earlier ones.
  5. Responses for existing transaction reads gain optional chainReference, sequence and purpose.

12.12 Tests to write first