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

# Overview

> Architecture and internal services for the Create AI Article endpoint

## Purpose

Creates AI-specific articles - SEO-optimized content pages designed to increase visibility in AI search results. Each page targets a specific topic related to the business.

## Architecture

```mermaid theme={null}
flowchart TD
    Request["POST /api/cron/create-ai-article"]
    
    subgraph steps [4-Step Pipeline]
        Step1["Step 1: Get Source Deployment"]
        Step2["Step 2: Scrape AI Site"]
        Step3["Step 3: Generate Content (LLM)"]
        Step4["Step 4: Generate Files"]
    end
    
    subgraph db [Database]
        AISites["ai_sites table"]
        AIArticles["ai_articles table"]
    end
    
    subgraph external [External]
        Vercel["Vercel (existing site)"]
        Gemini["Gemini API"]
    end
    
    Request --> Step1
    Step1 --> AISites
    AISites --> Step2
    Step2 --> Vercel
    Vercel --> Step3
    Step3 --> Gemini
    Gemini --> Step4
    Step4 --> AIArticles
```

## 4-Step Pipeline

| Step | Service                                               | Purpose                                 |
| ---- | ----------------------------------------------------- | --------------------------------------- |
| 1    | [get\_source\_deployment](step-1-get-source)          | Get AI site URL and existing posts      |
| 2    | [scrape\_ai\_site](step-2-scrape-ai-site)             | Scrape deployed AI site for content     |
| 3    | [generate\_article\_content](step-3-generate-content) | Use LLM to create new page content      |
| 4    | [generate\_article\_files](step-4-generate-files)     | Generate HTML, update sitemap, llms.txt |

## URL Structure

AI articles are published at root level for better AI SEO:

```
https://business.searchcompany.dev/topic-slug/
https://business.searchcompany.dev/another-topic/
```

## Generated Files

| File                 | Purpose                         |
| -------------------- | ------------------------------- |
| `/{slug}/index.html` | The AI article HTML             |
| `/sitemap.xml`       | Updated with new page           |
| `/llms.txt`          | Updated with new page reference |

## Code Location

```
src/app/apis/cron/create_boosted_page/
├── routes.py              # HTTP endpoint
├── mini_orchestrator.py   # Main orchestrator
├── url_utils.py           # URL/slug utilities
└── children/
    ├── step_1_get_source.py
    ├── step_2_scrape_ai_site.py
    ├── step_3_generate_content.py
    ├── step_4_generate_files.py
    └── templates/
        ├── article_html.py
        ├── article_index.py
        ├── article_llms_txt.py
        ├── llms_txt_update.py
        └── sitemap_update.py
```

## Response Format

```json theme={null}
{
  "status": "success",
  "files": [...],
  "article_url": "https://business.searchcompany.dev/topic-slug/",
  "article_path": "/topic-slug/",
  "article_id": "article_abc123",
  "title": "Topic Title",
  "project_name": "business-abc123",
  "ai_site_url": "https://business.searchcompany.dev",
  "faq_category": "business_article"
}
```

<Note>
  This endpoint generates files but does NOT deploy. Call `deploy-to-vercel` separately with the returned files.
</Note>
