Production-grade, Shariah-compliant AI client documentation generator built for Warba Bank (100% Islamic, Kuwait).
┌──────────────────────────────────────────────────────────┐
│ React + TypeScript │
│ (Vite, Tailwind, Recharts, React Router) │
│ Login │ Dashboard │ Generate │ Review │ ECL │ Reports │
│ │ Audit Log │ Admin │ Landing Page (public) │
└────────────────────────┬─────────────────────────────────┘
│ REST API (JWT + RBAC)
┌────────────────────────▼─────────────────────────────────┐
│ FastAPI Backend │
│ /auth/token │ /generate-memo │ /approve │ /reject │
│ /finalize │ /ecl/compute │ /audit-log │ /reports │
└────────────────────────┬─────────────────────────────────┘
│
┌────────────────────────▼─────────────────────────────────┐
│ LangGraph Pipeline + Sequential Fallback │
│ │
│ DataAgent → DataValidation → Ratio → ECL → Risk → │
│ Narrative → Compliance → Approval → Compiler │
└────────────────────────┬─────────────────────────────────┘
│
┌────────────────────────▼─────────────────────────────────┐
│ Core Modules │
│ • approval_rules — deterministic auto-approve decisions │
│ • shariah_filter — Islamic terminology validation │
│ • citation_validator — factual claim grounding │
│ • ecl_engine — CBK/IFRS 9 three-stage ECL │
│ • security — JWT + 5-role RBAC │
│ • audit — hash-chain tamper-evident log │
│ • integrations — CRM/CoreBanking/MarketData connectors │
│ • llm_client — 6 providers (no silent mock fallback) │
└──────────────────────────────────────────────────────────┘
# From the project root (MemoForge/)
cp .env.example .env
pip install -r requirements.txt
# Set local demo environment (SQLite + Mock LLM)
export MOCK_MODE=true
export DATABASE_URL=sqlite:///./memoforge.db
# Seed the database with demo clients, memos, and users
python3 -m app.scripts.seed_demo_data
# Start the API server
uvicorn app.main:app --reload --port 8000# In a new terminal, from the project root
cd frontend
npm install
npm run devOpen http://localhost:3000 to access MemoForge.
Use these login credentials to explore all roles. All passwords are for demo purposes only.
| Role | Username | Password |
|---|---|---|
| Relationship Manager (RM) | rm_ahmad |
warba2025 |
| Risk Manager | risk_sara |
warba2025 |
| Credit Committee | cc_khalid |
warba2025 |
| Shariah Board | sb_omar |
warba2025 |
| Admin | admin_system |
warba2025 |
Note: If your
.envfile is missing or you prefer not to copy it, set the environment variables shown above before running the seed script. This is especially important forDATABASE_URL– by default it points to PostgreSQL; for local demo, use the SQLite URL.
All settings via environment variables (see .env.example):
| Variable | Default | Description |
|---|---|---|
MOCK_MODE |
true |
Use mock LLM + connectors. When false, requires real API keys. |
INTEGRATION_MODE |
mock |
mock = synthetic data; real = live bank APIs. |
LLM_PROVIDER |
anthropic |
One of: anthropic, openai, azure, ollama, mock. |
LLM_API_KEY |
(empty) | API key for the chosen provider. |
DATABASE_URL |
postgresql://... |
SQLAlchemy connection string. |
JWT_SECRET_KEY |
(change me) | Secret for JWT signing. |
app/core/config.py— Pydantic settings with env-var overrideapp/core/business_config.py— config.json loader/validatorapp/core/approval_rules.py— Deterministic auto-approve logic (pure functions)app/core/security.py— JWT creation/verification + RBACapp/core/audit.py— SHA-256 hash-chained audit trail
llm_client.py— 6 providers (Anthropic, OpenAI, Azure, Bedrock, Ollama, Mock). RaisesLLMProviderErrorwhenMOCK_MODE=falseand credentials missing.data_agent.py— RAG + integration connectors for client data retrievaldata_validation_agent.py— Data completeness/confidence scoringratio_agent.py— Financial ratio computation (DSCR, leverage, current, etc.)risk_intelligence_agent.py— Risk identification and severity assessmentnarrative_agent.py— Section narrative generation with citation groundingcompliance_agent.py— Shariah + citation compliance checkingapproval_orchestrator.py— Multi-stage workflow state machinecompiler_agent.py— HTML/PDF memo compilationnotification_agent.py— Email/SMS/WhatsApp notificationsreporting_agent.py— Operational report generationescalation_agent.py— SLA-based escalation ladder
base.py— AbstractCRMConnector,CoreBankingConnector,MarketDataConnectormock_crm.py— Realistic Kuwaiti corporate client profilesmock_core_banking.py— Financial statements, facilities, collateralmock_market_data.py— CBK rates, sector benchmarks, FX ratesfactory.py— Returns correct connector based onINTEGRATION_MODE
- Three-stage model: Stage 1 (12-month), Stage 2 (lifetime), Stage 3 (credit-impaired)
- Real Warba Bank parameters: 1% PD floor, 30+ DPD Stage 2 trigger, three-scenario weighting
- Portfolio-level computation with per-facility audit trail
The ECL engine aligns with Warba Bank's dual-prerogative approach: it calculates ECL under IFRS 9 in accordance with CBK guidelines, then takes the higher of IFRS 9 ECL or CBK provisioning rules. On top of this, the engine applies Shariah-specific adjustments:
- EAD — Profit margin stripping: For Murabaha, Ijara, and Tawarruq contracts, the unearned profit portion is subtracted from gross exposure before applying CCF. Musharakah and Sukuk use gross exposure directly (no profit stripping). This reflects the Islamic finance principle that unearned profit is not part of the credit risk exposure.
- LGD — Asset-based recovery: For Ijara and Musharakah facilities with a tangible
asset_recovery_rate, LGD is computed as1 - recovery_rate(blended with CBK collateral haircuts), rather than using conventional LGD floors. This reflects the asset-backed nature of these contracts where the bank retains ownership of the underlying asset. - Stage 2 SICR — Shariah non-compliance: A
shariah_non_compliantflag on a facility triggers an immediate Stage 2 classification (significant increase in credit risk), taking precedence over DPD and rating-downgrade triggers. This captures the additional risk from Shariah non-compliance events. - Gharamah (penalty) exclusion: Penalty amounts are excluded from EAD calculations, consistent with the principle that Gharamah is not recognised as income and is channelled to charity.
- Configuration: Profit margin rates and asset recovery rates by facility type are defined in
config.jsonunder theecl_shariahsection.
- 5 facility types: Murabaha, Ijara, Musharakah, Sukuk, Tawarruq
- Required terms check (e.g., "cost-plus", "profit rate")
- Prohibited terms check (e.g., "interest rate", "conventional loan")
- APR exemption for profit rate disclosure context
| Role | Permissions |
|---|---|
| RM | Generate memos, approve sections, view all |
| Risk | Approve risk sections, view ECL |
| CreditCommittee | Final approve, finalize memos |
| ShariahBoard | Approve Shariah-flagged sections |
| Admin | Full access + user management |
React + TypeScript + Tailwind CSS + Recharts + Vite, redesigned around the Frost Bank Blue design system:
- Palette — deep navy
#0F2A4A, gold#C9A227, light gray#F1F5F9, white - Typography — Playfair Display (headings) + Open Sans (body)
- Layout — Transactional Focus split-view: main content + right sidebar (workflow, charts)
- Components — Toast notifications, shimmer skeletons, badge/badge/table design primitives
- Responsive — desktop and tablet breakpoints throughout
- Landing Page (
/landing, public) — see below - Login — JWT authentication
- Dashboard — see Dashboard Features below
- Generate Memo — 3-step wizard (Configuration → Review & Confirm → Live Pipeline)
- Memo Review — Section cards with citations/flags, role-gated Approve/Reject, Review Status sidebar with SLA countdown, Audit Trail
- ECL Dashboard — Staging distribution bar chart, portfolio composition donut, MemoForge-vs-Warba actuals, facility-level breakdown with rule applied
- Reporting Center — Pipeline status donut, SLA breach risk, avg approval time, performance logs (SLA violations / approval delays) with CSV export
- Audit Log — Searchable, CSV-exportable hash-chained log
- Admin & RBAC — Role configuration, security policy toggles, system audit log, add-user provisioning
- Notification Center — In-app notifications with unread count, mark-as-read, and filter (bell icon in Layout)
The public marketing page at /landing communicates MemoForge to bank stakeholders:
- Hero — "AI-Powered Client Documentation Engine for Islamic Banks" with stat strip (<1 hr generation, 5-stage workflow, 100% Shariah compliance)
- Problem — the 4–8 hour manual memo burden vs. <1 hr with MemoForge
- How It Works — Retrieve → Synthesize → Approve (3-step explainer)
- Features — 6 capability cards (RAG grounding, CBK/IFRS 9 ECL, Shariah compliance engine, approval workflows, audit trail, integrations)
- Comparison Table — MemoForge vs. Traditional manual process vs. Western AI tools (6 criteria)
- Compliance & Security — ISO 27001, Kuwait data residency, zero write-back, RBAC
- CTA — pilot-program request form with toast confirmation
- Footer — product navigation and regulatory badges
The internal Credit Dashboard (post-login home) follows the Transactional Focus split-view:
- KPI cards — Active Memos, Pending Approvals, Portfolio ECL Total, Compliance Flags
- Memo Pipeline table — searchable pipeline with facility type, workflow stage badges, SLA status (On Track / At Risk / Overdue), deal value, and row-level actions (View, Escalate)
- Approval Workflow panel — 5-stage progress tracker for the selected memo with live SLA countdown and assigned-role context
- ECL Breakdown donut — MemoForge ECL vs. Warba audited actuals with variance note
- Compliance Alerts — Shariah flags, citation issues, and policy exceptions with direct review links
- Quick Actions — Approve Section, Escalate, Export Memo Report
cd frontend && npm run build # Production build → dist/python3 -m pytest tests/ -v # 76 tests, all passingNote:
.pytest_cache/is excluded from version control via.gitignore.
MemoForge includes a built-in evaluation and benchmarking framework (app/evaluation/) that measures pipeline quality against a ground-truth corpus.
| Metric | Description |
|---|---|
source_extraction_accuracy |
How faithfully data agents extract source fields |
ratio_accuracy |
Computed financial ratios vs. ground truth |
ecl_accuracy |
ECL figures vs. annotated expected values |
shariah_classification |
Facility type and Shariah term correctness |
citation_correctness |
Citation grounding accuracy |
human_override_frequency |
Rate of human corrections to auto-generated content |
final_memo_quality |
Overall memo quality score |
processing_time |
End-to-end generation latency |
A seeded evaluation corpus lives in data/evaluation/corpus/ with 10 benchmark cases. Each case contains:
client_profile.json— synthetic client datafacility_details.json— facility parametersreference_annotations.json— ground-truth expected values
# Seed the corpus
python3 -m app.scripts.seed_evaluation_corpus --cases 10
# Run evaluation via API
POST /v1/evaluation/runThe evaluation runner (app/evaluation/runner.py) operates in shadow mode — it runs the live pipeline against corpus entries and aggregates deltas against reference annotations without affecting production memos.
docker compose up --build # Full stack on port 8000 (API) + 3000 (UI)- No
TODO,pass, orNotImplementedErrorin main code paths - All 76 tests pass
- Frontend builds without errors (
tsc + vite build) - CBK ECL parameters unchanged (validated)
- No silent mock fallback when
MOCK_MODE=false - PDF generation via WeasyPrint (requires system deps:
libpango,libcairo,libgdk-pixbuf,libffi— included in Dockerfile). Falls back to HTML when WeasyPrint unavailable. - System deployable with real API keys and connectors
- ECL in memo pipeline: The ECL figures in the memo pipeline use synthetic data for demonstration purposes. The ECL engine itself (
app/risk/ecl_engine.py) is validated separately with CBK/IFRS 9 parameters. - Integration connectors: Real CRM/Core Banking/Market Data connectors are currently mock adapters returning realistic synthetic data. Real bank API integrations are planned for production deployment.
- Vector store: The current implementation uses JSON-based TF-IDF embedding storage rather than pgvector. A pgvector-backed store is recommended for production scale.
- Generation time claim: The "<1 hour generation" claim in marketing materials is architectural — no formal benchmark suite is included. Actual generation time depends on LLM provider latency and infrastructure.