{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://data-lab.co/schema/v1.json",
  "title": "Data Lab architecture spec (data-lab/v1)",
  "description": "Describe a data architecture; import it into Data Lab. Only type/id on components and from/to on flows are required; everything else has realistic defaults.",
  "type": "object",
  "required": [
    "components",
    "flows"
  ],
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "type": "string"
    },
    "format": {
      "const": "data-lab/v1"
    },
    "name": {
      "type": "string",
      "maxLength": 80
    },
    "description": {
      "type": "string",
      "maxLength": 500
    },
    "components": {
      "type": "array",
      "minItems": 1,
      "maxItems": 500,
      "items": {
        "$ref": "#/$defs/component"
      }
    },
    "flows": {
      "type": "array",
      "maxItems": 2000,
      "items": {
        "$ref": "#/$defs/flow"
      }
    }
  },
  "$defs": {
    "component": {
      "type": "object",
      "required": [
        "id",
        "type"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.:-]+$",
          "minLength": 1,
          "maxLength": 64
        },
        "type": {
          "enum": [
            "api",
            "database",
            "kafka",
            "kinesis",
            "airflow",
            "spark",
            "flink",
            "dbt",
            "s3",
            "lakehouse",
            "snowflake",
            "bigquery",
            "dlq",
            "bi",
            "ml",
            "schema_registry",
            "cdc_connector",
            "feature_store",
            "vector_db",
            "reverse_etl",
            "data_quality",
            "catalog",
            "cache"
          ]
        },
        "label": {
          "type": "string",
          "maxLength": 80
        },
        "vendor": {
          "type": "string",
          "maxLength": 80,
          "description": "Concrete product, e.g. PostgreSQL, Confluent Kafka, Databricks."
        },
        "layer": {
          "enum": [
            "source",
            "ingest",
            "process",
            "store",
            "serve"
          ],
          "description": "Defaults from the type. Use \"serve\" for an api component that reads from a cache/DB/warehouse (consuming application)."
        },
        "description": {
          "type": "string",
          "maxLength": 500
        },
        "capacityPerSec": {
          "type": "number",
          "minimum": 0,
          "description": "Max events/s before the component becomes a bottleneck."
        },
        "capacityRecordsPerRun": {
          "type": "number",
          "minimum": 0,
          "description": "Batch engines: max records one run can process."
        },
        "partitions": {
          "type": "integer",
          "minimum": 0
        },
        "retentionHours": {
          "type": "number",
          "minimum": 0
        },
        "format": {
          "enum": [
            "parquet",
            "delta",
            "iceberg",
            "hudi",
            "avro",
            "protobuf",
            "json",
            "csv"
          ]
        },
        "slaFreshnessSec": {
          "type": "number",
          "minimum": 0,
          "description": "Max acceptable data age at this component, in seconds."
        },
        "transform": {
          "type": "object",
          "required": [
            "kind",
            "selectivity"
          ],
          "additionalProperties": false,
          "properties": {
            "kind": {
              "enum": [
                "map",
                "filter",
                "aggregate",
                "join",
                "explode"
              ]
            },
            "selectivity": {
              "type": "number",
              "minimum": 0,
              "description": "Output/input ratio."
            }
          }
        },
        "runsOn": {
          "description": "Where the component runs: drives hard throughput limits and the cost estimate. Unknown provider/service/size are dropped on import. Catalogue: aws: MSK Express (express.m7g.large, express.m7g.xlarge, express.m7g.2xlarge, express.m7g.4xlarge, express.m7g.8xlarge, express.m7g.12xlarge, express.m7g.16xlarge); MSK Standard (kafka.m5.large, kafka.m5.xlarge, kafka.m5.2xlarge, kafka.m5.4xlarge); Kinesis Data Streams provisioned (shard); Kinesis Data Streams on-demand (on-demand); Managed Service for Apache Flink (KPU); EMR (m5.xlarge, m5.2xlarge, m5.4xlarge); Redshift RA3 (ra3.large, ra3.xlplus, ra3.4xlarge, ra3.16xlarge); S3 (Standard) | confluent: Confluent Cloud Dedicated (CKU); Confluent Cloud Standard (eCKU); Confluent Cloud Enterprise (eCKU) | databricks: Databricks cluster (AWS) (m5.xlarge, m5.2xlarge, m5.4xlarge) | gcp: Dataproc (n2-standard-4, n2-standard-8, n2-standard-16); BigQuery (slots); Cloud Storage (Standard) | snowflake: Snowflake warehouse (X-Small, Small, Medium, Large, X-Large, 2X-Large, 3X-Large, 4X-Large) | azure: ADLS Gen2 (Standard).",
          "oneOf": [
            {
              "type": "object",
              "required": [
                "kind",
                "provider",
                "service",
                "size",
                "count"
              ],
              "additionalProperties": false,
              "properties": {
                "kind": {
                  "const": "managed"
                },
                "provider": {
                  "enum": [
                    "aws",
                    "confluent",
                    "databricks",
                    "gcp",
                    "snowflake",
                    "azure"
                  ]
                },
                "service": {
                  "type": "string"
                },
                "size": {
                  "type": "string"
                },
                "count": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 1000,
                  "description": "Number of units (brokers, shards, nodes, warehouses...)."
                },
                "activeHoursPerDay": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 24,
                  "description": "Hours per day the compute runs and is billed (0-24). Omit for always-on; set it for nightly clusters and auto-suspending warehouses."
                }
              }
            },
            {
              "type": "object",
              "required": [
                "kind",
                "vcpu",
                "memGiB",
                "disk",
                "diskGiB",
                "netGbps",
                "instances"
              ],
              "additionalProperties": false,
              "properties": {
                "kind": {
                  "const": "self-hosted"
                },
                "vcpu": {
                  "type": "number",
                  "minimum": 0.25,
                  "maximum": 448
                },
                "memGiB": {
                  "type": "number",
                  "minimum": 0.5,
                  "maximum": 24576
                },
                "disk": {
                  "enum": [
                    "nvme",
                    "ssd",
                    "hdd",
                    "object"
                  ]
                },
                "diskGiB": {
                  "type": "number",
                  "minimum": 1,
                  "maximum": 1048576
                },
                "netGbps": {
                  "type": "number",
                  "minimum": 0.001,
                  "maximum": 400
                },
                "instances": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 10000
                },
                "activeHoursPerDay": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 24,
                  "description": "Hours per day the compute runs and is billed (0-24). Omit for always-on; set it for nightly clusters and auto-suspending warehouses."
                }
              }
            }
          ]
        },
        "costUsdPerHour": {
          "type": "number",
          "minimum": 0,
          "description": "Your own measured compute price in USD per hour; replaces the price-table estimate (shown as measured)."
        }
      }
    },
    "flow": {
      "type": "object",
      "required": [
        "from",
        "to"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 64
        },
        "from": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.:-]+$",
          "minLength": 1,
          "maxLength": 64
        },
        "to": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.:-]+$",
          "minLength": 1,
          "maxLength": 64
        },
        "mode": {
          "enum": [
            "stream",
            "batch",
            "cdc"
          ],
          "description": "Inferred from the endpoints when omitted."
        },
        "kind": {
          "enum": [
            "data",
            "control",
            "metadata"
          ],
          "description": "control = orchestration trigger, carries no data. metadata = governance link from a pipeline component to a schema_registry, catalog or data_quality component; no rate, mode or schedule."
        },
        "eventsPerSec": {
          "type": "number",
          "minimum": 0,
          "description": "stream/cdc throughput."
        },
        "recordsPerRun": {
          "type": "number",
          "minimum": 0,
          "description": "batch volume per run."
        },
        "schedule": {
          "type": "string",
          "maxLength": 100,
          "description": "Cron, e.g. 0 * * * *"
        },
        "latencyMs": {
          "type": "number",
          "minimum": 0
        },
        "bytesPerRecord": {
          "type": "number",
          "minimum": 0
        },
        "errorRate": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "dlqTarget": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.:-]+$",
          "minLength": 1,
          "maxLength": 64,
          "description": "Component id (a dlq) receiving failed records. Pair with errorRate and one flow from the failing stage to that dlq."
        },
        "ordering": {
          "enum": [
            "none",
            "per-key",
            "global"
          ]
        },
        "delivery": {
          "enum": [
            "at-most-once",
            "at-least-once",
            "exactly-once"
          ]
        },
        "schema": {
          "type": "string",
          "maxLength": 80
        }
      }
    }
  }
}
