{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://turborepo.com/microfrontends/schema.json",
  "title": "Turborepo microfrontends configuration",
  "description": "Configuration for Turborepo's built-in microfrontends proxy server",
  "type": "object",
  "properties": {
    "$schema": {
      "type": "string",
      "description": "The JSON schema for this configuration file"
    },
    "applications": {
      "type": "object",
      "description": "Map of application configurations keyed by application name",
      "additionalProperties": {
        "$ref": "#/$defs/application"
      },
      "minProperties": 1
    },
    "options": {
      "type": "object",
      "description": "Global proxy options",
      "properties": {
        "localProxyPort": {
          "type": "integer",
          "description": "Port for the local proxy server",
          "default": 3024,
          "minimum": 1,
          "maximum": 65535
        }
      },
      "additionalProperties": false
    }
  },
  "required": ["applications"],
  "additionalProperties": false,
  "$defs": {
    "application": {
      "type": "object",
      "description": "Configuration for a single microfrontend application",
      "properties": {
        "packageName": {
          "type": "string",
          "description": "Name of the package from package.json in your workspace. If not provided, the application key is used."
        },
        "development": {
          "type": "object",
          "description": "Development configuration",
          "properties": {
            "local": {
              "description": "Port configuration for local development. Can be a number (port), string (hostname:port or URL), or object with port property.",
              "oneOf": [
                {
                  "type": "integer",
                  "description": "Port number",
                  "minimum": 1,
                  "maximum": 65535
                },
                {
                  "type": "string",
                  "description": "Hostname with port (e.g., 'localhost:3000') or full URL (e.g., 'http://localhost:3000')",
                  "pattern": "^([a-zA-Z][a-zA-Z0-9+.-]*:\\/\\/)?[^:]+:[0-9]+$"
                },
                {
                  "type": "object",
                  "properties": {
                    "port": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 65535
                    }
                  },
                  "additionalProperties": false
                }
              ]
            },
            "fallback": {
              "type": "string",
              "description": "Fallback URL to proxy to when the application is not running locally. Useful for commands like 'turbo dev --filter=web' that only run a subset of applications."
            }
          },
          "additionalProperties": false
        },
        "routing": {
          "type": "array",
          "description": "Array of path groups that should route to this application. If not provided, the application becomes the default application that catches all unmatched routes.",
          "items": {
            "$ref": "#/$defs/pathGroup"
          },
          "minItems": 1
        }
      },
      "additionalProperties": false
    },
    "pathGroup": {
      "type": "object",
      "description": "A group of URL path patterns",
      "properties": {
        "paths": {
          "type": "array",
          "description": "Array of URL path patterns. Use :param for single segments and :param* for wildcards.",
          "items": {
            "type": "string",
            "pattern": "^/.*$"
          },
          "minItems": 1
        },
        "group": {
          "type": "string",
          "description": "Optional label for organizing routes. This is for organizational purposes and doesn't affect routing behavior."
        }
      },
      "required": ["paths"],
      "additionalProperties": false
    }
  }
}
