Rule Engine Playground banner

Rule Engine Playground

14 devlogs
12h 7m 1s

Mini Rule Engine, you can write simple rules with syntax IF condition THEN action and test them with some input variables!

This project uses AI

ChatGPT was used to find this project idea and helping me check AST output, because AST is a tree (abstract syntax TREE) so its hard to check the output in console (nested ahhh object)

Demo Repository

Loading README...

Pratik

Shipped this project!

I made a rule engine!!!

so think of rule engine like a very very small programming language, except that its only IF statement and action lol, so i made a mini rule engine playground.
the current version is a nice MVP and i will make it better in future.
the syntax is: IF condition THEN action, very simple
You can press ? key to see the guide, it is a very small guide so i would recommend checking it out before using!

Pratik

Added import/export as json! yayayayayay

export the rules and variables as json files
i added this because in future i want to extend this project more and add more things in it, possibly making a CLI tool to run this thing locally too

Attachment
0
Pratik

Readme

added readme, it includes features, syntax, examples and all that shi

and also removed the preloaded empty rule when site is loaded fresh, cuz it looked cleaner without that

Attachment
0
Pratik

Smol Guide yayayayayay

Added a very small guide, it includes syntax, examples, operators, tokens for understanding errors, etc
i lowkey over-complicated this at the beginning cuz i made it a whole different page using react-router-dom, but halfway through doing that it felt too much just for a small amount of text i have move a lot of things around, so i decide to make it a modal which can opened with a button or shortcut (?)


and i got rid of that ugly ahh scroll bar too btw

Attachment
0
Pratik

Two smol keyboard shortcuts sob-ios

  1. CTRL + Enter => run all rules
  2. ESC => Close modal
Attachment
0
Pratik

Rule Templates! yayayayayay

i always add something so the user does not have to do too much to try my project, i dont want votes just because they cant understand how to use my project lol
so i added rule templates, just click “Add from templates” and pick a rule and it will clear the current rules and add that picked rule with the variables it needs, then you can customise it too.

there are 10 rules right now!!


that scroll bar looking ugly tho i gotta do something about that

Attachment
0
Pratik

Added new keywords! yayayayayay

1. CONTAINS

used to check if a string contains a substring
for example if the word “robotic” contains “robot” that would be:

IF word CONTAINS "robot" THEN yes = true

word is a variable with value robotic btw!

2. STARTSWITH

used to check if a string starts with something
same example:

IF word STARTSWITH "robo" THEN yes = true

3. ENDSWITH

the opposite, checks for a string at the end, like “tic” of “robotic”

IF word ENDSWITH "tic" THEN yes = true

4. BETWEEN

used to check if a numbe lies between some minum and maxium value, like if 18 lies between 10 and 20

IF age BETWEEN 10 AND 20 THEN teeneger = true
Attachment
0
Pratik

Multiple THEN actions + Clear All button yayayayayay

so i made the assignments after THEN keyword separated by comma so now you can do something like this:

IF age > 18 THEN allowed = true, unc = true

and a clear all buttons which clears all the rules, errors, variables, etc

Attachment
0
Pratik

Multiple rules support yay

now you can add multiple rules, run them separetly or all at once, it shows result with rule number too
it was quite hard tho ngl the for loop for evaluation was messing with me hard lmao and rule indexes

Attachment
0
Pratik

Better error messages + Error dislay rahh

improved the vague ahh errors, now its a teeny bit better, and now i am also dispaying error

it has 19 error throwing lines btw, like at 19 places it throws errors, probably more in future

Attachment
0
Pratik

Showing Result! rahh

it shows the boolean result and the output variable now :3
at first i was thinking of showing both input and output together as one object but i didnt do that was it was a bit weird after some thinking, so yeah this is how it looks:

Attachment
0
Pratik

Things added:


IF and THEN keyword

well, it was not that hard, i moved AST’s entry point from parseExpression to parseRule and it starts from a rule, and also THEN keyword used to define an action


Evaluation

it was pretty easy lol, because its just all about boolean output i just use a switch statement to get the values first and compare them with the identifiers, and in runRule function i just use the evaluate function in an if statement and based on that i set the action variable


Variable Panel UI

you can add variables as input, it suppors strings, numbers, and boolean, just simple click a button and add your variable, it was the hardest to do lol, i hate styling so much but i also love when it looks good at the end


todo: error handling

Attachment
0
Pratik

Abstract Syntax Tree sob-ios

this was easy but hard a the same time cuz of debugging.
AST produces complex nested objects as output so it was really hard to understand if something is wrong or not, reading the object and keeping track of the rule in head is confusing, but looks like it works right now


and honestly, dont look at the image lmao, not worth it, but you can tho it shows AST working but i am not going to show the entire object lol
however i am thinking to add an AST visualiser too cuz its a tree and best shown in tree format

Attachment
0
Pratik

Lexer!! yay

so after countless memory crash cuz of infinite loop my lexer is finally done, it is a very simple lexer with all the things i think i would need for an MVP.

things it can parse:

1. basic rules:

age > 18
name == "john pork"
score == 100
isActive == true
status != "banned"

2. logical combinations

age > 18 AND isActive == true
score >= 50 AND score <= 100

3. nested mixed bullshit

((age > 18 AND country == "IN") OR (score > 900 AND rank >= 10)) AND isActive == true

i am yet to handle contional statements tho

Attachment
0
Pratik

Made very basic homepage!

just a text area and a button, i only added those two because i made the UI first just for the sake showing something nice in first devlog instead of a console screenshot of backend logic :3

and also start very basic stuff for rule evaluation, so i hardcoded an object for rule IF age > 2 AND country == "Pangea" THEN access = "yesn't", no parsing right now tho, just an object

Attachment
0