Feature: Smart Tasks & Reminders
Relevant source files
The following files were used as context for generating this wiki page:
The Smart Tasks & Reminders feature is a proactive AI-driven system designed to transform VineSight from a reactive tool into an intelligent farming advisor. Its primary purpose is to reduce farmer decision fatigue by automatically generating and scheduling optimal farming tasks. The system analyzes multiple data points, including weather forecasts, farm growth stage, recent activities, and resource availability, to provide personalized and timely recommendations.
This feature is a core component of the "Phase 3: Advanced AI Intelligence" development stage. It aims to create a "Just tick ✅ Done" workflow, where the AI handles the complex scheduling, allowing the farmer to focus on execution. The system includes a user-facing dashboard for managing these tasks and a robust notification service to send timely reminders and alerts.
Sources: context/PRD.md:112-120, context/CLAUDE.md:27-31
Architecture Overview
The Smart Tasks system integrates frontend components, a dedicated backend service, a notification service, and the Supabase database. The user interacts with the SmartTasksDashboard, which triggers the SmartTaskGenerator service. This service, in turn, may interact with other AI services (like pest prediction) and fetches farm data to generate tasks, which are then stored in the database and displayed back to the user. The NotificationService runs on the client-side to schedule and display reminders for these tasks.
The following diagram illustrates the high-level data flow for generating and displaying smart tasks.
Data Models
The feature relies on several key data structures and a dedicated database table to manage AI-generated tasks.
Database Schema
A new table, ai_task_recommendations, is introduced in the Supabase database to persist the smart tasks. Row Level Security is enabled to ensure users can only access recommendations for their own farms.
The following ER diagram shows the schema for the ai_task_recommendations table and its relation to farms and users.
Sources: context/CLAUDE.md:40-56, 203-210
Key Interfaces
The application uses specific TypeScript interfaces to handle task data consistently between the frontend, backend, and database.
AITaskRecommendation
This is the primary interface for a smart task generated by the AI.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the task. |
farmId | number | The ID of the farm this task belongs to. |
userId | string | The ID of the user this task is for. |
taskType | 'irrigation' | 'spray' | ... | The category of the task. |
recommendedDate | Date | The date the AI recommends performing the task. |
priorityScore | number | A score from 0 to 1 indicating the task's urgency. |
weatherDependent | boolean | Flag indicating if the task timing is sensitive to weather. |
reasoning | string | The AI's explanation for why the task is recommended. |
confidenceScore | number | A score from 0 to 1 indicating the AI's confidence. |
status | 'pending' | 'accepted' | ... | The current state of the task. |
taskDetails | object | Optional detailed parameters like duration, resources, etc. |
createdAt | Date | Timestamp of when the task was created. |
Sources: context/TYPES_AND_INTERFACES.md:172-197, src/components/ai/SmartTasksDashboard.tsx:13
TaskReminder
This interface is used by the NotificationService to manage reminders.
| Field | Type | Description |
|---|---|---|
id | number (optional) | Unique identifier for the reminder. |
farmId | number | The ID of the associated farm. |
taskType | string | The category of the task. |
description | string | A brief description of the task. |
dueDate | string | The date the task is due. |
priority | 'low' | 'medium' | 'high' | ... | The priority level of the task. |
status | 'pending' | 'completed' | ... | The current status of the task. |
Sources: context/TYPES_AND_INTERFACES.md:46-55, src/lib/notification-service.ts:3
Core Components
Smart Task Generator (smart-task-generator.ts)
This service contains the core logic for generating, retrieving, and updating AI task recommendations. It acts as a static class, centralizing all interactions with smart tasks.
Key Functions:
generateSmartTasks(request: RecommendationRequest): The main function that triggers the generation process. It is intended to analyze various contexts like weather, growth stage, and recent activities to create new tasks.getActiveRecommendations(farmId: number): Fetches all non-completed tasks for a given farm from the backend.updateTaskStatus(taskId: string, action: 'accepted' | 'rejected' | 'completed', feedback?: string): Updates the status of a task, allowing the AI to learn from user feedback.
The generation logic is designed to be predictive, considering multiple factors to optimize task timing and priority.
Sources: src/lib/smart-task-generator.ts, context/PRD.md:112-120
The following flowchart outlines the process within the SmartTaskGenerator.
Source: context/CLAUDE.md:376-410
Smart Tasks Dashboard (SmartTasksDashboard.tsx)
This is the primary UI component for the feature. It provides a centralized view for farmers to see, manage, and interact with their AI-generated tasks.
Key Features:
- Task Generation: A "Refresh" button allows users to manually trigger the generation of new recommendations.
- Task Display: Tasks are categorized into "Today's Tasks" and "Upcoming Tasks". Each task is displayed on a
TaskCardcomponent. - Task Details: Each card shows the task type, priority, AI reasoning, confidence score, and whether it's weather-dependent.
- User Interaction: Users can "Accept", "Mark Done", or "Reject" tasks. These actions call
SmartTaskGenerator.updateTaskStatusto provide a feedback loop for the AI.
The component manages its state with useState for recommendations, loading, and generatingNew.
Sources: src/components/ai/SmartTasksDashboard.tsx
This sequence diagram shows a typical user interaction flow with the dashboard.
Notification Service (notification-service.ts)
This client-side service is responsible for scheduling and dispatching local push notifications for task reminders and other alerts. It is implemented as a singleton class.
Key Features:
- Permission Handling:
requestPermission()prompts the user to allow notifications. - Configurable Settings: Manages settings like
enabled,reminderTime, anddaysAdvanceinlocalStorage. - Task Reminders:
sendTaskReminder()sends notifications for tasks that are due today, overdue, or upcoming. - Scheduling:
scheduleTaskNotifications()iterates through tasks and usessetTimeoutto schedule future notifications based on user settings. - Other Alerts: Includes methods for weather alerts (
sendWeatherAlert) and water level alerts (sendWaterLevelAlert).
The diagram below shows the class structure of the NotificationService.
Task Templates (task-templates.ts)
The system includes a predefined list of task templates that serve as a blueprint for common farming activities. While the SmartTaskGenerator is designed to create tasks dynamically, these templates provide a structured basis for recurring tasks.
Each template includes an ID, title, description, type, priority, and optional instructions, frequency, and applicable growth stage or season.
Example Template:
// src/lib/task-templates.ts:25-35
{
id: 'preventive_spray_powdery_mildew',
title: 'Preventive Spray - Powdery Mildew',
description: 'Apply preventive fungicide spray for powdery mildew control',
type: 'spray',
priority: 'high',
estimatedDuration: '3 hours',
frequency: 'biweekly',
growthStage: ['bud_break', 'flowering', 'fruit_set'],
instructions:
'Use sulfur-based fungicide. Apply in early morning or evening. Ensure complete canopy coverage.',
}
Helper functions like getTemplatesByType and getTemplatesByGrowthStage are available to filter these templates.
Sources: src/lib/task-templates.ts
Summary
The Smart Tasks & Reminders feature is a cornerstone of VineSight's evolution into a proactive, AI-powered agricultural platform. By leveraging AI to analyze farm data and external factors, it automates the complex process of task scheduling, presenting farmers with a prioritized and actionable to-do list. The integration of a user-friendly dashboard for management and a robust notification system for reminders ensures that critical tasks are not missed, ultimately aiming to improve farm efficiency, optimize resource usage, and increase profitability.
Sources: context/PRD.md:112-120, context/CLAUDE.md:27-31, 513-529