A sophisticated rule engine using Abstract Syntax Tree (AST) for complex business rule evaluation. This project is developed as part of the Zeotap Intern Assignment, featuring a modern web interface for rule management and evaluation.
A modern 3-tier application that enables:
- Complex rule creation and evaluation
- Dynamic rule combinations
- Real-time data assessment
- Easy rule management through web interface
- β Dynamic rule creation and modification
- β Real-time rule evaluation
- β Rule combination using AST
- β MongoDB data persistence
- β Modern React UI
- β Visual Rule Builder with interactive components
- β Real-time rule validation
- β Performance analytics and metrics
- β Rule templates system
- β Advanced error handling with detailed feedback
- β AST implementation
- β Efficient rule traversal
- β RESTful API design
- β Error handling
- β Input validation
- β Component-based architecture
- β Modular code structure
- β Real-time validation service
- β Analytics tracking
- β Advanced UI components
class Node:
type: str # "operator" or "comparison"
left: Node # Left child node
right: Node # Right child for operators
field: str # Field name for comparisons
operator: str # Comparison operator
value: Any # Comparison value
rule_engine/
βββ app/
β βββ services/
β β βββ rule_validation.py
β β βββ rule_analytics.py
β βββ static/
β β βββ css/
β β βββ js/
β β βββ components/
β β βββ core/
β β β βββ RuleEngineUI.jsx
β β β βββ RuleBuilder.jsx
β β βββ shared/
β β β βββ AlertMessage.jsx
β β β βββ LoadingSpinner.jsx
β β βββ tabs/
β β βββ CreateTab.jsx
β β βββ ManageTab.jsx
β β βββ EvaluateTab.jsx
β β βββ CombineTab.jsx
β βββ routes/
β β βββ api.py
β βββ main.py
β βββ database.py
β βββ rule_engine.py
βββ tests/
β βββ test_api.py
β βββ test_rule_engine.py
β βββ test_rule_validation.py
βββ requirements.txt
βββ README.md
- Frontend: React, Tailwind CSS, Lucide Icons
- Backend: FastAPI, Python 3.7+
- Database: MongoDB
- Validation: Pydantic
- Testing: Pytest
- Python 3.7+
- MongoDB
- Node.js and npm
- Clone repository:
git clone https://github.com/AryanBV/rule_engine.git
cd rule_engine
- Create virtual environment:
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Configure MongoDB:
# Create .env file with:
MONGODB_URL=mongodb://localhost:27017/rule_engine
- Start server:
uvicorn app.main:app --reload
- Host name:
http://localhost:8000/static/index.html
# Simple Rule
age > 30 AND department = 'Sales'
# Complex Rule
((age > 30 AND department = 'Marketing')) AND (salary > 20000 OR experience > 5)
{
"age": 35,
"department": "Sales",
"salary": 75000,
"experience": 7
}
POST /api/rules/ # Create rule
GET /api/rules/ # List rules
GET /api/rules/{rule_id} # Get rule
PUT /api/rules/{rule_id} # Update rule
DELETE /api/rules/{rule_id} # Delete rule
POST /api/rules/evaluate/{rule_id} # Evaluate rule
POST /api/rules/combine # Combine rules
POST /api/rules/validate # Validate rule syntax
GET /api/rules/{rule_id}/analytics # Get rule analytics
Run tests:
pytest
- β Core engine implementation
- β AST evaluation logic
- β MongoDB integration
- β CRUD operations
- β Modern UI
- β Enhanced validation
- β Visual rule builder
- β Performance analytics
- β Component architecture
- β Real-time feedback
- π Enhanced error handling
- π UI/UX improvements
- π Performance optimizations
- π User authentication
- π Rule versioning
- π Advanced visualizations
- π Batch evaluations
- API Docs:
http://localhost:8000/docs
- Components:
app/static/js/components/
- Core Logic:
app/rule_engine.py
- Fork repository
- Create feature branch
- Commit changes
- Push to branch
- Submit pull request
- Unit tests
- API tests
- Integration tests
- Validation tests
- Component tests