# `anchor-routing.txt` — Routing Capability Declaration

**Version:** 1
**Status:** Draft

---

## Overview

`anchor-routing.txt` is a human-readable declaration file that tells apps, tools, SDKs, debuggers, crawlers, and AI agents how Anchor Routing is configured for a site or application.

It is the routing equivalent of `robots.txt` (crawler rules) or `sitemap.xml` (site structure) — but for **protocol discovery** of Anchor Routing capabilities.

---

## File Locations

### Standard (recommended)

```
/.well-known/anchor-routing.txt    # human-readable
/.well-known/anchor-routing.json   # machine-readable
```

### Shortcut alias (optional)

```
/ar.txt
```

---

## Purpose

Anchor Routing uses custom syntax that browsers, search engines, and dev tools do not understand natively. This file declares:

- Supported anchor cases
- Grammar version
- Syntax separators
- Registry mode and visibility
- SEO mapping behavior
- Resolver and docs endpoints

It turns Anchor Routing from hidden custom magic into **declared routing infrastructure**.

---

## Text Format (`anchor-routing.txt`)

Line-based key-value pairs. One field per line. Format: `Key: value`.

### v1 Fields

| Field                     | Required | Description                             | Example                            |
| ------------------------- | -------- | --------------------------------------- | ---------------------------------- |
| `Anchor-Routing`          | yes      | Spec version                            | `1`                                |
| `Name`                    | no       | App or SDK name                         | `My App`                           |
| `SDK`                     | no       | SDK package name                        | `@nextera.one/anchor-routing-core` |
| `Cases`                   | yes      | Comma-separated supported cases         | `page,param,dot,intent`            |
| `Primary-Case`            | no       | Default case if ambiguous               | `intent`                           |
| `Routing-Mode`            | no       | `registry` or `direct`                  | `registry`                         |
| `Internal-Anchor-Routing` | no       | Whether anchors are used internally     | `true`                             |
| `Public-SEO-URLs`         | no       | Whether SEO-friendly URLs are generated | `true`                             |
| `Anchor-Prefix`           | no       | Prefix for param/dot/intent cases       | `/~`                               |
| `Page-Case-Separator`     | no       | Page↔section separator                  | `~`                                |
| `Param-Case-Separator`    | no       | Param argument separator                | `;`                                |
| `Dot-Case-Separator`      | no       | Dot path separator                      | `.`                                |
| `Intent-Case-Binding`     | no       | Intent named-arg binding format         | `name.value`                       |
| `Escape-Mode`             | no       | Encoding strategy                       | `percent`                          |
| `Registry-Visibility`     | no       | `public` or `private`                   | `private`                          |
| `Resolver-Endpoint`       | no       | URL to a resolver API                   | `/api/resolve`                     |
| `Docs`                    | no       | Documentation URL                       | `/docs/anchor-routing`             |
| `Playground`              | no       | Playground URL                          | `/anchor-routing/playground`       |

### Example

```txt
Anchor-Routing: 1
Name: My Application
SDK: @nextera.one/anchor-routing-core
Cases: page,param,dot,intent
Primary-Case: intent
Routing-Mode: registry
Internal-Anchor-Routing: true
Public-SEO-URLs: true
Anchor-Prefix: /~
Page-Case-Separator: ~
Param-Case-Separator: ;
Dot-Case-Separator: .
Intent-Case-Binding: name.value
Escape-Mode: percent
Registry-Visibility: private
Docs: /docs/anchor-routing
Playground: /anchor-routing/playground
```

---

## JSON Format (`anchor-routing.json`)

Machine-readable counterpart for SDK auto-discovery, IDE extensions, crawlers, validators, and generators.

### Example

```json
{
  "anchorRouting": 1,
  "name": "My Application",
  "sdk": "@nextera.one/anchor-routing-core",
  "cases": ["page", "param", "dot", "intent"],
  "primaryCase": "intent",
  "routingMode": "registry",
  "internalAnchorRouting": true,
  "publicSeoUrls": true,
  "syntax": {
    "anchorPrefix": "/~",
    "pageCaseSeparator": "~",
    "paramCaseSeparator": ";",
    "dotCaseSeparator": ".",
    "intentCaseBinding": "name.value"
  },
  "escapeMode": "percent",
  "registryVisibility": "private",
  "docs": "/docs/anchor-routing",
  "playground": "/anchor-routing/playground"
}
```

---

## Security

The declaration file should describe **grammar and capabilities**, not expose sensitive internals.

### Safe to expose

- Supported cases
- Spec version
- Syntax separators
- Documentation and playground URLs
- Resolver style

### Do NOT expose by default

- Full route registry
- Auth-related mappings
- Hidden routes / internal module names
- Permission rules

---

## Discovery

Tools and SDKs should probe in this order:

1. `/.well-known/anchor-routing.json` (machine-readable, preferred)
2. `/.well-known/anchor-routing.txt` (human-readable fallback)
3. `/ar.txt` (shortcut alias)

A `404` at all three locations means the site does not declare Anchor Routing support (it may still use it internally without declaration).

---

## MIME Types

- `anchor-routing.txt` → `text/plain; charset=utf-8`
- `anchor-routing.json` → `application/json; charset=utf-8`
