{
  "openapi": "3.1.1",
  "info": {
    "title": "Room Layout Optimizer API",
    "version": "1.0.0",
    "summary": "Auto-arrange furniture in a room around doors, windows and a clear walkway.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://roomlayoutoptimizer.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Auto-arrange furniture in a room around doors, windows and a clear walkway.",
        "description": "Give the room size, doors, windows and your furniture with the clearance each piece needs. A deterministic grid search places everything inside the room without overlaps, keeps door swings and a walkway clear, prefers walls and windows where requested and returns coordinates plus a text floor plan.\n\nMethodology:\n- The room is rasterised into grid cells (default 10 cm); furniture sizes, clearances and door zones are rounded up to whole cells, the room size down.\n- Each door gets a keep-clear square (door width × door width) inside the room in front of it, approximating the quarter-circle swing.\n- Each item can face any of the 4 directions; its body must lie inside the room and not overlap other bodies, other clearance zones or door squares; its front clearance zone must lie inside the room and not overlap bodies. \"Back against wall\" items must touch the wall behind them.\n- Walkway: the free floor is eroded by a square of the walkway width; squares connected to a door square form the reachable walkway. Every item’s clearance zone (or the cell strip in front of it) must touch that walkway.\n- Search: items are placed largest-area first with a beam search (4 partial layouts kept). For each layout, every valid grid position is pre-scored (wall hugging, corner use, distance to the nearest window for \"prefer near window\" items); the 25 best are checked for walkway access and scored.\n- Score = 1000 × items placed + 10 × reachable walkway m² + 2 per wall item in a corner − 3 × distance (m) of free-standing items from the nearest wall − 5 × distance (m) from window-loving items to the nearest window. Ties break by input order, then north-to-south, west-to-east position.\n\nRectangles only; radiators, sockets, sloped ceilings and personal taste are not considered. Treat the result as a starting point.",
        "tags": [
          "home-travel"
        ],
        "x-mcp-tool": "room_layout_optimizer",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RoomLayoutOptimizerInput"
              },
              "examples": {
                "example1": {
                  "summary": "Bedroom with desk by the window",
                  "value": {
                    "roomWidth": 400,
                    "roomDepth": 350,
                    "gridCm": 10,
                    "walkwayCm": 60,
                    "openings": [
                      {
                        "kind": "door",
                        "wall": "south",
                        "offset": 20,
                        "width": 80
                      },
                      {
                        "kind": "window",
                        "wall": "north",
                        "offset": 150,
                        "width": 120
                      }
                    ],
                    "furniture": [
                      {
                        "name": "Double bed",
                        "width": 160,
                        "depth": 200,
                        "needsWall": true,
                        "clearanceFront": 60,
                        "nearWindow": false
                      },
                      {
                        "name": "Wardrobe",
                        "width": 150,
                        "depth": 60,
                        "needsWall": true,
                        "clearanceFront": 70,
                        "nearWindow": false
                      },
                      {
                        "name": "Desk",
                        "width": 120,
                        "depth": 60,
                        "needsWall": true,
                        "clearanceFront": 70,
                        "nearWindow": true
                      }
                    ]
                  }
                },
                "example2": {
                  "summary": "Living room",
                  "value": {
                    "roomWidth": 500,
                    "roomDepth": 420,
                    "gridCm": 10,
                    "walkwayCm": 70,
                    "openings": [
                      {
                        "kind": "door",
                        "wall": "west",
                        "offset": 30,
                        "width": 90
                      },
                      {
                        "kind": "window",
                        "wall": "east",
                        "offset": 120,
                        "width": 180
                      }
                    ],
                    "furniture": [
                      {
                        "name": "Sofa",
                        "width": 220,
                        "depth": 95,
                        "needsWall": true,
                        "clearanceFront": 80,
                        "nearWindow": false
                      },
                      {
                        "name": "TV unit",
                        "width": 180,
                        "depth": 45,
                        "needsWall": true,
                        "clearanceFront": 50,
                        "nearWindow": false
                      },
                      {
                        "name": "Armchair",
                        "width": 85,
                        "depth": 85,
                        "needsWall": false,
                        "clearanceFront": 50,
                        "nearWindow": true
                      },
                      {
                        "name": "Bookshelf",
                        "width": 100,
                        "depth": 35,
                        "needsWall": true,
                        "clearanceFront": 50,
                        "nearWindow": false
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RoomLayoutOptimizerResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "RoomLayoutOptimizerInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "roomWidth": {
            "title": "Room width (west → east)",
            "type": "number",
            "minimum": 100,
            "maximum": 2000,
            "x-unit": "cm"
          },
          "roomDepth": {
            "title": "Room depth (north → south)",
            "type": "number",
            "minimum": 100,
            "maximum": 2000,
            "x-unit": "cm"
          },
          "gridCm": {
            "title": "Grid size",
            "description": "Positions snap to this grid; furniture sizes are rounded up to it.",
            "type": "integer",
            "minimum": 5,
            "maximum": 50,
            "default": 10,
            "x-unit": "cm"
          },
          "walkwayCm": {
            "title": "Minimum walkway width",
            "type": "integer",
            "minimum": 30,
            "maximum": 150,
            "default": 60,
            "x-unit": "cm"
          },
          "openings": {
            "title": "Doors and windows",
            "description": "Offset is measured along the wall from its west end (north/south walls) or north end (east/west walls).",
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "kind": {
                  "title": "Type",
                  "type": "string",
                  "enum": [
                    "door",
                    "window"
                  ]
                },
                "wall": {
                  "title": "Wall",
                  "type": "string",
                  "enum": [
                    "north",
                    "east",
                    "south",
                    "west"
                  ]
                },
                "offset": {
                  "title": "Offset",
                  "type": "number",
                  "minimum": 0,
                  "x-unit": "cm"
                },
                "width": {
                  "title": "Width",
                  "type": "number",
                  "minimum": 30,
                  "maximum": 500,
                  "x-unit": "cm"
                }
              },
              "required": [
                "kind",
                "wall",
                "offset",
                "width"
              ]
            }
          },
          "furniture": {
            "title": "Furniture",
            "description": "Width = side along its back; depth = front to back. Clearance = free space needed in front (to open drawers, get into bed, sit).",
            "type": "array",
            "minItems": 1,
            "maxItems": 15,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "name": {
                  "title": "Name",
                  "type": "string",
                  "maxLength": 40
                },
                "width": {
                  "title": "Width",
                  "type": "number",
                  "minimum": 10,
                  "maximum": 1000,
                  "x-unit": "cm"
                },
                "depth": {
                  "title": "Depth",
                  "type": "number",
                  "minimum": 10,
                  "maximum": 1000,
                  "x-unit": "cm"
                },
                "needsWall": {
                  "title": "Back against wall",
                  "type": "boolean",
                  "default": true
                },
                "clearanceFront": {
                  "title": "Clearance in front",
                  "type": "number",
                  "minimum": 0,
                  "maximum": 300,
                  "default": 60,
                  "x-unit": "cm"
                },
                "nearWindow": {
                  "title": "Prefer near window",
                  "type": "boolean",
                  "default": false
                }
              },
              "required": [
                "name",
                "width",
                "depth"
              ]
            }
          }
        },
        "required": [
          "roomWidth",
          "roomDepth",
          "furniture"
        ]
      },
      "RoomLayoutOptimizerResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "roomWidthCm",
              "roomDepthCm",
              "gridCm",
              "placed",
              "unplaced",
              "walkwayAreaM2",
              "freeFloorAreaM2",
              "score"
            ],
            "properties": {
              "roomWidthCm": {
                "type": "number"
              },
              "roomDepthCm": {
                "type": "number"
              },
              "gridCm": {
                "type": "integer"
              },
              "placed": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "label",
                    "name",
                    "xCm",
                    "yCm",
                    "sizeXCm",
                    "sizeYCm",
                    "facing",
                    "againstWall",
                    "accessible"
                  ],
                  "properties": {
                    "label": {
                      "type": "string",
                      "description": "Letter used in the text plan."
                    },
                    "name": {
                      "type": "string"
                    },
                    "xCm": {
                      "type": "number",
                      "description": "Distance of the item’s west edge from the west wall."
                    },
                    "yCm": {
                      "type": "number",
                      "description": "Distance of the item’s north edge from the north wall."
                    },
                    "sizeXCm": {
                      "type": "number"
                    },
                    "sizeYCm": {
                      "type": "number"
                    },
                    "facing": {
                      "type": "string",
                      "enum": [
                        "north",
                        "east",
                        "south",
                        "west"
                      ],
                      "description": "Direction the front of the item faces."
                    },
                    "againstWall": {
                      "type": "string",
                      "enum": [
                        "north",
                        "east",
                        "south",
                        "west",
                        "none"
                      ]
                    },
                    "accessible": {
                      "type": "boolean"
                    }
                  }
                }
              },
              "unplaced": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "name",
                    "reason"
                  ],
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "reason": {
                      "type": "string"
                    }
                  }
                }
              },
              "walkwayAreaM2": {
                "type": "number",
                "minimum": 0
              },
              "freeFloorAreaM2": {
                "type": "number",
                "minimum": 0
              },
              "score": {
                "type": "number"
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}