# ๐ง 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.