## Data Model Overview

View Full

High-level entity relationships without field details. Shows the main actors, workflow, and data flow.

#### Clusters

- Users & Auth: Django auth.User as central identity
- Pet Owners & Pets: Clients, their pets, vaccines, studies
- Veterinarians: Vets with availability, specialties, coverage areas
- Services & Pricing: Service catalog with dynamic pricing
- Cart & Checkout: Shopping cart workflow
- Service Requests: Order lifecycle with state machine
- Veterinary Visits: Scheduled visits, reports, AFIP invoicing
- Reference Data: Lookups (specialties, neighborhoods, vaccines, etc.)

## Backend Architecture

View Full

Django apps structure: mascotas, productos, solicitudes, common, payments, and external integrations.

#### Celery Tasks

Task | App | Purpose
--- | --- | ---
`send_veterinarian_followup` | solicitudes | Re-sends availability request to vet if still pending
`run_payment_reminder_cron` | solicitudes | Cron job to send payment reminders
`create_vetvisit_in_sheet` | mascotas | Creates row in Google Sheets for visit
`update_vetvisit_in_sheet` | mascotas | Updates Google Sheets row
`create_event_calendar_vetvisit` | mascotas | Creates Google Calendar event
`update_event_calendar_vetvisit` | mascotas | Updates Google Calendar event
`create_user_owner` | mascotas | Creates Django user for PetOwner + welcome email
`generate_vetvisit_invoice` | mascotas | Generates AFIP invoice and PDF
`fetch_mp_notification_details` | payments | Fetches MercadoPago webhook details

Celery handles async operations: external APIs (Google, MercadoPago, AFIP), scheduled reminders, and heavy processing (invoices, emails).

## Frontend Architecture

View Full

Next.js 13+ App Router structure with public pages, backoffice, shared components, and services layer.

#### Key Areas

- Public Pages: Landing, service catalog, booking flow
- Backoffice: Role-based dashboards (admin, vet, petowner)
- Services Layer: API clients for backend communication
- State Management: Redux store for cart, auth, UI state
- Shared Components: Forms, tables, modals, navigation

## Detailed Data Model

View Full

Complete entity-relationship diagram with all fields, types, and relationships.

#### Data Patterns

- Soft delete: `deleted` flag on most models
- Audit trail: `StateHistory` for service requests
- Geographic: PostGIS polygons for coverage areas
- Versioned pricing: Date ranges on `Prices`

## Key Findings

### User Types

All users connect to `auth.User`:

- PetOwner: Optional 1:1 link (created lazily)
- Veterinarian: Required 1:1 link to User
- Staff: Direct Django users with `is_staff=True`

### Core Workflow

`PetOwner → Cart → ServiceRequest → VeterinarianAsked → VetVisit → Report`

State Machine:

pending → vet_asked → vet_accepted → coordinated → payed → Confirmado

### Pricing Logic

- Base price × `neighborhood.distance_coefficient`
- Optional vet-specific pricing via `Prices.veterinarian_id`
- Turn fee surcharge via `IndividualTurnFeeGroup`
- Time-based discounts via `Discounts` model

### External Integrations

- MercadoPago: Payment processing
- Google Calendar: Visit synchronization
- Google Sheets: Visit tracking spreadsheet
- Mercately: WhatsApp notifications
- AFIP: Argentine tax invoicing

## Technology Stack

### Backend

- Django 4.x
- Django REST Framework
- PostgreSQL + PostGIS
- Celery (Redis)
- JWT Authentication
- django-afip

### Frontend

- Next.js 13+ (App Router)
- React 18+
- TypeScript
- Redux
- Axios
- Tailwind CSS

### Infrastructure

- Docker
- Nginx
- AWS S3 (storage)
- MercadoPago API
- Google APIs
- WhatsApp Business