> ## 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 Create Business endpoint

## Purpose

Registers a new business for AI visibility tracking. Creates records in multiple tables and updates Clerk organization metadata.

## Architecture

```mermaid theme={null}
flowchart TD
    Request["POST /api/business"]
    
    subgraph create [Create Records]
        CreateOrg["Create clerk_organization_details"]
        CreateEntity["Create entity in entities table"]
        GetScore["Get or create ranking score"]
    end
    
    subgraph clerk [Clerk API]
        UpdateMeta["Update organization metadata"]
    end
    
    Request --> CreateOrg
    CreateOrg --> CreateEntity
    CreateEntity --> GetScore
    GetScore --> UpdateMeta
    UpdateMeta --> Response
```

## Request Body

```json theme={null}
{
  "business_name": "Acme Corp",
  "business_url": "https://acme.com",
  "tracking_type": "business",
  "clerk_org_id": "org_abc123",
  "clerk_user_id": "user_xyz789",
  "org_slug": "acme-corp"
}
```

## What Gets Created

1. **clerk\_organization\_details** - Links Clerk org to business
2. **entities** - Business entity for tracking
3. **pre\_payment\_rankings** - Initial ranking score (32-49)
4. **Clerk metadata** - Business data on organization

## Response Format

```json theme={null}
{
  "id": 1,
  "business_uuid": "uuid-...",
  "business_name": "Acme Corp",
  "created_at": "2024-01-15T10:30:00Z",
  "ranking_score": 42,
  "entity_id": "uuid-..."
}
```

## Code Location

```
src/app/apis/onboarding/create_business/routes.py
```
