← Recipes

A Vastu floor-plan check: from a listing's layout to a score

One endpoint scores a layout, but it only understands compass zones measured from the centre of the space. Floor plans and property listings speak in "front-left bedroom". Most of this recipe is the translation step, plus the two fields that are easy to get subtly wrong.

You build
A 0-100 Vastu alignment score with flagged doshas, their sources and remedies, from a room layout.
Code
Node.js, Python - no SDK, runnable as shown

Updated

The request, field by field

FieldValuesTrap
facingN, NE, E, SE, S, SW, W, NWAbbreviations only - "East" is a 400. It is the direction the main facade faces, not where the road is on the plan.
kindhome, apartment, plot, office, shopRequired.
zonesZone → list of rooms (entrance, kitchen, pooja, toilet, master_bedroom, …)Keys are compass zones plus center. Any other key is a 400 VALIDATION_ERROR naming it, and at least one zone must hold a room.
doorPosition1 to 8 along the facing wallOptional. 1 and 8 are the corners and are flagged; the middle positions are the classical ideal.

POST /v1/vastu/analyze is on the Free plan and needs no birth data or location - just the description of the space.

Node: analyse, and catch the unmapped plan

javascript
// vastu.mjs - Node 18+, server-side.
const API = "https://api.astronode.dev";

const analyze = async (layout) => {
  const res = await fetch(`${API}/v1/vastu/analyze`, {
    method: "POST",
    headers: { authorization: `Bearer ${process.env.ASTRONODE_API_KEY}`, "content-type": "application/json" },
    body: JSON.stringify(layout),
  });
  return { status: res.status, body: await res.json() };
};

// The floor plan, already mapped to compass zones (see "Map the plan first").
const layout = {
  facing: "N",
  kind: "apartment",
  doorPosition: 1, // 1-8 along the facing wall; 1 and 8 are the corners
  zones: {
    N: ["entrance", "living"],
    NE: ["kitchen"],
    SE: ["toilet"],
    SW: ["master_bedroom"],
    NW: ["bedroom"],
    W: ["dining"],
  },
};

const { body } = await analyze(layout);
const { data } = body;
console.log("score", data.alignment.score, "|", body.interpretation.summary);
for (const d of data.doshas) {
  console.log(`[${d.severity}] ${d.zone} ${d.title} - ${d.source} (${d.tier})`);
  console.log(`    ${d.remedies.length} remedies, first: ${d.remedies[0].text}`);
}
for (const z of data.zones.filter((z) => z.status === "misaligned")) console.log(`zone ${z.zone}: ${z.note}`);

// A listing-style key is rejected, and the 400 names it - surface it to whoever drew the plan.
const bad = await analyze({ facing: "N", kind: "apartment", zones: { "front-left": ["kitchen"] } });
console.log(bad.status, bad.body.error.code, bad.body.error.details.map((d) => d.message));
text
$ node vastu.mjs
score 25 | Vastu alignment: 25/100 - 2 doshas detected (1 major).
[major] NE Fire in the NE - element convention (NE = water/Īśāna) (web)
    5 remedies, first: Favour a water element (a small clean water feature) and openness in the NE.
[minor] center Main door at a corner position - Bṛhat Saṃhitā 53 vv.72–75 (primary)
    3 remedies, first: Favour a mid-side position for the main door rather than a corner.
zone NE: Kitchen (fire) clashes with the NE; Fire in the NE (major dosha).
zone SE: Toilet (water) sits poorly in SE.
400 VALIDATION_ERROR [ 'Unrecognized key: "front-left"' ]

The second call is the mistake this recipe exists to prevent: a plan that was never mapped to the compass. The API refuses it with 400 VALIDATION_ERROR and error.details[].message names the offending key (Unrecognized key: "front-left"), so pass that message back to whoever drew the plan. 400s are not billed. Note also that a zone holding a major dosha is reported as misaligned, and its note names the dosha.

Python: map "front-left" to a compass zone

Stand inside, looking out through the front. With the front facing east, your left is north, so front-left is north-east. Rotating an eight-point compass by the facing direction does this for every relative label:

Python 3.9+
# vastu_map.py - Python 3.9+, standard library only.
# Listings say "front-left"; the API wants compass zones. Rotate first.
import json, os, urllib.request

API = "https://api.astronode.dev"
KEY = os.environ["ASTRONODE_API_KEY"]

COMPASS = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
# Steps of 45 degrees clockwise from "front", standing inside and facing out.
RELATIVE = {"front": 0, "front-right": 1, "right": 2, "back-right": 3,
            "back": 4, "back-left": 5, "left": 6, "front-left": 7}

def to_compass(facing, relative):
    if relative == "center":
        return "center"
    return COMPASS[(COMPASS.index(facing) + RELATIVE[relative]) % 8]

facing = "E"
plan = {"front": ["entrance"], "front-left": ["pooja"], "front-right": ["kitchen"],
        "back-right": ["master_bedroom"], "back-left": ["toilet"]}
zones = {}
for rel, rooms in plan.items():
    zones.setdefault(to_compass(facing, rel), []).extend(rooms)
print(zones)

req = urllib.request.Request(
    API + "/v1/vastu/analyze",
    data=json.dumps({"facing": facing, "kind": "home", "doorPosition": 4, "zones": zones}).encode(),
    headers={"Authorization": "Bearer " + KEY, "Content-Type": "application/json"},
)
data = json.load(urllib.request.urlopen(req))["data"]
print("score", data["alignment"]["score"], "| doshas:", [d["id"] for d in data["doshas"]])
text
$ python3 vastu_map.py
{'E': ['entrance'], 'NE': ['pooja'], 'SE': ['kitchen'], 'SW': ['master_bedroom'], 'NW': ['toilet']}
score 100 | doshas: []

Rendering the result

  • Lead with alignment.score and doshas; each dosha has a severity (major / minor), a zone, a reason and its own remedies. The top-level remedies array is the same remedies flattened, for a single checklist.
  • Show the source and tier: primary means a classical text (for example *Bṛhat Saṃhitā* 53), web means a widely used convention. Users and consultants care about the difference.
  • A layout with no rooms at all (zones omitted, {} or only empty lists) is a 400 - "at least one room/zone is required" - not a score. A sparse layout does get a score, so decide how many placed rooms your product needs before showing one.
  • Zone status agrees with the doshas: a zone carrying a major dosha is misaligned, a minor one at best neutral. Colour zones from status and explain them with note.
  • meta.disclaimer is written for display. Vastu is a traditional design system, and the API says so; keep that sentence next to the score.

Questions

What do I end up with?
A 0-100 Vastu alignment score with flagged doshas, their sources and remedies, from a room layout. The code is in Node.js and Python.
Which endpoints does this recipe call, and in what order?
1 endpoint, in this order: Vastu Analysis (POST /v1/vastu/analyze).

In the API

Endpoints this recipe calls

  1. Vastu Analysis APIPOST /v1/vastu/analyze