> ## 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 Store Visibility Report endpoint

## Purpose

Stores daily visibility report after analyzing sampled prompts. Updates prompt visibility results and creates a daily report record.

## Architecture

```mermaid theme={null}
flowchart TD
    Request["POST /api/cron/store-visibility-report"]
    
    subgraph processing [Processing]
        ProcessResults["Process results"]
        CountPlatforms["Count platform hits"]
        BuildSummary["Build summary"]
    end
    
    subgraph db [Database Updates]
        UpdatePrompts["Update entity_prompts_tracker"]
        UpsertReport["Upsert visibility_reports"]
    end
    
    Request --> ProcessResults
    ProcessResults --> CountPlatforms
    CountPlatforms --> BuildSummary
    BuildSummary --> UpdatePrompts
    UpdatePrompts --> UpsertReport
    UpsertReport --> Response
```

## Request Body

```json theme={null}
{
  "clerk_org_id": "org-slug-123",
  "results": [
    {
      "prompt_id": 123,
      "prompt": "best payment gateway",
      "entity_id": "uuid-...",
      "entity_name": "Acme Corp",
      "entity_type": "business",
      "platforms": {
        "chatgpt": true,
        "claude": false,
        "gemini": true,
        ...
      }
    }
  ],
  "report_date": "2024-01-15"
}
```

## What Gets Updated

### entity\_prompts\_tracker

For each prompt result:

* Platform visibility booleans (chatgpt, claude, etc.)
* `checked_at` timestamp
* `last_tested_at` timestamp (for UI sorting)

### visibility\_reports

Daily report with:

* `prompts_sampled` - Array of all prompt results
* `summary` - Aggregated platform breakdown

## Response Format

```json theme={null}
{
  "status": "success",
  "report_date": "2024-01-15",
  "prompts_updated": 10,
  "summary": {
    "total_checked": 10,
    "platforms_breakdown": {
      "chatgpt": 7,
      "claude": 5,
      "gemini": 8,
      ...
    }
  }
}
```

## Code Location

```
src/app/apis/cron/store_visibility_report/routes.py
```
