Full request lifecycle — from user input to database write.
🏥 Telemedicine Flow Diagram
📊 Data + Provider Economy Diagrams
Request Data Flow
Provider Economy Flow
🔄 Flow State Diagram
🛡️ Governance Model
How Sudanna ensures determinism, safety, and institutional trust.
⚙️ Decision Architecture
All critical decisions pass through:
• IE Engine — 554 deterministic rules
• PDE Engine — policy-driven routing
AI is advisory only in non-critical contexts.
🏥 Medical Domain Rules
• HARD GATE enforced — no AI responses
• StepController takes full control
• Emergency: 999 immediately, no booking
• createMedicalCase() mandatory after triage
📋 System Guarantees
• Determinism: same input = same path
• Traceability: request_id + flow_id + step_id logged
• Safety: 7-layer OutputBuilder for medical
• Auditability: full audit_logs table
// Governance enforcement (Gateway.php)
if ($decision['type'] === 'REAL' && medical) {
// HARD GATE — no bypass possible
$flow = StepController::start('medical_telemedicine_v1');
if (!$flow) return $medical_safe_deterministic_response;
// ↑ Even on failure: no AI, no diagnosis
}
كل دفعة مؤكدة تُنشئ تلقائياً سجلاً في payment_receipts برقم تسلسلي RCP-YYYYMMDD-NNNNNN.
الإيصال مرتبط بالفاتورة و4 القيود المحاسبية. لا يمكن إنشاء إيصالَين لنفس الفاتورة (UNIQUE invoice_id).
2. البريد الإلكتروني
عند تأكيد الدفع، يُرسَل بريد تلقائي من finance@sudanna.ai يحتوي:
رقم الإيصال، المبلغ، الرمز المرجعي، وقت الدفع، رابط الإيصال الرقمي.
3. أمان الـ Webhook
لا يوجد bypass أو test mode في الإنتاج. التحقق من التوقيع HMAC-SHA256 إلزامي.
الـ WEBHOOK_SECRET يُولَّد من JWT_SECRET عند الإعداد.
Daily at 2:30 AM (cron)
│
ReconciliationEngine::run(date)
├── System: SELECT paid invoices WHERE DATE=?
├── Ledger: SUM(debit), SUM(credit) WHERE DATE=?
└── Bank: BankAdapter::getStatement(from, to)
│
┌─────┴─────┐
PASS FAIL
│ │
├── Log ├── Alert Admin (notification)
│ ├── BLOCK all payouts for date
│ └── Log audit_logs (immutable)
│
Settlement ALLOWED (3:00 AM)
└── SettlementEngine::processDate(date)
├── ReconciliationEngine::isPassed(date) → GATE
├── provider_earnings WHERE status=pending
├── BankAdapter::initiatePayout()
└── Ledger: DEBIT Provider(2002) CREDIT Cash(1001)
5. Accounting — Double-Entry Ledger
Payment Received (1000 SDG):
DEBIT Cash(1001) 1000 ← money enters
CREDIT UserLiability(2001) 1000 ← owed to user
DEBIT UserLiability(2001) 1000 ← settling
CREDIT UserWallet(1002) 1000 ← wallet funded
─────────────────────────────────
SUM(debit) = 2000 = SUM(credit) ✅
Settlement Payout (900 SDG to provider):
DEBIT ProviderLiability(2002) 900 ← paying out
CREDIT Cash(1001) 900 ← money leaves
─────────────────────────────────
BALANCED ✅ — Sudanna never holds
6. Revenue Streams — All Through Ledger
Stream Rate Ledger Account Trigger
────────────────────────────────────────────────────
Service Commission 10% Revenue(4001) booking.completed
Payment Fee 0.5% Revenue(4001) payment.confirmed
Subscription Fixed Revenue(4002) subscription.paid
API Usage /call Revenue(4002) api_engine.used
Provider Listing Fixed Revenue(4001) listing_boost
ALL revenue:
✔ goes through ledger
✔ linked to invoice_id
✔ reconciled with bank
✔ auditable (trace_id)
7. Production API Endpoints
Endpoint
Method
SLA
Auth
Purpose
/api/decision/check
POST
<100ms
Session
AI decision gate
/api/cashflow/summary
GET
<200ms
Session
Spending analysis
/api/limits/check
POST
<50ms
Session
Limit validation
/api/fraud/check
POST
<100ms
Session
Fraud detection
/api/payment/webhook
POST
<2s
HMAC
Gateway webhook
/api/payment/status
GET
<200ms
Public
Payment status
/api/reconcile/run
POST
<5min
Admin
Trigger reconcile
/api/payout/process
POST
<30s
Admin
Trigger settlement
8. System Principles + SLA
Principle Definition
──────────────────────────────────────────────────────
NO_CUSTODY Sudanna never holds money (shadow ledger only)
DEBIT_ONLY No credit/loans ever extended
BANK_SOURCE Bank statement wins on any mismatch
IDEMPOTENT Every operation safe to retry
EVENT_DRIVEN All state changes via EventBus
AI_CONTROLLED AI gates every payment decision
AUDITABLE trace_id on every action, immutable logs
SLA
──────────────────────────────────────────────────────
Decision check < 100ms
Webhook confirm < 2s
Full payment < 5s
Email dispatch < 10s
Reconciliation < 5min (daily)
Settlement after reconciliation PASS