Overview
Establishments represent individual dairy farm locations. Each user can manage multiple establishments, with all production data, costs, and analytics segregated by location.Multi-Location Benefits
- Centralized management across multiple farms
- Location-specific production tracking
- Independent analytics per establishment
- Scalable architecture for farm expansion
Data Structure
Establishments are defined in the Prisma schema:Key Fields
- idEstablecimiento: Unique UUID identifier
- nombre: Farm or establishment name
- localidad: City/locality
- provincia: Province/state
- idUsuario: Owner reference
- loteProducciones: All production batches for this location
Creating an Establishment
Users must create at least one establishment before tracking production:Listing Establishments
Retrieve all establishments for the authenticated user:The list is automatically filtered by the authenticated user’s
idUsuario. Users can only see their own establishments.Establishment Selection
In the frontend, establishments are accessed through the user context:- Single Establishment
- Multiple Establishments
For users with one establishment, the system automatically uses that location for all operations.
Establishment Context in Production
All production data is tied to an establishment:Production Batches
Each batch (
LoteProduccion) links to idEstablecimientoDashboard Analytics
Metrics are calculated per establishment
Alerts
AI-powered alerts are generated per location
Cost Tracking
Costs are segregated by establishment
Validation Rules
Schema Validation
Schema Validation
The All fields are mandatory. Invalid submissions return a 400 error.
createEstablishmentSchema validates:Authorization
Authorization
Use Cases
Single Farm Operation
Multi-Farm Enterprise
Integration with Other Features
Production Batches
Every batch requires an
idEstablecimiento. The system validates the establishment exists and belongs to the user.Best Practices
Naming Convention
Use clear, descriptive names that identify the physical location (e.g., “Tambo Las Rosas - Planta Norte”)
Location Accuracy
Provide accurate province and locality for potential future features like regional analytics
Establishment Selector
For multi-establishment users, implement a dropdown or selector in the navigation
Context Persistence
Store the selected establishment in local storage or context to maintain user preference
Future Enhancements
Consider implementing:
- Establishment editing (update name, location)
- Establishment archiving (soft delete)
- Role-based access for multi-user establishments
- Establishment-level settings and preferences
API Reference
| Endpoint | Method | Auth | Purpose |
|---|---|---|---|
/api/establishments | POST | Required | Create new establishment |
/api/establishments | GET | Required | List user’s establishments |
