Possible to Evaluate Nested Conditionality Like Notion's Advanced Filters

I want to create a condition filter similar to Notion’s “advanced filters” with databases.

I’m having a hard time wrapping my head around this. I’m able to evaluate conditions rules. But i’m not sure how I would go about evaluating it as a whole with these nested groupings (maximum nested 3).

My brain wants to use recursion and return true/false back up to the parent group once I get to a condition rule and have it evaluated.
But the bubble API doesn’t return values how I’m used to with a more traditional language.

Here’s my current 4 tables involved.

Product Line Items

  • linked to (1) “measurement condition grouping”

Project Measurement Data

  • any data that conditions can act on (lawn square feet, gutter length, number of chimneys etc…)

Measurement Condition Grouping

  • nested tier (number, up to 3)
  • AND/OR (option set)
  • Nested “Measurement Condition Groupings”
  • “measurement conditions rules”

Measurement Condition Rule

  • a rule based on available project data
  • link to relevant project data
  • value type (number, text, etc)
  • operator (<,>,=,!=, contains, etc)
  • value

Any help is greatly appreciated thank you.