5.8 KiB
NAKS Synchronization & Trigger System Documentation
This document explains the technical architecture and workflow of the NAKS multi-project synchronization system. This system ensures that when a NAKS certificate changes its "Source Project" (ownership), all other project sites are notified and updated automatically.
🇹🇷 Türkçe Dokümantasyon
1. Genel Bakış
NAKS Senkronizasyon Sistemi, birden fazla proje sahasında (Web Uygulaması) ortak bir veri havuzunun korunmasını sağlar. Özellikle naks_certificates (Technology) modülünde, bir sertifikanın "Source Project" (Kaynak Proje) alanı değiştiğinde, diğer tüm projelerin bu değişikliği anında öğrenmesi ve verilerini güncellemesi gerekir.
Bu sistem, Event-Driven (Olay Güdümlü) bir yapı kullanır:
- Kullanıcı bir kaydı düzenler.
- Sistem değişikliği algılar.
- Diğer projelere "Senkronizasyon Yap" emri gönderilir.
- Diğer projeler, güncel veriyi çeker.
2. Mimari Bileşenler
Sistem 4 ana bileşenden oluşur:
A. Observer (Gözlemci)
Dosya: app/Observers/NaksCertificateObserver.php
- Veritabanındaki
updatedolayını dinler. - Eğer
source_projectsütunu değişmişse (örneğin Viksa'dan boş/bu proje'ye geçmişse) tetiklenir. TriggerNaksSyncJob'ı kuyruğa (Queue) ekler.
B. Trigger Job (Tetikleyici İş)
Dosya: app/Jobs/TriggerNaksSyncJob.php
- Arka planda (Queue) çalışır.
- Sistemdeki diğer tüm proje URL'lerini (
api/project-app-urls) listeler. - Kendisi hariç diğer tüm projelere
POST /api/naks/trigger-syncisteği atar.
C. Endpoint Controller (Karşılayıcı Uç Nokta)
Dosya: app/Http/Controllers/Api/NaksSyncController.php
- Diğer projelerden gelen tetikleme isteklerini karşılar.
- İstek geldiğinde güvenlik kontrolü yapar.
- Gelen isteğe göre
NaksSyncService->sync()metodunu çalıştıracak bir işlemi kuyruğa alır.
D. Sync Service (Senkronizasyon Servisi)
Dosya: app/Services/NaksSyncService.php
- Asıl işi yapan servistir.
- Karşı projeye bağlanır, token alır ve verileri (
naks_certificates) indirip yerel veritabanını günceller. - Conflict (Çakışma) yönetimi yapar (timestamp kontrolü).
3. İş Akışı (Workflow)
- Adım 1: Kullanıcı A Projesinde bir NAKS sertifikasını düzenler ve
Source Projectalanını değiştirir (örneğin temizler). - Adım 2:
NaksCertificateObserverbu değişikliği yakalar. - Adım 3: Observer,
TriggerNaksSyncJobbaşlatır. - Adım 4: Job, Proje B ve Proje C'ye API isteği gönderir:
POST .../api/naks/trigger-sync. - Adım 5: Proje B isteği alır, doğrular ve kendi kuyruğuna "Senkronizasyon Başlat" emri verir.
- Adım 6: Proje B, arka planda Proje A'ya bağlanır ve güncellenmiş kaydı kendi veritabanına yazar.
4. Kurulum ve Gereksinimler
- Queue Worker: Sistemin çalışması için Laravel Queue Worker (
php artisan queue:work) sunucuda çalışıyor olmalıdır. - Observer Kaydı:
AppServiceProvideriçerisinde observer tanımlı olmalıdır. - Yetkilendirme:
.envdosyasındaSYNC_ADMIN_EMAILveSYNC_ADMIN_PASSWORDtanımlı olmalıdır.
🇬🇧 English Documentation
1. Overview
The NAKS Synchronization System maintains a shared data pool across multiple project sites (Web Applications). Specifically for the naks_certificates (Technology) module, when the "Source Project" field of a certificate changes, all other projects must be notified immediately to update their local data.
The system uses an Event-Driven architecture:
- User updates a record.
- System detects the change.
- A "Trigger Sync" command is sent to other projects.
- Other projects pull the latest data.
2. Architecture Components
The system consists of 4 main components:
A. Observer
File: app/Observers/NaksCertificateObserver.php
- Listens for the database
updatedevent. - Triggers if the
source_projectcolumn has changed (e.g., changed from 'Viksa' to empty/this project). - Dispatches
TriggerNaksSyncJobto the queue.
B. Trigger Job
File: app/Jobs/TriggerNaksSyncJob.php
- Runs in the background (Queue).
- Lists all other project URLs via (
api/project-app-urls). - Sends a
POST /api/naks/trigger-syncrequest to all projects except the current one.
C. Endpoint Controller
File: app/Http/Controllers/Api/NaksSyncController.php
- Receives trigger requests from other projects.
- Validates the incoming request.
- Queues a task to run
NaksSyncService->sync()based on the trigger.
D. Sync Service
File: app/Services/NaksSyncService.php
- The core service that performs logic.
- Connects to the remote project, authenticates, downloads data (
naks_certificates), and updates the local database. - Handles conflict resolution (via timestamp checks).
3. Workflow
- Step 1: User modifies a NAKS certificate in Project A and changes the
Source Projectfield. - Step 2:
NaksCertificateObservercaptures this event. - Step 3: The Observer dispatches
TriggerNaksSyncJob. - Step 4: The Job sends an API request to Project B and Project C:
POST .../api/naks/trigger-sync. - Step 5: Project B receives the request, validates it, and queues a "Start Sync" command locally.
- Step 6: Project B connects to Project A in the background and updates its local record with the new data.
4. Setup & Requirements
- Queue Worker: A Laravel Queue Worker (
php artisan queue:work) must be running on the server for asynchronous processing. - Observer Registration: The observer must be registered in
AppServiceProvider. - Authentication:
SYNC_ADMIN_EMAILandSYNC_ADMIN_PASSWORDmust be configured in the.envfile.