> ## Documentation Index
> Fetch the complete documentation index at: https://docs.diyanet.pro/llms.txt
> Use this file to discover all available pages before exploring further.

# Altyapı Servisleri — Genel Bakış

> Email, SMS, Notification, OAuth, Authenticator ve Hangfire altyapı servislerinin ortak kayıt deseni, config konvansiyonu ve resilience yaklaşımı.

Altyapı servisleri, Application katmanının ihtiyaç duyduğu dış dünya entegrasyonlarını (e-posta, SMS, OAuth sağlayıcıları, TOTP üreteci, arka plan iş kuyruğu, gerçek-zamanlı bildirim) sağlayan ayrı projelerdir. Her biri `src/DiyanetCleanArchitecture.Infrastructure.Services.*` ya da `src/DiyanetCleanArchitecture.Infrastructure.Jobs.*` altında yaşar.

## Ortak desen

Tüm servisler aynı üç kuralı izler:

<Steps>
  <Step title="Application arayüzünü implemente eder">
    Servis sınıfı, Application/Domain katmanının tanımladığı (ya da kendi projesindeki) bir arayüzü implemente eder: `IEmailService`, `IOtpSmsService`, `IAuthenticationTotpService`, `IOAuthClient<TUserInfo>`, `IAdminNotificationBroadcaster`. Tüketici kod somut sınıfı değil arayüzü inject eder.
  </Step>

  <Step title="Bir Add*Service extension'ı ile kaydedilir">
    Her projenin kök `DependencyInjection.cs` dosyasında `Add*` adında bir `IServiceCollection` extension metodu vardır. `Program.cs` bunları sırayla çağırır:

    ```csharp theme={null}
    builder.Services.AddHangfireServers(builder.Configuration);
    builder.Services.AddSmsService(builder.Configuration);
    builder.Services.AddEmailService(builder.Configuration);
    builder.Services.AddAuthenticatorService(builder.Configuration);
    builder.Services.AddOAuthProviders(builder.Configuration);
    builder.Services.AddNotificationService(builder.Configuration);
    ```
  </Step>

  <Step title="Config Services:* altında bind edilir">
    Servis ayarları `appsettings.json` içinde `Services:<Ad>` bölümünden bind edilir (OAuth ve Keycloak istisna — kök seviyede `OAuth` ve `Keycloak` bölümlerini kullanır). Bind, `services.Configure<TOptions>(o => configuration.GetSection("Services:...").Bind(o))` deseni ile yapılır.
  </Step>
</Steps>

<Note>
  Çoğu servis **Polly** ile resilience (retry / circuit-breaker) ve bir **health check** ekler. Dış sağlayıcı health check'leri `[External]` tag'i taşır: sağlayıcı çökse de `/health/ready` bozulmaz, sadece `/health/external` degraded olur. Mantık: e-posta/SMS sağlayıcısı geçici çökerse API çalışmaya devam etmeli.
</Note>

## Servis matrisi

| Servis        | Provider / Teknoloji           | Ana arayüz                      | Config anahtarı          | DI extension              |
| ------------- | ------------------------------ | ------------------------------- | ------------------------ | ------------------------- |
| Email         | Brevo SMTP (MailKit + Scriban) | `IEmailService`                 | `Services:Email`         | `AddEmailService`         |
| SMS           | NetGSM REST v2 OTP             | `IOtpSmsService`                | `Services:Sms`           | `AddSmsService`           |
| Notification  | SSE (in-memory Channel)        | `IAdminNotificationBroadcaster` | `Services:Notification`  | `AddNotificationService`  |
| OAuth         | Google / Meta / Keycloak       | `IOAuthClient<TUserInfo>`       | `OAuth`, `Keycloak`      | `AddOAuthProviders`       |
| Authenticator | OtpNet (TOTP / RFC 6238)       | `IAuthenticationTotpService`    | `Services:Authenticator` | `AddAuthenticatorService` |
| Hangfire      | Hangfire + PostgreSQL          | `ICommandBus` / `IEventBus`     | `Services:Hangfire`      | `AddHangfireServers`      |

## Resilience ve health check özeti

| Servis        | Resilience                                                                | Health check (tag)            |
| ------------- | ------------------------------------------------------------------------- | ----------------------------- |
| Email         | Polly retry (`RetryCount`, exponential) + circuit-breaker (6 hata / 1 dk) | `smtp` — `[External]`         |
| SMS           | Polly HTTP retry (`RetryCount`, lineer backoff)                           | `sms-provider` — `[External]` |
| OAuth         | Polly HTTP retry (3×, exponential)                                        | —                             |
| Hangfire      | Postgres storage retry + DLX kuyrukları                                   | `hangfire` — `[Ready]`        |
| Notification  | Bounded Channel `DropOldest` (backpressure)                               | —                             |
| Authenticator | Saf hesaplama (dış bağımlılık yok)                                        | —                             |

## Servis detayları

<CardGroup cols={2}>
  <Card title="Email" icon="envelope" href="/services/email">
    Brevo SMTP üzerinden Scriban şablonlu e-posta; ResilientEmailGateway ile Polly koruması.
  </Card>

  <Card title="SMS" icon="comment-sms" href="/services/sms">
    NetGSM REST v2 OTP entegrasyonu; ASCII-only mesaj, ortam bazlı telefon çözümleme.
  </Card>

  <Card title="Notification" icon="bell" href="/services/notification">
    SSE tabanlı, rol-hedefli admin bildirimleri; HMAC stream-token ile kimlik.
  </Card>

  <Card title="OAuth" icon="key" href="/services/oauth">
    Google, Meta ve Keycloak; PKCE (S256) tabanlı backend-driven akış.
  </Card>

  <Card title="Authenticator (TOTP)" icon="qrcode" href="/services/authenticator">
    OtpNet ile RFC 6238 TOTP; QR üretimi, drift toleranslı doğrulama.
  </Card>

  <Card title="Hangfire" icon="clock" href="/services/hangfire">
    PostgreSQL destekli arka plan iş kuyruğu; MediatR command/event köprüsü.
  </Card>
</CardGroup>
