المعمارية

نظرة شاملة على طبقات النظام والمسؤوليات.

الطبقات

┌─────────────────────────────────────────────────────────┐
│  Presentation (Blade views + future Flutter mobile app)  │
├─────────────────────────────────────────────────────────┤
│  Controllers (32 endpoints across 7 portals)             │
├─────────────────────────────────────────────────────────┤
│  Services (18 services — domain logic)                   │
│    AI · Crisis · Assessment · Exploration                │
│    Treatment · Outcome · Billing · Compliance · Journey  │
├─────────────────────────────────────────────────────────┤
│  Integrations (8 contracts + mock/production adapters)   │
├─────────────────────────────────────────────────────────┤
│  Models + Migrations (19 models, 30+ migrations)         │
├─────────────────────────────────────────────────────────┤
│  PostgreSQL + pgvector  |  Anthropic Claude  |  OpenAI  │
└─────────────────────────────────────────────────────────┘

Multi-Tenancy

كل entity له organization_id. مستخدم يمكن أن ينتمي لعدة مؤسسات بأدوار مختلفة.

// Pivot: organization_user
role_in_org: patient | therapist | supervisor | org_admin | spiritual_counsel
is_primary: boolean

الأدوار + الصلاحيات

7 أدوار مع 31 صلاحية موزّعة عبر Spatie Permission.

الدورالصلاحياتالبوابة
super_admin31 (الكل)/admin
org_admin12/admin
supervisor10/therapist
therapist9/therapist
spiritual_counsel3/therapist
patient5/patient
researcher3/admin/reports

الـ Patient Journey

8 مراحل مرتبة في state machine على جدول user_journeys:

  1. welcome — demographics form (age slider, country, dialect)
  2. path_selection — اختيار 1-4 مسارات من 13
  3. intake — أسئلة structured (universal + per-path)
  4. deep_exploration — 5 محاور biopsychosocial + AI follow-ups
  5. formulation_review — Claude يبني case formulation + user يوافق
  6. assessment — adaptive cascading من 20 أداة
  7. track_selection — short_fast / balanced / long_deep
  8. treatment — 12+ جلسات بـ 6 خطوات لكل واحدة

AI Pipeline

User message
   ↓
CrisisDetectionService (5-level severity check)
   ↓ (لو آمن)
ProtocolModeSelector (يحدد modes نشطة)
   ↓
SystemPromptLoader (يبني stack: base + mode + TIIP)
   ↓
EnhancedRagRetriever (pgvector cosine + tag boost)
   ↓
Claude Sonnet 4.6 (مع prompt caching)
   ↓
Post-flight crisis scan على الـ output
   ↓
AiInteraction.save() (encrypted)

Compliance Layers

Subscription Tiers

Tierالسعرالمرضىالمعالجون
Free$051
Starter$49/mo252
Professional$199/mo20015
Enterpriseمخصص

الاختبار

docker compose exec app ./vendor/bin/pest
# 102 passed (363 assertions)