- 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)
4.2 KiB
4.2 KiB
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 termapp/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:
- Define TypeScript interfaces in
lib/types.ts:Plant,Disease,CausalAgentType,Severity. - 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.).
- For each plant, research 2–5 common diseases (e.g., Tomato: early blight, late blight, septoria leaf spot, blossom end rot, powdery mildew).
- Write
data/plants.jsonanddata/diseases.jsonwith realistic, detailed entries — each disease must have ≥3 symptoms, ≥2 causes, ≥3 treatment steps, and ≥2 prevention tips. - Add
lookalikeDiseaseIdsto entries that are easily confused (e.g., early blight vs. septoria leaf spot). - Implement
lib/api/diseases.tswith filter-by-plant, filter-by-id, full-text search (name + description), and lookalike resolution. - 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). - Add request logging middleware and response caching headers (
Cache-Control: public, max-age=3600). - Write a smoke test script that validates all seed data has no missing references.
tests:
- Unit: Test
lib/api/diseases.tssearch and filter functions with known data. - Unit: Validate every disease entry references a valid plant ID and has valid enum values.
- Integration:
GET /api/plantsreturns 200 with plant array;GET /api/plants/tomatoreturns 200 or 404 for unknown ID. - Integration:
GET /api/diseases?plantId=tomatoreturns only tomato diseases. - Integration:
GET /api/diseases/unknown-idreturns 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:
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.