{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://nanosaas.ai/schema/nanospec.json",
  "title": "NanoSpec",
  "description": "Declarative specification for a NanoApp on the NanoSaaS platform. NanoSpec defines what a micro-application does — inputs, outputs, auth, pricing, delivery type, and trust requirements. The platform generates, audits, and deploys the code from this spec. Cross-field validation rules (not expressible in JSON Schema): hosted NanoApps require ui_type and at least one output; download NanoApps require artifact config and must not declare capabilities, ui, or api config; domain category requires subcategory; per_use pricing requires per_use_usd >= $0.10; subscription pricing requires subscription_usd; domain_sensitive trust tier disallows auth type 'none'; PHI data sensitivity requires domain_sensitive trust tier.",
  "$ref": "#/definitions/NanoSpec",
  "definitions": {
    "NanoSpec": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64,
          "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
        },
        "version": {
          "type": "string",
          "pattern": "^\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9.]+)?$"
        },
        "description": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1000
        },
        "tagline": {
          "type": "string",
          "maxLength": 80
        },
        "category": {
          "type": "string",
          "enum": [
            "auth",
            "data",
            "ui",
            "ai",
            "integration",
            "domain",
            "infra"
          ]
        },
        "subcategory": {
          "type": "string"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "maxItems": 8
        },
        "delivery_type": {
          "type": "string",
          "enum": [
            "hosted",
            "download"
          ],
          "default": "hosted"
        },
        "ui_type": {
          "type": "string",
          "enum": [
            "page",
            "widget",
            "api_only",
            "headless"
          ]
        },
        "versioning": {
          "type": "string",
          "enum": [
            "rolling",
            "immutable"
          ]
        },
        "auth": {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "nanosass_session",
                "api_key",
                "none"
              ]
            },
            "scope": {
              "type": "string",
              "enum": [
                "user",
                "org",
                "global"
              ],
              "default": "user"
            },
            "mfa_required": {
              "type": "boolean",
              "default": false
            }
          },
          "required": [
            "type"
          ],
          "additionalProperties": false
        },
        "inputs": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1
              },
              "type": {
                "type": "string",
                "enum": [
                  "string",
                  "number",
                  "boolean",
                  "object",
                  "array",
                  "file"
                ]
              },
              "required": {
                "type": "boolean",
                "default": true
              },
              "description": {
                "type": "string"
              },
              "default": {},
              "validation": {
                "type": "object",
                "properties": {
                  "min_length": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "max_length": {
                    "type": "integer",
                    "exclusiveMinimum": 0
                  },
                  "pattern": {
                    "type": "string"
                  },
                  "enum": {
                    "type": "array",
                    "items": {
                      "type": [
                        "string",
                        "number"
                      ]
                    }
                  },
                  "minimum": {
                    "type": "number"
                  },
                  "maximum": {
                    "type": "number"
                  },
                  "min_items": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "max_items": {
                    "type": "integer",
                    "exclusiveMinimum": 0
                  },
                  "required_keys": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "max_size_bytes": {
                    "type": "integer",
                    "exclusiveMinimum": 0
                  },
                  "allowed_types": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "additionalProperties": false
              },
              "schema": {
                "type": "object",
                "additionalProperties": {}
              }
            },
            "required": [
              "name",
              "type"
            ],
            "additionalProperties": false
          },
          "minItems": 0
        },
        "outputs": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1
              },
              "type": {
                "type": "string",
                "enum": [
                  "string",
                  "number",
                  "boolean",
                  "object",
                  "array",
                  "file"
                ]
              },
              "description": {
                "type": "string"
              },
              "nullable": {
                "type": "boolean",
                "default": false
              }
            },
            "required": [
              "name",
              "type"
            ],
            "additionalProperties": false
          },
          "minItems": 0
        },
        "capabilities": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "external_api",
              "persistent_storage",
              "email",
              "internet"
            ]
          }
        },
        "trust_tier": {
          "type": "string",
          "enum": [
            "standard",
            "elevated",
            "domain_sensitive"
          ]
        },
        "data_sensitivity": {
          "type": "string",
          "enum": [
            "none",
            "pii",
            "phi"
          ],
          "default": "none"
        },
        "pricing": {
          "type": "object",
          "properties": {
            "model": {
              "type": "string",
              "enum": [
                "per_use",
                "subscription",
                "free"
              ]
            },
            "per_use_usd": {
              "type": "number"
            },
            "subscription_usd": {
              "type": "number"
            },
            "free_tier": {
              "type": "object",
              "properties": {
                "requests_per_day": {
                  "type": "integer",
                  "exclusiveMinimum": 0
                }
              },
              "required": [
                "requests_per_day"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "model"
          ],
          "additionalProperties": false
        },
        "dependencies": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "model_hint": {
          "type": "string"
        },
        "runtime": {
          "type": "string",
          "enum": [
            "js",
            "python"
          ],
          "default": "js"
        },
        "ui": {
          "type": "object",
          "properties": {
            "title": {
              "type": "string"
            },
            "theme": {
              "type": "string",
              "enum": [
                "light",
                "dark",
                "auto"
              ],
              "default": "auto"
            },
            "responsive": {
              "type": "boolean",
              "default": true
            },
            "embed_allowed": {
              "type": "boolean",
              "default": true
            }
          },
          "additionalProperties": false
        },
        "api": {
          "type": "object",
          "properties": {
            "base_path": {
              "type": "string",
              "default": "/v1"
            },
            "rate_limit": {
              "type": "object",
              "properties": {
                "requests_per_minute": {
                  "type": "integer",
                  "exclusiveMinimum": 0
                }
              },
              "required": [
                "requests_per_minute"
              ],
              "additionalProperties": false
            },
            "timeout_ms": {
              "type": "integer",
              "exclusiveMinimum": 0,
              "default": 10000
            },
            "streaming": {
              "type": "boolean",
              "default": false
            }
          },
          "additionalProperties": false
        },
        "artifact": {
          "type": "object",
          "properties": {
            "format": {
              "type": "string",
              "enum": [
                "markdown",
                "component",
                "template",
                "bundle"
              ]
            },
            "files": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "language": {
              "type": "string"
            },
            "framework": {
              "type": "string"
            }
          },
          "required": [
            "format"
          ],
          "additionalProperties": false
        },
        "created_at": {
          "type": "string"
        },
        "published_at": {
          "type": "string"
        },
        "creator_slug": {
          "type": "string"
        },
        "analysis_score": {}
      },
      "required": [
        "name",
        "version",
        "description",
        "category",
        "auth",
        "inputs",
        "outputs",
        "trust_tier",
        "pricing"
      ],
      "additionalProperties": false
    }
  }
}
