Files
plant-disease-id/tasks/multi-image-user-feedback/01-api-types-and-schema.md

3.0 KiB

01. Extend Types and Add Feedback DB Schema

meta: id: multi-image-user-feedback-01 feature: multi-image-user-feedback priority: P0 depends_on: [] tags: [types, schema, database]

objective:

  • Update shared TypeScript types to support multi-image requests, species-constrained inference, top-5 combo predictions, and post-evaluation feedback.
  • Add a new database table for storing feedback entries.

deliverables:

  • src/lib/types.ts — updated with new interfaces
  • src/lib/db/schema.ts — updated with diagnosisFeedback table

steps:

  1. Add these new types to src/lib/types.ts:

    • IdentifyOptions — optional fields sent in the identify request: secondImageId?: string, userSpecies?: string, useForTraining?: boolean
    • IdentifyRequest — extend to include options?: IdentifyOptions
    • TopPrediction — a prediction with both species and disease info: { speciesName: string, diseaseName: string, diseaseId: string, confidence: ConfidenceResult, rank: number }
    • IdentifyResponse — extend to include topSpeciesDisease?: TopPrediction[], speciesConfidence?: ConfidenceResult, infoProvided: string[] (which optional inputs the user gave)
    • AccuracyRating"correct" | "incorrect" | "unsure"
    • DiagnosisFeedback — full feedback shape: { sessionId: string, imageIds: string[], userSpecies?: string, predictedDiseaseId: string, accuracyRating: AccuracyRating, consentToStoreImages: boolean, userCorrectedSpecies?: string, notes?: string, createdAt: string }
    • FeedbackRequest — POST body for the feedback endpoint
    • FeedbackResponse — confirmation response
  2. Add a diagnosisFeedback table to src/lib/db/schema.ts:

    • id — text primary key (UUID v4)
    • sessionId — text, session identifier for grouping
    • imageIds — JSON text array of stored image IDs
    • userSpecies — text, nullable
    • predictedDiseaseId — text, the top model prediction
    • accuracyRating — text enum: "correct" | "incorrect" | "unsure"
    • consentToStoreImages — integer (boolean)
    • userCorrectedSpecies — text, nullable (only when accuracy=incorrect or unsure)
    • notes — text, nullable
    • modelVersion — text, the model version used
    • createdAt — text, auto timestamp
    • Add indexes on sessionId, accuracyRating, createdAt
  3. Export DiagnosisFeedbackRow and DiagnosisFeedbackInsert type helpers.

tests:

  • Unit: verify new types compile correctly
  • Unit: verify schema migration produces correct table DDL
  • Unit: verify INSERT and SELECT on feedback table through Drizzle

acceptance_criteria:

  • All new types are exported from src/lib/types.ts
  • diagnosisFeedback table exists in schema with all required columns
  • DiagnosisFeedbackRow and DiagnosisFeedbackInsert are exported

validation:

  • npx tsc --noEmit passes
  • Drizzle Kit (npx drizzle-kit generate) produces valid migration SQL

notes:

  • The sessionId ties together the upload, identify, and feedback flow
  • Image storage consent is a boolean to comply with data privacy requirements