- Added a new API endpoint in the `IntegrationViewSet` to update the WordPress site structure, including post types and taxonomies. - Implemented a function to retrieve the site structure and sync it to the IGNY8 backend after establishing a connection. - Scheduled a daily cron job to keep the site structure updated. - Enhanced the WordPress plugin to trigger synchronization upon successful API connection. - Updated relevant files to support the new synchronization feature, improving integration capabilities.
18 KiB
18 KiB
WordPress Plugin ↔ IGNY8 Backend - Sync Architecture
System Diagram (Complete Flow)
┌─────────────────────────────────────────────────────────────────────────────┐
│ WORDPRESS SITE │
│ │
│ ┌──────────────────────────────────────────────────────────────────────┐ │
│ │ IGNY8 WordPress Bridge Plugin │ │
│ │ │ │
│ │ ┌─ Settings Page ┐ │ │
│ │ │ │ │ │
│ │ │ Email: dev@igny8.com │ │ │
│ │ │ API Key: igny8_aBcD3fG... │ │ │
│ │ │ Password: •••••••••• │ │ │
│ │ │ │ │ │
│ │ │ [Connect to IGNY8] ──────────────┐ │ │ │
│ │ │ │ │ │ │
│ │ │ Connection Status: Connected ✅ │ │ │ │
│ │ │ Enable Sync Operations: ☑️ │ │ │ │
│ │ │ Enable Two-Way Sync: ☑️ │ │ │ │
│ │ └─────────────────────────────────│────────────────────────────┘ │ │
│ │ │ │ │
│ │ Post Types: │ [NEW] Send Structure │ │
│ │ - Posts (123) │ ├─ Post Types │ │
│ │ - Pages (45) │ ├─ Taxonomies │ │
│ │ - Products (67) │ ├─ Counts │ │
│ │ │ └─ Enabled/Disabled │ │
│ │ Taxonomies: ↓ │ │
│ │ - Categories (12) │ │
│ │ - Tags (89) │ │
│ │ - Product Cat (15) │ │
│ │ │ │
│ │ [Daily Cron Job] │ │
│ │ └─ Re-sync structure every 24h │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
│ igny8_get_site_structure() ──── Gathers all post types & taxonomies │
│ igny8_sync_site_structure_to_backend() ──── Sends to API │
│ │
└─────────────────────────────────────────────────────────────────────────┘
│
│ HTTPS API Call
│ Bearer: API_KEY
↓
┌─────────────────────────────────────────────────────────────────────────────┐
│ IGNY8 SAAS BACKEND │
│ │
│ ┌──────────────────────────────────────────────────────────────────────┐ │
│ │ API Endpoint: POST /integration/integrations/{id}/update-structure/ │ │
│ │ │ │
│ │ [NEW] Receives: │ │
│ │ { │ │
│ │ "post_types": { │ │
│ │ "post": {"label": "Posts", "count": 123, ...}, │ │
│ │ "page": {"label": "Pages", "count": 45, ...}, │ │
│ │ "product": {"label": "Products", "count": 67, ...} │ │
│ │ }, │ │
│ │ "taxonomies": { │ │
│ │ "category": {"label": "Categories", "count": 12, ...}, │ │
│ │ "post_tag": {"label": "Tags", "count": 89, ...} │ │
│ │ }, │ │
│ │ "plugin_connection_enabled": true, │ │
│ │ "two_way_sync_enabled": true │ │
│ │ } │ │
│ │ │ │
│ │ ↓ Stores in Database │ │
│ │ │ │
│ │ SiteIntegration.config_json = { │ │
│ │ "content_types": { │ │
│ │ "post_types": {...}, │ │
│ │ "taxonomies": {...}, │ │
│ │ "last_structure_fetch": "2025-11-22T10:00:00Z" │ │
│ │ }, │ │
│ │ "plugin_connection_enabled": true, │ │
│ │ "two_way_sync_enabled": true │ │
│ │ } │ │
│ │ │ │
│ └──────────────────────────────────────────────────────────────────────┘ │
│ │
│ Endpoint: GET /integration/integrations/{id}/content-types/ │
│ ├─ Reads stored structure │
│ ├─ Counts synced content from Content model │
│ └─ Returns: POST_TYPES + TAXONOMIES + SYNC_COUNTS │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
│
│ HTTPS Response
│ JSON Data
↓
┌─────────────────────────────────────────────────────────────────────────────┐
│ IGNY8 FRONTEND │
│ │
│ ┌──────────────────────────────────────────────────────────────────────┐ │
│ │ Site Settings → Content Types Tab │ │
│ │ │ │
│ │ WordPress Content Types │ │
│ │ Last structure fetch: just now │ │
│ │ [Sync Now] │ │
│ │ │ │
│ │ Post Types │ │
│ │ ├─ Posts 123 total · 45 synced [Enabled] Limit: 100 │ │
│ │ ├─ Pages 45 total · 45 synced [Enabled] Limit: 100 │ │
│ │ └─ Products 67 total · 12 synced [Disabled] Limit: 100 │ │
│ │ │ │
│ │ Taxonomies │ │
│ │ ├─ Categories 12 total · 10 synced [Enabled] Limit: 100 │ │
│ │ ├─ Tags 89 total · 50 synced [Enabled] Limit: 100 │ │
│ │ └─ Product Categories 15 total · 0 synced [Disabled] Limit: 100 │ │
│ │ │ │
│ │ [Shows structure is populated ✅] │ │
│ │ │ │
│ └──────────────────────────────────────────────────────────────────────┘ │
│ │
│ Status Indicator: Connected ✅ (green dot) │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
Data Flow Timeline
TIME EVENT COMPONENT STATUS
────────────────────────────────────────────────────────────────────
T=0s User clicks "Connect" WordPress Admin 🔄
T=1s ├─ Validate credentials Plugin API 🔄
T=2s ├─ Store API key securely WordPress ✅
T=3s ├─ Get site ID from backend Plugin API ✅
T=4s │
T=5s ├─ [NEW] Get site structure WordPress DB 🔄
T=6s │ (gather post types/taxes)
T=7s │
T=8s └─ [NEW] POST to update- Plugin API 🔄
T=9s structure endpoint
T=10s
T=11s Backend receives structure API Endpoint 🔄
T=12s └─ Parse request Django View 🔄
T=13s └─ Update integration config Database ✅
T=14s └─ Return success API Response ✅
T=15s
T=16s Show success message WordPress Admin ✅
T=17s
T=18s User navigates to Frontend Browser 🔄
T=19s ├─ Load Site Settings Frontend 🔄
T=20s ├─ Click Content Types tab Frontend JS 🔄
T=21s │
T=22s ├─ GET content-types endpoint Frontend API 🔄
T=23s │
T=24s Backend retrieves structure API Endpoint 🔄
T=25s └─ Read from config_json Database 🔄
T=26s └─ Count synced content Database Query 🔄
T=27s └─ Return data API Response ✅
T=28s
T=29s Display in table Frontend UI ✅
T=30s ├─ Post Types section ✅ POPULATED
T=31s ├─ Taxonomies section ✅ POPULATED
T=32s ├─ Sync counts ✅ SHOWS NUMBERS
T=33s └─ "Connected" badge ✅ GREEN
STATUS: 🟢 FULLY OPERATIONAL
State Transitions
┌─────────────────┐
│ Not Connected │ (Initial state)
└────────┬────────┘
│ User fills form + clicks Connect
↓
┌──────────────────────────┐
│ Authenticating │ (Validating credentials)
└────────┬─────────────────┘
│ Credentials valid
↓
┌──────────────────────────┐
│ Connected │ ✅
│ Structure syncing... │ (NEW: Pushing structure)
└────────┬─────────────────┘
│ Structure pushed
↓
┌──────────────────────────┐
│ Connected & Ready │ ✅✅
│ All data synced │ (NOW: Content Types tab ready)
└──────────────────────────┘
│
├─→ Every 24 hours
│ ├─ Cron: igny8_sync_site_structure
│ └─ [Repeats structure sync]
│
└─→ On demand
├─ "Sync Now" button
└─ Manual structure push
Component Interactions
WordPress Plugin IGNY8 Backend
─────────────────── ──────────────
User Input Django REST Framework
↓ ↑
Settings Form ─────────────→ Authentication
↓ (API Key Check)
Connection Handler ↑
├─ Login IntegrationViewSet
├─ Get Site ID ↑
│ [NEW] update_site_structure()
└─→ igny8_get_site_structure()
├─ Get post types ↓
├─ Get taxonomies Store in config_json
└─ Count items ↓
↓ SiteIntegration.save()
igny8_sync_site_structure_to_backend()
│
├─ Find integration ID
│
└─→ POST /update-structure/
↓
Validation ✅
↓
Update config_json
↓
Return 200 OK
Error Handling Flow
Connection Attempt
│
├─→ Credentials Invalid?
│ └─ Return: "Failed to connect"
│
├─→ Site ID Not Found?
│ └─ Return: "Site not found"
│
└─→ Success! ✅
│
└─→ Get Site Structure
│
├─→ No Post Types?
│ └─ Log error, continue
│
├─→ No Taxonomies?
│ └─ Log error, continue
│
└─→ Success! ✅
│
└─→ Find Integration
│
├─→ Not Found?
│ └─ Create temp integration
│
└─→ Found! ✅
│
└─→ POST Structure
│
├─→ API Error?
│ └─ Log error, retry daily
│
└─→ Success! ✅
└─ Update last_sync timestamp
Performance Characteristics
| Operation | Time | Frequency |
|---|---|---|
| Get site structure | ~50ms | On connect, then daily |
| POST structure | ~500ms | On connect, then daily |
| GET content-types | ~200ms | When user opens tab |
| Database query (counts) | ~100ms | Per request |
Total time for complete sync: ~550ms (typically < 1 second)
Security Architecture
Request Flow:
WordPress Plugin
│
├─ Authorization: Bearer {API_KEY}
│
└─→ HTTPS only
└─→ Backend
│
├─ Authenticate API Key
├─ Validate Site Active
├─ Check Permissions
└─ Process Request
│
└─ Update SiteIntegration
└─ Encrypted storage (if sensitive)
Architecture diagram updated: November 22, 2025
Sync fix implementation: Complete