> ## 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.

# Step 4: Generate Files

> Internal service that generates all AI article files

# Internal Service: generate\_article\_files

Generates all static files for an AI article at the ROOT level of the site.

## Function Signature

```python theme={null}
async def generate_article_files(content_result: dict) -> dict
```

## Parameters

| Parameter        | Type | Description                                                              |
| ---------------- | ---- | ------------------------------------------------------------------------ |
| `content_result` | dict | Output from Step 3 (generate\_article\_content) with additional metadata |

### content\_result Structure

```python theme={null}
{
    "article_content": {
        "title": "...",
        "sources": [...],
        "mentioned_business": "..."
    },
    "business_id": "...",
    "product_id": "...",  # Optional
    "product_name": "...",  # Optional
    "article_id": "article_xxx",
    "article_type": "article",
    "ai_site_url": "https://...",
    "source_url": "https://...",  # Customer's real domain (REQUIRED)
    "existing_posts": [...],
    "entity_id": "...",
    "faq_category": "business_article" | "product_article"
}
```

## Returns

```python theme={null}
{
    "status": "success",
    "files": [
        {"path": "pages/{slug}.js", "content": "..."},
        {"path": "public/{slug}/index.html", "content": "..."},
        {"path": "public/{slug}/llms.txt", "content": "..."},
        {"path": "public/{slug}/data.json", "content": "..."}
    ],
    "title": "...",
    "slug": "...",
    "article_path": "/{slug}/",
    "published_date": "YYYY-MM-DD",
    "faq_category": "..."
}
```

## Generated Files

| File                       | Purpose                              |
| -------------------------- | ------------------------------------ |
| `pages/{slug}.js`          | Next.js page component for routing   |
| `public/{slug}/index.html` | Static HTML for direct access        |
| `public/{slug}/llms.txt`   | AI-optimized content for crawlers    |
| `public/{slug}/data.json`  | Structured data (Schema.org Article) |

## URL Structure

All AI articles are placed at ROOT level for better AI SEO:

* **Business articles**: `/{slug}/`
* **Product articles**: `/{slug}/`

No more `/ai_blog/` prefix.

## Canonical URLs

**Critical**: All public-facing URLs use `source_url` (customer's real domain), NOT `ai_site_url`. This ensures search engines index the correct domain.

## Template Dependencies

Uses templates from `children/templates/`:

* `generate_article_html()` - HTML with proper meta tags
* `generate_article_llms_txt()` - AI-optimized text content
* `slugify()` - URL-safe slug generation

## Code Location

```
src/app/apis/cron/create_boosted_page/children/step_4_generate_files.py
```
