{
  "openapi": "3.1.0",
  "info": {
    "title": "Northbridge Workflow Analysis API",
    "version": "1.0",
    "description": "Programmatic workflow and automation-readiness analysis for business applications and internal tools.",
    "contact": {
      "name": "Northbridge Software LLC",
      "url": "https://nbsoftware.net",
      "email": "support@nbsoftware.net"
    }
  },
  "servers": [
    {
      "url": "https://nbsoftware.net"
    }
  ],
  "externalDocs": {
    "url": "https://nbsoftware.net/developers/workflow-analysis-api"
  },
  "paths": {
    "/api/v1/health": {
      "get": {
        "summary": "Health check",
        "operationId": "getHealth",
        "security": [],
        "responses": {
          "200": {
            "description": "Service is available",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/workflow-analysis": {
      "post": {
        "summary": "Analyze a workflow",
        "operationId": "analyzeWorkflow",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WorkflowAnalysisRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Analysis result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkflowAnalysisResponse"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON or validation failure (codes INVALID_JSON, INVALID_REQUEST)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key (MISSING_API_KEY)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Invalid, disabled or revoked API key (INVALID_API_KEY)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed (METHOD_NOT_ALLOWED)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Request body larger than 32 KB (PAYLOAD_TOO_LARGE)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (RATE_LIMIT_EXCEEDED)",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds until retry"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (INTERNAL_ERROR)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key in the form nb_live_..."
      }
    },
    "schemas": {
      "Health": {
        "type": "object",
        "required": [
          "status",
          "service",
          "version"
        ],
        "properties": {
          "status": {
            "type": "string",
            "const": "ok"
          },
          "service": {
            "type": "string"
          },
          "version": {
            "type": "string"
          }
        }
      },
      "WorkflowAnalysisRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "workflow_name",
          "description"
        ],
        "properties": {
          "workflow_name": {
            "type": "string",
            "minLength": 2,
            "maxLength": 120
          },
          "description": {
            "type": "string",
            "minLength": 20,
            "maxLength": 5000
          },
          "monthly_volume": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000000
          },
          "current_tools": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "type": "string",
              "maxLength": 100
            }
          },
          "manual_steps": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1000
          },
          "business_goal": {
            "type": "string",
            "maxLength": 1000
          }
        }
      },
      "Recommendation": {
        "type": "object",
        "required": [
          "title",
          "category",
          "priority"
        ],
        "properties": {
          "title": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "priority": {
            "type": "string",
            "enum": [
              "high",
              "medium",
              "low"
            ]
          }
        }
      },
      "WorkflowAnalysisResponse": {
        "type": "object",
        "required": [
          "request_id",
          "workflow_name",
          "automation_score",
          "complexity",
          "summary",
          "bottlenecks",
          "recommendations",
          "estimated_manual_steps_removed",
          "integration_opportunities",
          "generated_at"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "pattern": "^wa_"
          },
          "workflow_name": {
            "type": "string"
          },
          "automation_score": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "complexity": {
            "type": "string",
            "enum": [
              "low",
              "medium",
              "high"
            ]
          },
          "summary": {
            "type": "string"
          },
          "bottlenecks": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "recommendations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Recommendation"
            }
          },
          "estimated_manual_steps_removed": {
            "type": "integer",
            "minimum": 0
          },
          "integration_opportunities": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}