Astrology9 MIN READ19 / 31

Matching Engine — High-Level Design

Status: Draft for review · Part of: Astro Composer · Updated: 2026-10-24

The matching engine evaluates ashtakoota (eight-factor compatibility) for two charts: eight kootas, thirty-six points, the doshas (faults) they imply and the cancellation rules the rulebook chooses. It is pure table evaluation over two sets of Moon facts: no astronomy, no binder call, no interpretation.

1. Purpose

Ashtakoota looks like eight table lookups plus a total, but the total is the least trustworthy part. Three things complicate it:

  • Several schools cancel Nadi and Bhakoot doshas under named conditions.
  • Varna, Vashya and Tara are computed in a direction, so pair order changes the result.
  • 18 of 36 is a traditional threshold, not a verdict on two people.

The matching engine exists so that:

  1. the eight kootas run once, in fixed order, from one rulebook;
  2. every koota returns points, basis and verdict, not just a total;
  3. doshas and cancellations stay visible;
  4. the pair direction is explicit, because order-sensitive kootas change the result;
  5. two charts are matched only under the same conventions.

2. Where it sits

subject A · Moon sign/nakshatra/pada ──┐
subject B · Moon sign/nakshatra/pada ──┼──▶ matching engine ──▶ eight kootas + doshas + total
pair direction · profile · rulebook ───┘
  • Upstream: the composition facade supplies two compact subject references, the pair direction, one profile and one rulebook handle. Each subject comes from a verified chart core chart or a stored composer snapshot; the engine reads neither birth data nor the binder.
  • Downstream: the facade builds POST /v1/matching; the product renders points and doshas in its own words, and the chart/account domain may store the response as an immutable report snapshot.
  • Never: it does not compute a natal chart, call the binder, recompute a nakshatra from a longitude, read a clock, or decide whether two people should marry.

Input contract

Input Source Used for
Subject A facts Stored composer snapshot or chart core Moon sign, Moon nakshatra, Moon pada
Subject B facts Stored composer snapshot or chart core Moon sign, Moon nakshatra, Moon pada
Reference versions Each subject’s chart metadata Profile, rulebook hash and binder engine equality
Pair direction Request Which subject is scored against which for ordered kootas
Profile Request One sidereal convention for both subjects
Rulebook handle Registry Koota matrices, class maps, friendship, cancellations
Traditional threshold Rulebook or profile Echoed as 18 of 36; never a per-request override

Output contract

Output Shape Read by
pair Subject ids, direction and reference versions Response and audit
kootas[] Id, max points, points, verdict, basis and cancellation Response, product report
total Exact points, maximum 36, threshold and meetsTraditionalThreshold Response, product report
doshas[] Id, koota, present, cancelled, rule id and affected facts Response, product report
threshold Traditional threshold and its source Audit and fixtures
diagnostics Missing facts, unsupported profile, inconsistent subject Facade errors

3. Responsibilities

Each area owns one compatibility factor and one deterministic rule.

Area Owns Deterministic rule
Subject admission Required Moon facts and version equality Same profile, rulebook and binder; valid sign/nakshatra pair
Varna Moon-sign class and pair order Rulebook class order; ordered pair
Vashya Sign group and attraction Rulebook group table; ordered pair
Tara Nakshatra count between the two Moons ((B − A) mod 27) + 1; rulebook remainder band
Yoni Nakshatra animal symbol Rulebook 14×14 compatibility matrix
Graha Maitri Sign lords and friendship Rulebook natural friendship; compound only if enabled
Gana Deva, manushya or rakshasa class Rulebook 3×3 matrix
Bhakoot Moon-sign distance Rulebook distance table; direction-independent
Nadi Nakshatra nadi class Rulebook class map; cancellation predicates
Dosha resolver Nadi and Bhakoot doshas and cancellations Named predicates; a cancelled dosha stays visible
Score assembler Exact total and threshold comparison Scaled integer or decimal; maxima sum to 36

Koota ledger

Koota Max Facts used Rulebook table
Varna 1 Moon-sign class of both subjects Class order and direction
Vashya 2 Moon sign and group of both subjects Group and attraction table
Tara 3 Nakshatra count from subject to partner Remainder bands
Yoni 4 Nakshatra animal symbol of both subjects 14×14 matrix
Graha Maitri 5 Moon-sign lords and friendship Natural friendship table
Gana 6 Nakshatra class of both subjects 3×3 matrix
Bhakoot 7 Moon-sign distance Distance and dosha table
Nadi 8 Nakshatra nadi class of both subjects Class map and cancellation predicates

4. Architecture

Matching Engine — High-Level Design Eight kootas, thirty-six points and explicit doshas over two verified Moon-fact references. Reference design, not deployed behaviour. Matching Engine — High-Level Design Eight kootas, thirty-six points and explicit doshas over two verified Moon-fact references. Subject A · Moon facts sign · nakshatra · pada from stored chart snapshot Subject B · Moon facts sign · nakshatra · pada same convention as A Pair order + profile subject → partner direction threshold 18/36 echoed Matching engine · pure koota tables over two charts Subject admission version equality · required facts sign/nakshatra consistency Varna + Vashya Moon-sign class and group ordered-pair tables Tara + Yoni nakshatra count · animal remainder and 14×14 matrix Graha Maitri + Gana sign lords · class matrix friendship table Bhakoot + Nadi sign distance · nadi class dosha predicates Dosha + score cancellations stay visible exact total · 36 maximum Eight kootas in fixed order; points are facts, not a verdict. A cancelled dosha remains in the response with its rule id. Rulebook · koota registry Koota tables varna · vashya · tara · yoni gana · bhakoot · nadi Friendship + class maps sign lords · natural friendship yoni · gana · nadi · varna Cancellation rules named predicates per dosha no implicit exceptions Load gate: maxima sum to 36. Every koota table is read-only. Match layer · facade eight kootas · doshas · total profile · rulebook · versions Product match report points and doshas only no recommendation copy Chart/account domain stores the response snapshot immutable revision subject A subject B conventions tables + limits kootas + doshas report snapshot dependency pure module engine output boundary No binder call: both charts arrive as verified Moon facts.

Diagram: reference design, not deployed behaviour.

The engine is a table evaluator with an admission gate. Once both subjects pass, every koota reads the same facts and rulebook, so the total can disagree with its parts only through an assembler defect.

5. Rules

  1. Matching compares facts, not charts. The engine reads Moon sign, nakshatra and pada; never a longitude, house, aspect or dasha period.
  2. Same conventions on both sides. Both subjects must share profile version, rulebook hash and binder engine version; a cross-convention pair gets REFERENCE_VERSION_MISMATCH.
  3. The pair has a direction. Ordered kootas score A against B, and the response echoes that direction; a reverse request is a different evaluation.
  4. Only Moon facts are required. Sign, nakshatra and pada cover all eight kootas; pada enters only where a cancellation rule needs it.
  5. The binder owns nakshatra. The engine never recomputes a nakshatra or pada from a longitude; a fact disagreeing with its sign span fails admission.
  6. Koota tables are rulebook data. Every matrix, class order and remainder band is a table row. Maxima must sum to 36 and each table must cover its domain at load.
  7. Exact arithmetic. Points are exact decimals or scaled integers; a total is never a float sum of eight rounded parts.
  8. Every koota is returned. All eight carry points, maximum, verdict and basis; collapsing to one score is a product choice.
  9. Doshas are explicit. Nadi and Bhakoot carry present, cancelled and the deciding rule id; a cancelled dosha stays in the response.
  10. Eighteen is a threshold, not a verdict. meetsTraditionalThreshold compares against the pinned threshold; the engine does not rank or recommend.
  11. Graha Maitri is pinned. Natural friendship is the default; compound friendship needs temporal friendship and is a rulebook option.
  12. Cancellations are named predicates. No exception is hardcoded; a rulebook without a cancellation table yields cancelled: false.
  13. Mangal dosha is not in this slice. It needs Mars and a different fact set, so it belongs to a separate dosha pack.
  14. Deterministic order and ids. Kootas run varna, vashya, tara, yoni, graha maitri, gana, bhakoot, nadi; identical requests give byte-identical output.
  15. No clock, no binder, no storage. The engine is a pure function of two admitted subjects and one rulebook; caching and report storage belong elsewhere.
  16. Privacy is part of the contract. The response carries Moon facts and scores, never birth dates or coordinates; cache keys are hashed and bodies are not logged.

6. Edge cases

Bad input fails loudly; nothing is silently corrected.

Case Behaviour
The same chart is used for both subjects Valid; Nadi is same-class and the normal tables apply
Subjects from different profiles or rulebooks REFERENCE_VERSION_MISMATCH; no silent reconciliation
Subjects from different binder engine versions REFERENCE_VERSION_MISMATCH; recompute both before matching
Tropical profile LAYER_UNSUPPORTED; ashtakoota needs sidereal nakshatras
Missing Moon nakshatra in a sidereal chart INSUFFICIENT_INPUT
Sign and nakshatra do not intersect INSUFFICIENT_INPUT; no silent correction
Pada outside 1–4 INSUFFICIENT_INPUT; no default pada
Pair order reversed Ordered kootas may change points; the response echoes the new direction
Nadi is the same and a cancellation applies Zero Nadi points, dosha cancelled: true and the rule id
Nadi is the same and no cancellation table exists Zero Nadi points, cancelled: false; no guessed exception
Bhakoot is a 2–12, 5–9 or 6–8 distance Dosha reported; any cancellation is evaluated separately
Gana is rakshasa against deva Rulebook matrix decides; no hardcoded zero
Unknown yoni, gana or nadi id Rulebook load or request admission fails; never a default
Maxima do not sum to 36 Startup failure; no match is served under a broken table
A table yields points outside 0..max Rulebook load failure, not clamping
Fractional points are configured Exact decimal arithmetic preserves them and the total
Total is exactly 18 meetsTraditionalThreshold: true; no rounding decides it
Total is high but a dosha is present Both facts are returned; neither overrides the other
Both subjects are identical Valid evaluation; no special-case score
A cancellation table is absent No cancellation is applied and the absence is explicit
Request tries to override the threshold Rejected; the threshold comes from the profile or rulebook
A koota id is duplicated in the rulebook Startup failure; the eight-koota order must be unique

7. Out of scope

  • Natal chart assembly, signs and nakshatras (chart core) and binder astronomy (Astro Binder).
  • Mangal or Kuja dosha, Saptamamsha, Nadi astrology, western synastry, composite charts and dasha compatibility.
  • Panchang, transits and muhurta windows (panchang engine, transit engine).
  • Interpretation, recommendations, remedies, wedding advice and compatibility prose.
  • Gender roles in the API. Subjects are ordered, not gendered; a rulebook may encode the traditional direction, and the response always states it.
  • Storing match reports (chart/account domain).
  • Binder access, caching, retries and provenance (facade and binder).
  • Localisation and display formatting (client).

8. Planned code

Piece Responsibility
matching/MatchingEngine Admission, koota order and response assembly
matching/SubjectAdmission Version equality, required facts and fact consistency
matching/KootaCatalog Eight kootas, maxima, order and the 36-point check
matching/KootaTable Rulebook matrices, class maps and remainder bands
matching/FriendshipTable Sign lords and natural or compound friendship
matching/KootaEvaluator One evaluator per koota over the shared Moon facts
matching/DoshaResolver Nadi and Bhakoot doshas with named cancellations
matching/ScoreAssembler Exact totals, threshold comparison and deterministic order