{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "softr.json",
  "type": "object",
  "properties": {
    "auth": {
      "type": "object",
      "description": "Authentication. Written in this repo and read by the app's build.",
      "properties": {
        "routes": {
          "type": "object",
          "description": "Where the app's sign-in pages live.",
          "properties": {
            "login": {
              "type": "object",
              "description": "The sign-in page.",
              "properties": {
                "path": { "$ref": "#/$defs/appPath" },
                "redirectParam": {
                  "type": "string",
                  "description": "The search param that carries where to go after signing in. Every unauthenticated redirect sets it."
                }
              },
              "required": ["path", "redirectParam"],
              "additionalProperties": false
            },
            "resetPassword": { "$ref": "#/$defs/tokenRoute", "description": "The page a password reset email links to." },
            "acceptInvitation": { "$ref": "#/$defs/tokenRoute", "description": "The page an invitation email links to." },
            "magicLink": { "$ref": "#/$defs/tokenRoute", "description": "The page a magic link email links to." },
            "sso": {
              "type": "object",
              "description": "The page single sign-on comes back to when it needs an authenticator code or failed. Defaults to /sso-authentication.",
              "properties": {
                "path": { "$ref": "#/$defs/appPath" }
              },
              "required": ["path"],
              "additionalProperties": false
            }
          },
          "required": ["login", "resetPassword", "acceptInvitation", "magicLink"],
          "additionalProperties": false
        },
        "guard": {
          "type": "object",
          "description": "What a route guard does when it denies a visitor. A route's own overrides win over these.",
          "properties": {
            "unauthenticated": {
              "$ref": "#/$defs/accessBehaviour",
              "description": "The route needs a signed-in visitor and there is none. Defaults to a redirect to /login."
            },
            "alreadyAuthenticated": {
              "$ref": "#/$defs/accessBehaviour",
              "description": "The route is for signed-out visitors only. Defaults to a redirect to /."
            },
            "forbidden": {
              "$ref": "#/$defs/accessBehaviour",
              "description": "Signed in, but in none of the groups the route names. Defaults to throwing, for the route's errorComponent to render."
            }
          },
          "required": ["unauthenticated", "alreadyAuthenticated", "forbidden"],
          "additionalProperties": false
        }
      },
      "required": ["routes", "guard"],
      "additionalProperties": false
    },
    "user": {
      "type": "object",
      "description": "The signed-in user.",
      "properties": {
        "properties": {
          "type": "object",
          "description": "Fields of the users table the app reads as user.properties, keyed by the name the app uses. Each value is a field id. No other field leaves the server.",
          "additionalProperties": { "type": "string" }
        }
      },
      "required": ["properties"],
      "additionalProperties": false
    },
    "allowEmbedding": {
      "type": "array",
      "description": "Sites that may show the published app in an iframe, signed-in pages included, as https origins like \"https://partner.com\", or \"*\" for any site. Any other site is still blocked. With at least one, session cookies use SameSite=None, which drops the browser's CSRF protection. Empty by default.",
      "items": { "type": "string", "pattern": "^(\\*|https://[^/\\\\?#@\\s;,]+)$" }
    },
    "logo": {
      "type": "object",
      "description": "The app's logo, written by the Logo field in Studio. Every place the app shows its brand reads it. Defaults to the \"layers\" icon.",
      "properties": {
        "source": {
          "enum": ["image", "icon"],
          "description": "Which of the two the app shows. Both are kept, so switching back loses nothing."
        },
        "icon": {
          "type": "string",
          "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
          "description": "A Lucide icon name, like \"layers\". Shown next to the app's name. Also what shows when source is \"image\" and no image fits."
        },
        "image": {
          "type": "object",
          "properties": {
            "square": { "$ref": "#/$defs/logoFile", "description": "The logo without the app name, about square." },
            "horizontal": { "$ref": "#/$defs/logoFile", "description": "The logo with the app name in it, wide." }
          }
        }
      },
      "required": ["source", "icon", "image"]
    },
    "seo": {
      "type": "object",
      "description": "Search engine settings. With enabled true, every page gets a canonical link and social tags by default.",
      "properties": {
        "enabled": { "type": "boolean", "description": "Turns on the search engine defaults for every page." }
      },
      "required": ["enabled"]
    }
  },
  "required": ["auth"],
  "$defs": {
    "appPath": {
      "type": "string",
      "pattern": "^/[^?#]*$",
      "description": "A path on this app, with no search or hash."
    },
    "tokenRoute": {
      "type": "object",
      "properties": {
        "path": { "$ref": "#/$defs/appPath" },
        "tokenParam": {
          "type": "string",
          "description": "The search param that carries the link's token."
        }
      },
      "required": ["path", "tokenParam"],
      "additionalProperties": false
    },
    "logoFile": {
      "type": "object",
      "properties": {
        "onLight": { "$ref": "#/$defs/logoUrl", "description": "The file for light backgrounds." },
        "onDark": { "$ref": "#/$defs/logoUrl", "description": "The file for dark backgrounds, such as dark mode. onLight shows there when it is missing." }
      },
      "required": ["onLight"]
    },
    "logoUrl": {
      "type": "string",
      "pattern": "^(/(?!/)|https://)[^\\\\\\u0000-\\u001F\\u007F-\\u009F]*$",
      "description": "A path under public/, like \"/logo.svg\", or an https URL, with no backslash or control character."
    },
    "accessBehaviour": {
      "oneOf": [
        { "type": "string", "description": "A path to redirect to." },
        {
          "type": "object",
          "properties": {
            "strategy": { "const": "redirect" },
            "to": { "type": "string" }
          },
          "required": ["strategy", "to"],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": { "strategy": { "const": "throw" } },
          "required": ["strategy"],
          "additionalProperties": false
        }
      ]
    }
  }
}
