Files
lab-app/docs/super_admin_architecture.md
T
2026-06-20 18:24:40 +03:00

123 lines
3.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Super Admin Scope
## Neden tenant rolünden ayrı?
- `tenant_members` bir kullanıcının bir veya daha fazla tenant içindeki rolünü taşır.
- `platform_memberships` ise kullanıcının ürün genelindeki yetkisini taşır.
- Böylece aynı kullanıcı:
- birden fazla klinik/lab tenant'ına bağlı olabilir
- aynı anda platformda `super_admin` veya `support` olabilir
- tenant rolü ile platform rolü birbirine karışmaz
## İlk faz modülleri
### 1. Tenant & Plan Yönetimi
- tenant listeleme
- tenant detay
- plan atama/değiştirme
- aktif/pasif durumu
- üye limiti
- workflow/feature override görüntüleme
### 2. Abonelik & AI Kredisi
- tenant subscription durumu
- billing provider bilgileri
- aylık AI kredi tahsisi
- bonus kredi
- manuel kredi düzeltmeleri
- kredi hareket geçmişi
### 3. Kullanım & Operasyon
- AI kullanım logları
- tenant başına maliyet/yoğunluk
- en çok kredi tüketen tenant ve kullanıcılar
- admin müdahale logları
### 4. Platform Erişimi
- super admin atama
- support / finance ops / operations rolleri
- kim hangi işlemi yaptı audit takibi
## Veri modeli
### `platform_memberships`
- `user_id`
- `role`: `super_admin | support | finance_ops | operations | read_only`
- `status`: `active | suspended`
### `tenant_subscriptions`
- `tenant_id`
- `plan`: `starter | pro | enterprise`
- `status`: `trialing | active | past_due | cancelled | paused`
- `billing_provider`
- `provider_customer_id`
- `provider_subscription_id`
- `period_start`
- `period_end`
- `ai_monthly_credits`
- `ai_bonus_credits`
### `ai_credit_ledger`
- `tenant_id`
- `entry_type`: `monthly_allocation | bonus_allocation | usage_debit | manual_adjustment | refund | expire`
- `delta`
- `balance_after`
- `reference_type`
- `reference_id`
- `created_by_user_id`
- `note`
### `ai_usage_logs`
- `tenant_id`
- `user_id`
- `job_id`
- `action`
- `model`
- `credit_cost`
- `token_input`
- `token_output`
- `latency_ms`
### `admin_audit_logs`
- `actor_user_id`
- `actor_role`
- `action_type`
- `target_collection`
- `target_record_id`
- `target_tenant_id`
- `summary`
- `metadata`
## Yetki ilkeleri
- `super_admin`: tüm platform yetkileri
- `finance_ops`: abonelik ve kredi yönetimi
- `operations`: tenant ve operasyonel müdahaleler
- `support`: destek amaçlı görünüm + sınırlı düzeltmeler
- `read_only`: sadece raporlama ve denetim
## Multi-tenant kullanıcı kuralı
- bir kullanıcı `tenant_members` üzerinde birden fazla kayda sahip olabilir
- her kayıt `(tenant_id, user_id)` bazında benzersiz kalır
- aktif tenant seçimi UI durumudur, kimlik modeli değildir
- platform erişimi tenant seçimine bağlı değildir
## Uygulama akışı
1. kullanıcı login olur
2. auth katmanı:
- `tenant_members`
- `platform_memberships`
kayıtlarını ayrı çeker
3. normal uygulama tenant seçimiyle çalışır
4. super admin paneli `platform_memberships` üzerinden açılır
## Sonraki implementasyon adımları
1. super admin route guard
2. dashboard ekranı
3. tenant subscription listesi
4. AI kredi müdahale ekranı
5. audit log görünümü