{"id":23871331,"url":"https://github.com/nikhilgugwad/rule-engine-api","last_synced_at":"2026-05-15T08:07:08.400Z","repository":{"id":258627921,"uuid":"874202692","full_name":"nikhilgugwad/rule-engine-api","owner":"nikhilgugwad","description":"Rule Engine API that allows users to define and evaluate rules based on various conditions.","archived":false,"fork":false,"pushed_at":"2024-10-21T14:36:13.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-03T14:51:57.257Z","etag":null,"topics":["flask","python","sqlite3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nikhilgugwad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-17T12:28:10.000Z","updated_at":"2024-11-22T11:54:51.000Z","dependencies_parsed_at":"2025-01-03T14:50:47.777Z","dependency_job_id":"334948d8-0987-4892-bed8-7bb3d69502ff","html_url":"https://github.com/nikhilgugwad/rule-engine-api","commit_stats":null,"previous_names":["nikhilgugwad/rule-engine","nikhilgugwad/rule-engine-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilgugwad%2Frule-engine-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilgugwad%2Frule-engine-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilgugwad%2Frule-engine-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilgugwad%2Frule-engine-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikhilgugwad","download_url":"https://codeload.github.com/nikhilgugwad/rule-engine-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240222505,"owners_count":19767458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask","python","sqlite3"],"created_at":"2025-01-03T14:50:43.285Z","updated_at":"2025-10-28T20:47:19.700Z","avatar_url":"https://github.com/nikhilgugwad.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rule Engine API Documentation\n\n## Project Overview\nThis project is a **Rule Engine API** that allows users to define and evaluate rules based on various conditions. The rules can be combined using logical operators (AND, OR) and evaluated against given data.\n\n### Key Features\n- Add rules with their corresponding AST (Abstract Syntax Tree).\n- Evaluate rules against provided data.\n- Store rules persistently in a SQLite database.\n\n## Installation Instructions\n\n### Prerequisites\n- Python 3.11.9\n- Flask 3.0.3\n- SQLite3 (comes pre-installed with Python)\n\n### Steps to Install\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/nikhilgugwad/rule-engine.git\n   cd rule-engine-api\n   ```\n\n2. Create a virtual environment (optional but recommended):\n   ```bash\n   python -m venv venv\n   source venv/bin/activate  # On Windows use `venv\\Scripts\\activate`\n   ```\n\n3. Install the required packages:\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n4. Set up the database:\n   ```bash\n   python database_setup.py\n   ```\n\n5. Run the application:\n   ```bash\n   python app.py\n   ```\n\n6. The API should now be running at `http://127.0.0.1:5000/`.\n\n## Usage Instructions\n\n### API Endpoints\n\n#### 1. Health Check\n- **Endpoint**: `/`\n- **Method**: `GET`\n- **Description**: Verify that the API is working.\n\n**Example Request**:\n```bash\ncurl -X GET http://127.0.0.1:5000/\n```\n\n**Example Response**:\n```json\n\"Rule Engine API is working!\"\n```\n\n---\n\n#### 2. Add Rule\n- **Endpoint**: `/rules`\n- **Method**: `POST`\n- **Description**: Add a new rule to the database.\n\n**Request Payload**:\n```json\n{\n    \"rule_string\": \"age \u003e 30 AND department = 'Sales'\",\n    \"ast\": {\n        \"node_type\": \"operator\",\n        \"value\": \"AND\",\n        \"left\": {\"node_type\": \"operand\", \"value\": \"age \u003e 30\"},\n        \"right\": {\"node_type\": \"operand\", \"value\": \"department = 'Sales'\"}\n    }\n}\n```\n\n**Example Request**:\n```bash\ncurl -X POST http://127.0.0.1:5000/rules -H \"Content-Type: application/json\" -d '{\n    \"rule_string\": \"age \u003e 30 AND department = 'Sales'\",\n    \"ast\": {\n        \"node_type\": \"operator\",\n        \"value\": \"AND\",\n        \"left\": {\"node_type\": \"operand\", \"value\": \"age \u003e 30\"},\n        \"right\": {\"node_type\": \"operand\", \"value\": \"department = 'Sales'\"}\n    }\n}'\n```\n\n**Example Response**:\n```json\n{\n    \"message\": \"Rule added successfully\"\n}\n```\n\n---\n\n#### 3. Get Rules\n- **Endpoint**: `/rules`\n- **Method**: `GET`\n- **Description**: Retrieve all rules from the database.\n\n**Example Request**:\n```bash\ncurl -X GET http://127.0.0.1:5000/rules\n```\n\n**Example Response**:\n```json\n{\n    \"rules\": [\n        {\n            \"rule_string\": \"age \u003e 30 AND department = 'Sales'\",\n            \"ast_json\": \"{\\\"node_type\\\": \\\"operator\\\", \\\"value\\\": \\\"AND\\\", \\\"left\\\": {\\\"node_type\\\": \\\"operand\\\", \\\"value\\\": \\\"age \u003e 30\\\"}, \\\"right\\\": {\\\"node_type\\\": \\\"operand\\\", \\\"value\\\": \\\"department = 'Sales'\\\"}}\"\n        }\n    ]\n}\n```\n\n---\n\n#### 4. Evaluate Rule\n- **Endpoint**: `/evaluate`\n- **Method**: `POST`\n- **Description**: Evaluate a specific rule on provided data.\n\n**Query Parameter**: \n- `rule_id` (int): The ID of the rule to evaluate.\n\n**Request Payload**:\n```json\n{\n    \"data\": {\"age\": 35, \"department\": \"Sales\"}\n}\n```\n\n**Example Request**:\n```bash\ncurl -X POST http://127.0.0.1:5000/evaluate?rule_id=1 -H \"Content-Type: application/json\" -d '{\n    \"data\": {\"age\": 35, \"department\": \"Sales\"}\n}'\n```\n\n**Example Response**:\n```json\n{\n    \"result\": true\n}\n```\n\n## Testing Instructions\n\n### Testing Framework\nThis project uses the `unittest` framework for testing.\n\n### Running Tests\nTo run the tests in this project, follow these steps:\n\n1. **Set Up the Database**:\n   Ensure that the database is set up by running the `database_setup.py` script to create the `rules.db` file.\n\n   ```bash\n   python database_setup.py\n   ```\n\n2. **Run the Tests**:\n   You can run all tests using the following command:\n\n   ```bash\n   python -m unittest discover -s tests\n   ```\n\n   Alternatively, to run a specific test file, use:\n\n   ```bash\n   python -m unittest tests/test_ast_evaluator.py\n   ```\n\n### Test Structure\nThe tests are organized in the `tests` directory, which includes the following test files:\n\n- **test_ast_evaluator.py**: Contains unit tests for the AST evaluation logic.\n- **test_database.py**: Tests for database operations, ensuring rules can be saved and loaded correctly.\n- **test_app.py**: Tests for the Flask application endpoints to verify correct API behavior.\n\nEach test file uses the `unittest` framework to define test cases and assertions.\n\n## Contribution Guidelines\n\nWe welcome contributions to this project! Please follow the guidelines below to help us maintain a high-quality codebase.\n\n### How to Contribute\n\n1. **Fork the Repository**:\n   - Click the \"Fork\" button in the top-right corner of the repository to create your copy of the project.\n\n2. **Create a Feature Branch**:\n   - Create a new branch for your feature or bug fix. Use a descriptive name for your branch.\n   ```bash\n   git checkout -b feature/your-feature-name\n   ```\n\n3. **Make Changes**:\n   - Make your changes, ensuring that you follow the coding standards and conventions used in the project.\n\n4. **Commit Your Changes**:\n   - Commit your changes with a clear and concise commit message.\n   ```bash\n   git commit -m \"Add your message here\"\n   ```\n\n5. **Push to Your Fork**:\n   - Push your changes to your forked repository.\n   ```bash\n   git push origin feature/your-feature-name\n   ```\n\n6. **Create a Pull Request**:\n   - Go to the original repository and create a pull request from your feature branch.\n   - Provide a clear description of your changes and why they should be merged.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikhilgugwad%2Frule-engine-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikhilgugwad%2Frule-engine-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikhilgugwad%2Frule-engine-api/lists"}