المعمارية
نظرة شاملة على طبقات النظام والمسؤوليات.
الطبقات
┌─────────────────────────────────────────────────────────┐
│ 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_admin | 31 (الكل) | /admin |
org_admin | 12 | /admin |
supervisor | 10 | /therapist |
therapist | 9 | /therapist |
spiritual_counsel | 3 | /therapist |
patient | 5 | /patient |
researcher | 3 | /admin/reports |
الـ Patient Journey
8 مراحل مرتبة في state machine على جدول user_journeys:
- welcome — demographics form (age slider, country, dialect)
- path_selection — اختيار 1-4 مسارات من 13
- intake — أسئلة structured (universal + per-path)
- deep_exploration — 5 محاور biopsychosocial + AI follow-ups
- formulation_review — Claude يبني case formulation + user يوافق
- assessment — adaptive cascading من 20 أداة
- track_selection — short_fast / balanced / long_deep
- 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
- WORM audit_logs — PostgreSQL trigger يرفض UPDATE/DELETE
- Encrypted PHI — كل clinical notes + narratives + formulation
- Right to data portability — تصدير ZIP بكل البيانات
- Right to erasure — 30-day grace period + cascade
- 2FA TOTP — Google Authenticator-compatible
- Consent versioning — كل موافقة لها timestamp + version
Subscription Tiers
| Tier | السعر | المرضى | المعالجون |
|---|---|---|---|
| Free | $0 | 5 | 1 |
| Starter | $49/mo | 25 | 2 |
| Professional | $199/mo | 200 | 15 |
| Enterprise | مخصص | ∞ | ∞ |
الاختبار
docker compose exec app ./vendor/bin/pest
# 102 passed (363 assertions)