Feature: Farm Management
Relevant source files
The following files were used as context for generating this wiki page:
The Farm Management feature is a foundational component of the VineSight application. It provides the core functionality for users, primarily grape farmers, to digitally register, manage, and view their farms. Each farm entity serves as a central data object to which all other operational records, such as irrigation, spraying, harvesting, and financial expenses, are linked.
This feature was part of the "Phase 1: Core Record-Keeping & Calculators" development stage. It enables users to add, edit, and delete multiple farms, capturing essential details like name, region, area, grape variety, and planting date. This data is then reused across the application for scientific calculators, analytics, reporting, and AI-powered recommendations.
Sources: context/PRD.md:19-22, 102-103
Data Model
The farm data is structured to hold both basic farm attributes and more detailed parameters for calculations and location-based services. The system uses two main interfaces for farm data: one for the application layer (Farm) and one for the database layer (DatabaseFarm), which maps directly to the Supabase table schema.
Sources: context/TYPES_AND_INTERFACES.md:5-40
TypeScript Interfaces
The primary Farm interface used within the application logic is defined as follows:
// Core Farm interface (Application Layer)
export interface Farm {
id?: number;
name: string;
region: string;
area: number;
grapeVariety: string;
plantingDate: string;
vineSpacing?: number;
rowSpacing?: number;
totalTankCapacity?: number;
systemDischarge?: number;
remainingWater?: number;
waterCalculationUpdatedAt?: string;
latitude?: number;
longitude?: number;
elevation?: number;
locationName?: string;
timezone?: string;
locationSource?: 'manual' | 'search' | 'gps';
locationUpdatedAt?: string;
createdAt?: string;
updatedAt?: string;
userId?: string;
}
Sources: context/TYPES_AND_INTERFACES.md:6-30
Database Schema
The farms table in the Supabase PostgreSQL database is the persistence layer for farm data. It is linked to the auth.users table via a user_id foreign key, ensuring that each farm is associated with a specific user. Row Level Security is enabled on this table to enforce data privacy.
Sources: CLAUDE.md:46-68, 110
The following diagram illustrates the entity relationship for the farms table.
Sources: CLAUDE.md:46-68
The table below details the columns in the farms table.
| Column | Type | Description |
|---|---|---|
id | SERIAL PRIMARY KEY | Unique identifier for the farm. |
user_id | UUID | Foreign key referencing auth.users(id). |
name | TEXT | The name of the farm. |
region | TEXT | The geographical region of the farm. |
area | REAL | The total area of the farm, typically in acres. |
grape_variety | TEXT | The variety of grape grown on the farm. |
planting_date | DATE | The date the grapevines were planted. |
vine_spacing | REAL | Spacing between vines. |
row_spacing | REAL | Spacing between rows. |
latitude | REAL | Geographic latitude for weather and location services. |
longitude | REAL | Geographic longitude for weather and location services. |
created_at | TIMESTAMP | Timestamp of when the record was created. |
updated_at | TIMESTAMP | Timestamp of the last update. |
Sources: CLAUDE.md:46-68, context/TYPES_AND_INTERFACES.md:6-30
Core Functionality & UI
The Farm Management feature is integrated throughout the application. A key UI pattern is the ability for a user to select a specific farm, which then scopes the data displayed in various modules like the Dashboard, Reports, and Performance pages.
Sources: src/components/dashboard/FarmerDashboard.tsx:103-122, src/app/reports/page.tsx:439-453
Farm Selection
Across the application, users with multiple farms are presented with a dropdown selector to switch context between their different properties. This selection mechanism is a central part of the user experience.
- Farmer Dashboard: The
FarmerDashboardcomponent includes aSelectdropdown that lists all the user's farms. Changing the selection updates theselectedFarmIdstate, which in turn triggers a reload of dashboard data for the chosen farm. - Reports Page: The
UnifiedReportsPageuses a similarSelectcomponent to allow users to choose which farm to generate a report for. - Performance Page: The
FarmEfficiencyPagealso uses a farm selector to load and display performance metrics for the selected farm.
Sources: src/components/dashboard/FarmerDashboard.tsx:103-122, src/app/reports/page.tsx:439-453, src/app/performance/page.tsx:210-229
The sequence diagram below shows the process of a user selecting a farm and the subsequent data loading.
Data Consumption
Once a farm is selected, its data is used as the primary context for other features:
- Dashboards: The
FarmerDashboardandPortfolioDashboarddisplay high-level metrics and status for one or more farms. - Calculators: Scientific calculators, such as the
SoilHealthMonitoringComponent, use farm context like crop type and planting year to provide accurate analyses. - Reporting: The
ReportingServiceandExportServiceuse thefarmIdto fetch all associated records (irrigation, harvest, expenses) to generate comprehensive PDF or CSV reports. - Performance Analytics: The
FarmEfficiencyPagecalculates metrics like "Yield per Hectare" and "Water Use Efficiency" based on the selected farm's area and its associated operational records.
Sources: src/components/dashboard/FarmerDashboard.tsx, src/components/calculators/SoilHealthMonitoring.tsx:80-97, src/lib/export-service.ts:31, src/app/performance/page.tsx:64-71
This diagram shows how farm data is consumed by different modules.
Sources: context/PRD.md:19-58
Internationalization
The Farm Management feature supports multiple languages, including English, Hindi, and Marathi. UI labels and fields related to farm management are defined in the i18n resource file.
Sources: src/lib/i18n.ts:100-116
| Key | English | Hindi | Marathi |
|---|---|---|---|
farm.title | Farm Management | फार्म प्रबंधन | शेत व्यवस्थापन |
farm.addFarm | Add New Farm | नया फार्म जोड़ें | नवीन शेत जोडा |
farm.farmName | Farm Name | फार्म का नाम | शेताचे नाव |
farm.location | Location | स्थान | स्थान |
farm.area | Area (acres) | क्षेत्रफल (हेक्टेयर) | क्षेत्रफळ (हेक्टर) |
farm.grapeVariety | Grape Variety | अंगूर की किस्म | द्राक्षाचा प्रकार |
farm.plantingDate | Planting Date | रोपण तारीख | लागवडीची तारीख |
Sources: src/lib/i18n.ts:100-116, 229-245, 360-376
Conclusion
The Farm Management feature is the structural backbone of the VineSight application. It establishes the primary data entity—the farm—upon which all other features are built. By allowing users to create and manage detailed profiles for their farms, the system can provide tailored calculations, analytics, and AI-driven insights. The consistent use of a farm selection mechanism across different modules ensures a cohesive and context-aware user experience, making it possible for farmers to manage multiple properties efficiently from a single interface.