- Next.js 16 App Router project with Tailwind CSS - Plant disease knowledge base (93 diseases, 25 plants) - Image upload with client+server preprocessing - ML inference pipeline with mock/demo fallback - Responsive results page with disease cards and treatment - Full test suite (285 passing tests)
67 lines
4.2 KiB
Markdown
67 lines
4.2 KiB
Markdown
# 02. Plant Disease Knowledge Base Schema, Seed Data, and API Endpoints
|
||
|
||
meta:
|
||
id: hyper-specific-plant-disease-id-02
|
||
feature: hyper-specific-plant-disease-id
|
||
priority: P1
|
||
depends_on: [hyper-specific-plant-disease-id-01]
|
||
tags: [data, api, database]
|
||
|
||
objective:
|
||
- Define the data schema for plants and diseases, seed the knowledge base with ≥80 plant-disease pairs covering common houseplants and garden crops, and expose read-only API endpoints.
|
||
|
||
deliverables:
|
||
- `data/plants.json` — seed data for 20–30 common plants (id, common name, scientific name, family, care summary, image URL)
|
||
- `data/diseases.json` — seed data for 80–120 disease entries (id, plantId, name, scientific name, causal agent type [fungal/bacterial/viral/environmental], description, symptoms list, causes list, treatment steps, prevention tips, lookalike disease IDs, severity)
|
||
- `lib/api/diseases.ts` — typed helpers to query the knowledge base by plant ID, disease ID, or search term
|
||
- `app/api/plants/route.ts` — `GET /api/plants` (list all), `GET /api/plants?search=` (search)
|
||
- `app/api/plants/[id]/route.ts` — `GET /api/plants/:id` (single plant with its diseases)
|
||
- `app/api/diseases/route.ts` — `GET /api/diseases` (list all with optional plantId filter)
|
||
- `app/api/diseases/[id]/route.ts` — `GET /api/diseases/:id` (single disease with full detail)
|
||
- `lib/types.ts` — shared TypeScript interfaces for Plant, Disease, and related types
|
||
|
||
steps:
|
||
1. Define TypeScript interfaces in `lib/types.ts`: `Plant`, `Disease`, `CausalAgentType`, `Severity`.
|
||
2. Research and compile seed data for 20–30 common plants (tomato, basil, rose, monstera, pothos, snake plant, peace lily, orchid, succulent varieties, pepper, cucumber, squash, bean, strawberry, mint, lavender, etc.).
|
||
3. For each plant, research 2–5 common diseases (e.g., Tomato: early blight, late blight, septoria leaf spot, blossom end rot, powdery mildew).
|
||
4. Write `data/plants.json` and `data/diseases.json` with realistic, detailed entries — each disease must have ≥3 symptoms, ≥2 causes, ≥3 treatment steps, and ≥2 prevention tips.
|
||
5. Add `lookalikeDiseaseIds` to entries that are easily confused (e.g., early blight vs. septoria leaf spot).
|
||
6. Implement `lib/api/diseases.ts` with filter-by-plant, filter-by-id, full-text search (name + description), and lookalike resolution.
|
||
7. Build `app/api/plants/route.ts`, `app/api/plants/[id]/route.ts`, `app/api/diseases/route.ts`, `app/api/diseases/[id]/route.ts` — all return typed JSON with proper error handling (404 for missing IDs, 400 for invalid queries).
|
||
8. Add request logging middleware and response caching headers (`Cache-Control: public, max-age=3600`).
|
||
9. Write a smoke test script that validates all seed data has no missing references.
|
||
|
||
tests:
|
||
- **Unit:** Test `lib/api/diseases.ts` search and filter functions with known data.
|
||
- **Unit:** Validate every disease entry references a valid plant ID and has valid enum values.
|
||
- **Integration:** `GET /api/plants` returns 200 with plant array; `GET /api/plants/tomato` returns 200 or 404 for unknown ID.
|
||
- **Integration:** `GET /api/diseases?plantId=tomato` returns only tomato diseases.
|
||
- **Integration:** `GET /api/diseases/unknown-id` returns 404 with error message.
|
||
|
||
acceptance_criteria:
|
||
- ≥80 disease entries across ≥20 plants exist.
|
||
- All API endpoints return correct 200/404/400 responses.
|
||
- Search endpoint returns matches by common name, scientific name, and description.
|
||
- Lookalike references are bidirectional and valid.
|
||
- Seed data passes cross-reference validation (no orphan disease entries).
|
||
|
||
validation:
|
||
```bash
|
||
curl http://localhost:3000/api/plants | jq '.plants | length'
|
||
# → ≥20
|
||
|
||
curl http://localhost:3000/api/diseases | jq '.diseases | length'
|
||
# → ≥80
|
||
|
||
curl http://localhost:3000/api/plants/tomato | jq '.plant.diseases[0].name'
|
||
# → e.g., "Early Blight"
|
||
|
||
curl http://localhost:3000/api/diseases?search=blight | jq '.diseases | length'
|
||
# → ≥2
|
||
```
|
||
|
||
notes:
|
||
- Data is file-based JSON (no external DB) so the app remains simple to deploy on Vercel.
|
||
- Diseases should include both biotic (fungal, bacterial, viral) and abiotic (nutrient deficiency, overwatering, sunburn) conditions.
|
||
- Each disease entry should be detailed enough that a gardener can confidently diagnose and act.
|