Blog System Flow Diagram

Request Routing & Content Generation Flow

📊 Architecture 🔄 Flow Diagram

Request Flow & Client Detection

Entry Point
Decision Point
Ben's Flow
KashLegal Flow
Error/Forbidden

🌐 Incoming Request

wordpress-seo-agent.benitos.workers.dev

🔍 Client Manager

Detects client from:
• Headers (X-Client-Slug)
• URL path (/api/kash-legal/...)
• Subdomain
• Query params

Which Client?

👤 Ben Pouladian

Default client detected

⚖️ KashLegal

kash-legal client detected

📝 /api/wordpress/auto-post

Fortune 500 style content

📄 /api/kash-legal/professional-content

Professional legal format

🚫 Forbidden Access

KashLegal attempting to use /api/wordpress/auto-post
Returns 400 error with message

🤖 AI Content Generator

• GPT-4.1 Fortune style
• 800-1200 words
• First-person voice
• Current news integration

⚖️ Accident Generator

• Professional format
• 1300-1600 words
• CA law references
• Accident news only

✅ WordPress Publishing

Content published to respective sites

Ben (default)
kash-legal
FORBIDDEN

Content Generation Timeline

Step 1 - Ben Pouladian

📰 News Fetching (Optional)

Guardian API, NewsAPI for current tech/business news

Step 1 - KashLegal

🚗 Accident News Integration

SerpAPI, NewsAPI filtered for California accidents only

Step 2 - Ben Pouladian

🔗 Link Curation

Curates 5-7 external links to Forbes, HBR, MIT, etc.

Step 2 - KashLegal

📋 Format Template

Loads professional legal format with required sections

Step 3 - Ben Pouladian

🤖 GPT-4.1 Generation

Fortune 500 style, conversational tone, Ben's voice

Step 3 - KashLegal

⚖️ Legal Content Generation

Structured sections, CA statutes, no em-dashes

Step 4 - Ben Pouladian

🖼️ Dynamic Images

3 Pexels images embedded in content

Step 4 - KashLegal

📸 Image Placeholders

3 descriptive placeholders for legal scenarios

Final Step - Both Clients

📤 WordPress Publishing

Ben → benpouladian.com | KashLegal → kashlegal.com

⏰ Scheduled Auto-Post Flow

Ben Pouladian Schedule

Times: 6:00 AM & 4:00 PM PST
Days: Every day (Mon-Sun)
Categories: Randomly selected
Flow:
1. Cron triggers at scheduled time
2. Check if already posted today
3. Select random category
4. Generate Fortune 500 content
5. Publish to WordPress

KashLegal Schedule

Times: 9:00 AM & 4:00 PM PST
Days: Weekdays only (Mon-Fri)
Content: City + accident type
Flow:
1. Cron triggers at scheduled time
2. Check if already posted today
3. Select random city & accident type
4. Generate professional legal content
5. Publish to WordPress

⚠️ Critical Error Prevention

❌ Format Mixing Prevention

ClientManager enforces that KashLegal CANNOT use Ben's Fortune 500 format endpoint

if (clientSlug === 'kash-legal' && endpoint === '/api/wordpress/auto-post') {
  return error(400, 'Forbidden');
}

🔐 Token Isolation

Each client has separate WordPress tokens to prevent cross-posting

Ben: WPCOM_ACCESS_TOKEN
Kash: WPCOM_ACCESS_TOKEN_KASH_LEGAL

📊 Format Validation

Each client has strict format requirements enforced at generation time

KashLegal: 1,300-1,600 words
Ben: 800-1,200 words