{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tradeoff.studio/schemas/studio-v1.schema.json",
  "title": "Tradeoff Studio scenario project, version 1",
  "description": "Portable teaching model. Durations are milliseconds unless named otherwise. Imports are limited to 1 MiB of UTF-8 JSON. Graph drafts may be disconnected or cyclic; runnable graphs require separate semantic validation. Project references and active fault/burst windows also receive semantic validation.",
  "type": "object",
  "properties": {
    "format": {
      "const": "tradeoff-studio"
    },
    "schemaVersion": {
      "const": 1
    },
    "engineVersion": {
      "const": "1.0.0"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    },
    "description": {
      "type": "string",
      "minLength": 0,
      "maxLength": 4000
    },
    "baselineId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80
    },
    "activeVariantId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80
    },
    "variants": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "entryNodeId": {
            "type": "string",
            "minLength": 0,
            "maxLength": 80
          },
          "nodes": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 80
                },
                "name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 120
                },
                "kind": {
                  "type": "string",
                  "enum": ["service", "database", "external", "queue", "cache"]
                },
                "x": {
                  "type": "number",
                  "minimum": -2000,
                  "maximum": 4000
                },
                "y": {
                  "type": "number",
                  "minimum": -2000,
                  "maximum": 4000
                },
                "technology": {
                  "type": "string",
                  "minLength": 0,
                  "maxLength": 120
                },
                "provenance": {
                  "type": "string",
                  "enum": ["estimated", "measured"]
                },
                "processingMs": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 5000
                },
                "capacity": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 64
                },
                "replicas": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                },
                "workerLimit": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 256
                },
                "execution": {
                  "type": "string",
                  "enum": ["blocking", "async"]
                },
                "queueCapacity": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 1000
                },
                "dispatch": {
                  "type": "string",
                  "enum": ["sequential", "parallel"]
                },
                "cacheHitRate": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 100
                }
              },
              "required": [
                "id",
                "name",
                "kind",
                "x",
                "y",
                "technology",
                "provenance",
                "processingMs",
                "capacity",
                "replicas",
                "workerLimit",
                "execution",
                "queueCapacity",
                "dispatch",
                "cacheHitRate"
              ],
              "additionalProperties": false
            },
            "minItems": 0,
            "maxItems": 12
          },
          "edges": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 80
                },
                "from": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 80
                },
                "to": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 80
                },
                "mode": {
                  "type": "string",
                  "enum": ["sync", "async"]
                },
                "required": {
                  "type": "boolean"
                },
                "timeoutMs": {
                  "type": "integer",
                  "minimum": 50,
                  "maximum": 10000
                },
                "retries": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 2
                },
                "poolSize": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 100
                }
              },
              "required": [
                "id",
                "from",
                "to",
                "mode",
                "required",
                "timeoutMs",
                "retries",
                "poolSize"
              ],
              "additionalProperties": false
            },
            "minItems": 0,
            "maxItems": 24
          }
        },
        "required": ["id", "name", "entryNodeId", "nodes", "edges"],
        "additionalProperties": false
      },
      "minItems": 1,
      "maxItems": 4
    },
    "workload": {
      "type": "object",
      "properties": {
        "rate": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100
        },
        "durationSeconds": {
          "type": "integer",
          "minimum": 1,
          "maximum": 30
        },
        "drainSeconds": {
          "type": "integer",
          "minimum": 0,
          "maximum": 30
        },
        "burstMultiplier": {
          "type": "integer",
          "minimum": 1,
          "maximum": 3
        },
        "burstStartSeconds": {
          "type": "integer",
          "minimum": 0,
          "maximum": 30
        },
        "burstEndSeconds": {
          "type": "integer",
          "minimum": 0,
          "maximum": 30
        }
      },
      "required": [
        "rate",
        "durationSeconds",
        "drainSeconds",
        "burstMultiplier",
        "burstStartSeconds",
        "burstEndSeconds"
      ],
      "additionalProperties": false
    },
    "fault": {
      "type": "object",
      "properties": {
        "nodeId": {
          "type": "string",
          "minLength": 0,
          "maxLength": 80
        },
        "kind": {
          "type": "string",
          "enum": ["none", "slow", "outage"]
        },
        "startSeconds": {
          "type": "number",
          "minimum": 0,
          "maximum": 60
        },
        "endSeconds": {
          "type": "number",
          "minimum": 0,
          "maximum": 60
        },
        "multiplier": {
          "type": "number",
          "minimum": 1,
          "maximum": 20
        }
      },
      "required": ["nodeId", "kind", "startSeconds", "endSeconds", "multiplier"],
      "additionalProperties": false
    },
    "targets": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "version": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100000
        },
        "responseP95Ms": {
          "type": "integer",
          "minimum": 1,
          "maximum": 60000
        },
        "completionP95Ms": {
          "type": "integer",
          "minimum": 1,
          "maximum": 60000
        },
        "successRate": {
          "type": "number",
          "minimum": 0,
          "maximum": 100
        },
        "maxUnfinished": {
          "type": "integer",
          "minimum": 0,
          "maximum": 10000
        },
        "warningPercent": {
          "type": "number",
          "minimum": 1,
          "maximum": 99
        }
      },
      "required": [
        "name",
        "version",
        "responseP95Ms",
        "completionP95Ms",
        "successRate",
        "maxUnfinished",
        "warningPercent"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "format",
    "schemaVersion",
    "engineVersion",
    "name",
    "description",
    "baselineId",
    "activeVariantId",
    "variants",
    "workload",
    "fault",
    "targets"
  ],
  "additionalProperties": false
}
