> ## 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 for the Deploy to Vercel endpoint

## Purpose

Batch deploys all pending files to Vercel in a single deployment. Called after content generation jobs complete.

## Architecture

```mermaid theme={null}
flowchart TD
    Request["POST /api/cron/deploy-to-vercel"]
    
    subgraph helpers [Helper Functions]
        PreserveSections["Preserve article sections"]
        SyncFAQ["Sync FAQ with AI articles"]
        GenSitemap["Generate sitemap"]
        BuildMapping["Build file mapping"]
    end
    
    subgraph vercel [Vercel API]
        GetCurrent["Get current deployment"]
        UploadFiles["Upload new files"]
        CreateDeploy["Create deployment"]
        WaitReady["Wait for READY"]
        VerifyPaths["Verify paths accessible"]
    end
    
    Request --> PreserveSections
    PreserveSections --> SyncFAQ
    SyncFAQ --> GenSitemap
    GenSitemap --> BuildMapping
    BuildMapping --> GetCurrent
    GetCurrent --> UploadFiles
    UploadFiles --> CreateDeploy
    CreateDeploy --> WaitReady
    WaitReady --> VerifyPaths
    VerifyPaths --> Response
```

## Request Body

```json theme={null}
{
  "project_name": "business-abc123",
  "files": [
    {"path": "/topic-slug/index.html", "content": "..."},
    {"path": "public/sitemap.xml", "content": "..."}
  ],
  "ai_site_url": "https://business.searchcompany.dev",
  "source_url": "https://customer-domain.com",
  "business_name": "Acme Corp",
  "products": ["Product A", "Product B"],
  "new_posts": [...],
  "existing_posts": [...],
  "verify_paths": ["/topic-slug/"]
}
```

## Key Features

### Article Section Preservation

When deploying a new `index.js`, existing AI article links are preserved:

```javascript theme={null}
// Existing article sections are extracted and merged
const existing = extract_article_sections(current_index)
const merged = merge_article_sections_into_new_index(new_index, existing)
```

### FAQ Sync

Automatically adds missing AI article links to FAQ sections.

### Sitemap Regeneration

Regenerates `sitemap.xml` to include all AI articles.

## Response Format

```json theme={null}
{
  "status": "success",
  "deployment_url": "https://...",
  "ai_site_url": "https://business.searchcompany.dev",
  "files_deployed": 15,
  "verified_paths": ["/topic-slug/"]
}
```

## Code Location

```
src/app/apis/cron/deploy_to_vercel/
├── routes.py    # HTTP endpoint
└── helpers/
    ├── index_js.py       # Index.js manipulation
    ├── sitemap.py        # Sitemap generation
    └── article_sections.py # Article section extraction
```
