# Module portable: App\DmGrading

Chấm bài DuckMind + lưu bảng `dm_grading`. Không phụ thuộc Testsite/CMS.

## Copy sang project khác

```
app/DmGrading/                          # toàn bộ thư mục
database/migrations/*_create_dm_grading_table.php
config/dm.php                             # hoặc merge vào config project
dm/AGENTS.md
dm/prompts.json
dm/grading_results/                       # thư mục writable
```

Thêm routes (xem `routes/api.php` section DM GRADING PORTABLE).

`.env`: `DUCKMIND_API_KEY`, `OPENROUTER_API_KEY`, `DM_TIMEOUT`.

Chạy: `php artisan migrate` + `php artisan queue:work` (nếu dùng queue).

## API

| Method | URI | Mô tả |
|--------|-----|--------|
| POST | `/api/dm-grading/submit` | Tạo record + dispatch job |
| POST | `/api/dm-grading/submit?sync=1` | Chấm đồng bộ |
| GET | `/api/dm-grading/status?id=` | Poll trạng thái |
| GET | `/api/dm-grading/result?id=` | Lấy `{ idGptMessage, score, content }` |

## Output format

```json
{
  "idGptMessage": 100001,
  "score": 6.5,
  "content": "Overall Score: 6.5\n\n..."
}
```

`idGptMessage = 100000 + dm_grading.id`

## File CLI

- Input: `dm/grading_{id}.json`
- Output: `dm/grading_results/grading_{id}_graded.json`
