# ๐Ÿง  Backend Developer Take-Home Assignment: Rule Engine API ## ๐Ÿ“Œ Objective Build a lightweight **Rule Engine API** using **Django** and **Django REST Framework**. The system should allow admins to define dynamic rules and let clients evaluate JSON payloads against those rules. The outcome should be either **APPROVED** or **REJECTED** based on whether the payload satisfies the rules. --- ## ๐ŸŽฏ Requirements ### 1. Authentication Implement JWT-based authentication. - Two roles: `admin` and `client`. - **Admins** can create and manage rules. - **Clients** can only evaluate payloads. ### 2. Rule Management Admins should be able to: - Create, list, update, and delete rules. - Each rule consists of: - `name`: A unique rule name. - `condition`: JSON logic to define conditions (see example below). - `is_active`: Boolean flag. #### ๐Ÿงพ Example Rule Condition ```json { "field": "age", "operator": ">=", "value": 18 } ``` Supported operators: - `==`, `!=`, `>`, `<`, `>=`, `<=`, `contains` **Bonus**: Support nested conditions using `AND`, `OR`. ### 3. Payload Evaluation Endpoint Create an endpoint: ```bash POST /api/evaluate/ ``` โœ… Input Example ``` { "rules": ["Minimum Age Check", "Country Check"], "payload": { "age": 21, "country": "Thailand" } } ``` ๐Ÿ”„ Output Example ``` { "result": "APPROVED", "passed_rules": ["Minimum Age Check", "Country Check"], "failed_rules": [] } ``` If **at least one rule fails**, the result should be `"REJECTED"`. โœ… Bonus Points - Unit tests for rule evaluation logic - Swagger/OpenAPI documentation - Optional: Background job queue (e.g., Celery) to evaluate payloads asynchronously - Docker setup ## ๐Ÿ” Evaluation Criteria |Area |What We're Looking For | |--|--| |Code Quality | Clean, readable, modular code | |Django/DRF Practices| Correct use of models, serializers, viewsets, etc.| |Business Logic | Robust and flexible rule evaluation| |Security | Role-based access control | | Testing (Bonus) | Unit/integration tests for rules and evaluation logic | | Documentation (Bonus) | Instructions for setup and API usage ## ๐Ÿ“ฆ Submission Guidelines - Share a GitHub repo or downloadable zip file. - Include setup instructions in a `README.md`. - Keep it simple but functional โ€” you are not expected to build a production-grade engine.