> ## 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 Get Visibility Score endpoint

## Purpose

Returns the current visibility score and historical data for dashboard charts. Shows how visible a business/product is across AI platforms over time.

## Architecture

```mermaid theme={null}
flowchart TD
    Request["GET /api/visibility-score/{org_slug}"]
    
    subgraph logic [Logic]
        GetEntity["Get entity_id"]
        GetHistory["Get history_scores"]
        CalcTrend["Calculate 7-day trend"]
        FormatHistory["Format for frontend"]
    end
    
    subgraph db [Database]
        Entities["entities table"]
        History["visibility_score_history"]
    end
    
    Request --> GetEntity
    GetEntity --> Entities
    GetEntity --> GetHistory
    GetHistory --> History
    History --> CalcTrend
    CalcTrend --> FormatHistory
    FormatHistory --> Response
```

## Query Parameters

| Parameter       | Type     | Description                     |
| --------------- | -------- | ------------------------------- |
| `product_id`    | `string` | Filter by product (optional)    |
| `business_url`  | `string` | Business URL for ranking lookup |
| `ranking_score` | `int`    | Pre-payment ranking score       |

## Response Format

```json theme={null}
{
  "visibilityScore": {
    "value": 67,
    "trend": "+12%"
  },
  "history": [
    {"date": "Jan 15", "value": 55},
    {"date": "Jan 16", "value": 58},
    {"date": "Jan 17", "value": 67}
  ]
}
```

## Trend Calculation

Compares current score to score from 7 days ago:

```
trend = ((current - week_ago) / week_ago) * 100
```

## History Format

* Returns last 6 months of data
* Dates formatted as "Jan 15" for frontend charts
* Values are 0-100 percentage scores

## Code Location

```
src/app/apis/current_setup/visibility_score/routes.py
```
